|
8 | 8 | import java.util.List; |
9 | 9 |
|
10 | 10 | import static org.hamcrest.MatcherAssert.assertThat; |
11 | | -import static org.hamcrest.Matchers.equalTo; |
12 | 11 | import static org.hamcrest.Matchers.notNullValue; |
13 | 12 | import static org.hamcrest.core.Is.is; |
14 | 13 |
|
15 | 14 | public class AuthenticationTest { |
16 | 15 | @Test |
17 | 16 | public void constructorWithMethod() { |
18 | | - for ( AuthenticationMethod authenticationMethod : AuthenticationMethod.values() ) { |
19 | | - Authentication authentication = new Authentication( authenticationMethod ); |
20 | | - assertThat( "method is not set correctly for " + authenticationMethod.name(), authentication.getMethod(), is( equalTo( authenticationMethod ) ) ); |
| 17 | + for (AuthenticationMethod authenticationMethod : AuthenticationMethod.values()) { |
| 18 | + Authentication authentication = new Authentication(authenticationMethod); |
| 19 | + assertThat("method is not set correctly for " + authenticationMethod.name(), authentication.getMethod(), is(authenticationMethod)); |
21 | 20 | } |
22 | 21 | } |
23 | 22 |
|
24 | 23 | private List<Challenge> challenges; |
25 | 24 |
|
26 | 25 | private Authentication newChallengeAuthentication() { |
27 | 26 | challenges = new ArrayList<Challenge>(); |
28 | | - challenges.add( new Challenge( "one", "two" ) ); |
29 | | - challenges.add( new Challenge( "three", "four" ) ); |
30 | | - challenges.add( new Challenge( "four", "five" ) ); |
31 | | - return new Authentication( challenges ); |
| 27 | + challenges.add(new Challenge("one", "two")); |
| 28 | + challenges.add(new Challenge("three", "four")); |
| 29 | + challenges.add(new Challenge("four", "five")); |
| 30 | + return new Authentication(challenges); |
32 | 31 | } |
33 | 32 |
|
34 | 33 | @Test |
35 | 34 | public void constructorWithListOfChallenges() { |
36 | 35 | Authentication authentication = newChallengeAuthentication(); |
37 | 36 |
|
38 | | - assertThat( "method not set correctly", authentication.getMethod(), is( equalTo( AuthenticationMethod.CHALLENGE ) ) ); |
39 | | - assertThat( "challenges list is null", authentication.getChallenges(), is( notNullValue() ) ); |
40 | | - assertThat( "challenges list is wrong size", authentication.getChallenges().size(), is( equalTo( challenges.size() ) ) ); |
41 | | - for ( int i = 0; i < challenges.size(); i++ ) { |
42 | | - assertThat( "challenge question #" + i + " is not set correctly", authentication.getChallenges().get( i ).getQuestion(), is( equalTo( challenges.get( i ).getQuestion() ) ) ); |
43 | | - assertThat( "challenge answer #" + i + " is not set correctly", authentication.getChallenges().get( i ).getAnswer(), is( equalTo( challenges.get( i ).getAnswer() ) ) ); |
| 37 | + assertThat("method not set correctly", authentication.getMethod(), is(AuthenticationMethod.CHALLENGE)); |
| 38 | + assertThat("challenges list is null", authentication.getChallenges(), notNullValue()); |
| 39 | + assertThat("challenges list is wrong size", authentication.getChallenges().size(), is(challenges.size())); |
| 40 | + for (int i = 0; i < challenges.size(); i++) { |
| 41 | + assertThat("challenge question #" + i + " is not set correctly", authentication.getChallenges().get(i).getQuestion(), is(challenges.get(i).getQuestion())); |
| 42 | + assertThat("challenge answer #" + i + " is not set correctly", authentication.getChallenges().get(i).getAnswer(), is(challenges.get(i).getAnswer())); |
44 | 43 | } |
45 | 44 | } |
46 | 45 |
|
47 | 46 | private String phoneNumber; |
48 | 47 |
|
49 | 48 | public Authentication newSMSAuthentication() { |
50 | 49 | phoneNumber = "1234567890"; |
51 | | - return new Authentication( phoneNumber ); |
| 50 | + return new Authentication(phoneNumber); |
52 | 51 | } |
53 | 52 |
|
54 | 53 | @Test |
55 | 54 | public void constructorWithTelephoneNumber() { |
56 | 55 | Authentication authentication = newSMSAuthentication(); |
57 | 56 |
|
58 | | - assertThat( "authentication method is not being set to sms", authentication.getMethod(), is( equalTo( AuthenticationMethod.SMS ) ) ); |
59 | | - assertThat( "phone number is not set correctly", authentication.getPhoneNumber(), is( equalTo( phoneNumber ) ) ); |
| 57 | + assertThat("authentication method is not being set to sms", authentication.getMethod(), is(AuthenticationMethod.SMS)); |
| 58 | + assertThat("phone number is not set correctly", authentication.getPhoneNumber(), is(phoneNumber)); |
60 | 59 | } |
61 | 60 |
|
62 | 61 | private Authentication newEmailAuthentication() { |
63 | | - return new Authentication( AuthenticationMethod.EMAIL ); |
| 62 | + return new Authentication(AuthenticationMethod.EMAIL); |
64 | 63 | } |
65 | 64 |
|
66 | 65 | @Test |
67 | 66 | public void emailAuthToAPIAuth() { |
68 | 67 | Authentication authentication = newEmailAuthentication(); |
69 | 68 | Auth auth = new AuthenticationConverter(authentication).toAPIAuthentication(); |
70 | | - assertThat("Null value was returned by converter", auth, is(notNullValue())); |
71 | | - assertThat( "AuthScheme was not set to NONE", auth.getScheme(), is( equalTo( "NONE" ) ) ); |
| 69 | + assertThat("Null value was returned by converter", auth, notNullValue()); |
| 70 | + assertThat("AuthScheme was not set to NONE", auth.getScheme(), is("NONE")); |
72 | 71 | } |
73 | 72 |
|
74 | 73 | @Test |
75 | 74 | public void challengeAuthToAPIAuth() { |
76 | 75 | Authentication authentication = newChallengeAuthentication(); |
77 | 76 | Auth auth = new AuthenticationConverter(authentication).toAPIAuthentication(); |
78 | | - assertThat("Null value was returned by converter", auth, is(notNullValue())); |
79 | | - assertThat( "AuthScheme was not set to CHALLENGE", auth.getScheme(), is( equalTo( "CHALLENGE" ) ) ); |
80 | | - assertThat( "Challenge list was set to null", auth.getChallenges(), is( notNullValue() ) ); |
81 | | - assertThat( "Challenge list did not contain the expected number of elements", auth.getChallenges().size(), is( equalTo( challenges.size() ) ) ); |
82 | | - for ( int i = 0; i < challenges.size(); i++ ) { |
83 | | - assertThat( "Challenge question #" + i + " + was not set correctly", auth.getChallenges().get( i ).getQuestion(), is( equalTo( challenges.get( i ).getQuestion() ) ) ); |
84 | | - assertThat( "Challenge answer #" + i + " + was not set correctly", auth.getChallenges().get( i ).getAnswer(), is( equalTo( challenges.get( i ).getAnswer() ) ) ); |
| 77 | + assertThat("Null value was returned by converter", auth, notNullValue()); |
| 78 | + assertThat("AuthScheme was not set to CHALLENGE", auth.getScheme(), is("CHALLENGE")); |
| 79 | + assertThat("Challenge list was set to null", auth.getChallenges(), notNullValue()); |
| 80 | + assertThat("Challenge list did not contain the expected number of elements", auth.getChallenges().size(), is(challenges.size())); |
| 81 | + for (int i = 0; i < challenges.size(); i++) { |
| 82 | + assertThat("Challenge question #" + i + " + was not set correctly", auth.getChallenges().get(i).getQuestion(), is(challenges.get(i).getQuestion())); |
| 83 | + assertThat("Challenge answer #" + i + " + was not set correctly", auth.getChallenges().get(i).getAnswer(), is(challenges.get(i).getAnswer())); |
85 | 84 | } |
86 | 85 | } |
87 | 86 |
|
88 | 87 | @Test |
89 | 88 | public void smsAuthToAPIAuth() { |
90 | 89 | Authentication authentication = newSMSAuthentication(); |
91 | 90 | Auth auth = new AuthenticationConverter(authentication).toAPIAuthentication(); |
92 | | - assertThat("AuthScheme was not set to SMS", auth.getScheme(), is(equalTo("SMS"))); |
93 | | - assertThat( "Challenges list was null (should hold phone number)", auth.getChallenges(), notNullValue() ); |
94 | | - assertThat( "Challenges list was not length 1", auth.getChallenges().size(), is( equalTo( 1 ) ) ); |
95 | | - assertThat( "First challenge item should hold the phone number as question, but didn't", auth.getChallenges().get( 0 ).getQuestion(), is( equalTo( phoneNumber ) ) ); |
96 | | - assertThat( "First challenge answer should be blank", auth.getChallenges().get( 0 ).getAnswer(), is( notNullValue() ) ); |
| 91 | + assertThat("AuthScheme was not set to SMS", auth.getScheme(), is("SMS")); |
| 92 | + assertThat("Challenges list was null (should hold phone number)", auth.getChallenges(), notNullValue()); |
| 93 | + assertThat("Challenges list was not length 1", auth.getChallenges().size(), is(1)); |
| 94 | + assertThat("First challenge item should hold the phone number as question, but didn't", auth.getChallenges().get(0).getQuestion(), is(phoneNumber)); |
| 95 | + assertThat("First challenge answer should be blank", auth.getChallenges().get(0).getAnswer(), notNullValue()); |
97 | 96 | } |
98 | 97 | } |
0 commit comments