1 package com.xtremelabs.robolectric.shadows; 2 3 import com.xtremelabs.robolectric.WithTestDefaultsRunner; 4 import org.hamcrest.CoreMatchers; 5 import org.junit.Before; 6 import org.junit.Test; 7 import org.junit.runner.RunWith; 8 9 import static org.hamcrest.CoreMatchers.is; 10 import static org.hamcrest.MatcherAssert.assertThat; 11 12 @RunWith(WithTestDefaultsRunner.class) 13 public class PasswordTransformationMethodTest { 14 15 private ShadowPasswordTransformationMethod transformationMethod; 16 17 @Before 18 public void setUp(){ 19 transformationMethod = new ShadowPasswordTransformationMethod(); 20 } 21 22 @Test 23 public void shouldMaskInputCharacters(){ 24 CharSequence output = transformationMethod.getTransformation("foobar", null); 25 assertThat(output.toString(), is("\u2022\u2022\u2022\u2022\u2022\u2022")); //using the escaped characters for cross platform compatibility. 26 } 27 28 @Test 29 public void shouldTransformSpacesWithText(){ 30 CharSequence output = transformationMethod.getTransformation(" baz ", null); 31 assertThat(output.toString(), is("\u2022\u2022\u2022\u2022\u2022")); 32 } 33 34 @Test 35 public void shouldTransformSpacesWithoutText(){ 36 CharSequence output = transformationMethod.getTransformation(" ", null); 37 assertThat(output.toString(), is("\u2022\u2022\u2022\u2022")); 38 } 39 40 @Test 41 public void shouldNotTransformBlank(){ 42 CharSequence output = transformationMethod.getTransformation("", null); 43 assertThat(output.toString(), is("")); 44 } 45 46 @Test 47 public void shouldNotTransformNull(){ 48 CharSequence output = transformationMethod.getTransformation(null, null); 49 assertThat(output.toString(), is("")); 50 } 51 52 @Test 53 public void shouldRetrieveAnInstance(){ 54 assertThat(ShadowPasswordTransformationMethod.getInstance(), is(CoreMatchers.<Object>notNullValue())); 55 } 56 } 57