aboutsummaryrefslogtreecommitdiff
path: root/v1/src/test/java/com/xtremelabs/robolectric/shadows/PasswordTransformationMethodTest.java
blob: da38879b3bd960bab407983bdc6785cd3f03529b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package com.xtremelabs.robolectric.shadows;

import com.xtremelabs.robolectric.WithTestDefaultsRunner;
import org.hamcrest.CoreMatchers;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;

@RunWith(WithTestDefaultsRunner.class)
public class PasswordTransformationMethodTest {

    private ShadowPasswordTransformationMethod transformationMethod;

    @Before
    public void setUp(){
        transformationMethod = new ShadowPasswordTransformationMethod();
    }

    @Test
    public void shouldMaskInputCharacters(){
        CharSequence output = transformationMethod.getTransformation("foobar", null);
        assertThat(output.toString(), is("\u2022\u2022\u2022\u2022\u2022\u2022")); //using the escaped characters for cross platform compatibility.
    }

    @Test
    public void shouldTransformSpacesWithText(){
        CharSequence output = transformationMethod.getTransformation(" baz ", null);
        assertThat(output.toString(), is("\u2022\u2022\u2022\u2022\u2022"));
    }

    @Test
    public void shouldTransformSpacesWithoutText(){
        CharSequence output = transformationMethod.getTransformation("    ", null);
        assertThat(output.toString(), is("\u2022\u2022\u2022\u2022"));
    }

    @Test
    public void shouldNotTransformBlank(){
        CharSequence output = transformationMethod.getTransformation("", null);
        assertThat(output.toString(), is(""));
    }

    @Test
    public void shouldNotTransformNull(){
        CharSequence output = transformationMethod.getTransformation(null, null);
        assertThat(output.toString(), is(""));
    }

    @Test
    public void shouldRetrieveAnInstance(){
        assertThat(ShadowPasswordTransformationMethod.getInstance(), is(CoreMatchers.<Object>notNullValue()));
    }
}