@@ -17,14 +17,13 @@ public class TestToopherAPI {
17
17
18
18
private static String AUTH_REQUEST_JSON = "{'id':'1', 'granted':true, 'pending':true,'automated':true, 'reason':'test', 'terminal':{'id':'1','name':'some user'}}" .replace ("'" , "\" " );
19
19
private final String BASE_URI_STRING = "https://api.toopher.test/v1/" ;
20
- private final String CONSUMER_KEY = "key" ;
20
+ private final String CONSUMER_KEY = "key" ;
21
21
private final String CONSUMER_SECRET = "secret" ;
22
- private final String PAIRING_ID = "pairing_id" ;
23
- private final String TERMINAL_NAME = "terminal_name" ;
24
- private final String ACTION_NAME = "action_name" ;
22
+ private final String PAIRING_ID = "pairing_id" ;
23
+ private final String TERMINAL_NAME = "terminal_name" ;
24
+ private final String ACTION_NAME = "action_name" ;
25
25
private final String USER_NAME = "user_name" ;
26
26
27
-
28
27
@ Test
29
28
public void testCreatePairing () throws InterruptedException , RequestError {
30
29
HttpClientMock httpClient = new HttpClientMock (200 ,
@@ -36,7 +35,7 @@ public void testCreatePairing() throws InterruptedException, RequestError {
36
35
37
36
assertEquals (httpClient .getLastCalledMethod (), "POST" );
38
37
assertEquals (httpClient .getLastCalledData ("pairing_phrase" ), "awkward turtle" );
39
-
38
+
40
39
assertEquals (pairing .userId , "1" );
41
40
assertEquals (pairing .userName , "some user" );
42
41
assertTrue (pairing .pending );
@@ -62,32 +61,25 @@ public void testGetPairingStatus() throws InterruptedException, RequestError {
62
61
63
62
@ Test
64
63
public void testAuthenticateWithActionName () throws InterruptedException , RequestError {
65
- String pairingId = "pairing ID" ;
66
- String terminalName = "my computer" ;
67
- String actionName = "action" ;
68
64
HttpClientMock httpClient = new HttpClientMock (200 , AUTH_REQUEST_JSON );
69
65
ToopherAPI toopherApi = new ToopherAPI ("key" , "secret" ,
70
66
createURI ("https://api.toopher.test/v1/" ), httpClient );
71
- try {
72
- toopherApi .authenticate (pairingId , terminalName , actionName );
73
- } catch (RequestError re ){}
67
+ toopherApi .authenticate (PAIRING_ID , TERMINAL_NAME , ACTION_NAME );
74
68
assertEquals (httpClient .getLastCalledMethod (), "POST" );
75
- assertEquals (httpClient .getLastCalledData ("pairing_id" ), pairingId );
76
- assertEquals (httpClient .getLastCalledData ("terminal_name" ), terminalName );
77
- assertEquals (httpClient .getLastCalledData ("action_name" ), actionName );
69
+ assertEquals (httpClient .getLastCalledData ("pairing_id" ), PAIRING_ID );
70
+ assertEquals (httpClient .getLastCalledData ("terminal_name" ), TERMINAL_NAME );
71
+ assertEquals (httpClient .getLastCalledData ("action_name" ), ACTION_NAME );
78
72
}
79
73
80
74
@ Test
81
75
public void testAuthenticateThrowingRequestError () throws InterruptedException , RequestError {
82
- String pairingId = "pairing ID" ;
83
- String terminalName = "my computer" ;
84
76
HttpClientMock httpClient = new HttpClientMock (200 , "{'id':'1'}" );
85
77
ToopherAPI toopherApi = new ToopherAPI ("key" , "secret" ,
86
78
createURI ("https://api.toopher.test/v1/" ), httpClient );
87
79
try {
88
- toopherApi .authenticate (pairingId , terminalName );
89
- } catch ( RequestError re ){
90
- assertTrue ( true );
80
+ toopherApi .authenticate (PAIRING_ID , TERMINAL_NAME );
81
+ fail ();
82
+ } catch ( RequestError re ) {
91
83
}
92
84
}
93
85
@@ -97,7 +89,7 @@ public void testAuthenticateWithTerminalName() throws InterruptedException, Requ
97
89
String terminalName = "my computer" ;
98
90
HttpClientMock httpClient = new HttpClientMock (200 , AUTH_REQUEST_JSON );
99
91
ToopherAPI toopherApi = new ToopherAPI ("key" , "secret" ,
100
- createURI ("https://api.toopher.test/v1/" ), httpClient );
92
+ createURI ("https://api.toopher.test/v1/" ), httpClient );
101
93
toopherApi .authenticate (pairingId , terminalName );
102
94
assertEquals (httpClient .getLastCalledMethod (), "POST" );
103
95
assertEquals (httpClient .getLastCalledData ("pairing_id" ), pairingId );
@@ -122,17 +114,15 @@ public void testAuthenticateWithExtras() throws InterruptedException, RequestErr
122
114
assertEquals (httpClient .getLastCalledData ("extra_parameter" ), extraParameter );
123
115
}
124
116
125
-
126
-
127
117
@ Test
128
118
public void testAuthenticateByUserNameNoExtras () throws InterruptedException , RequestError {
129
119
String extraTerminalName = "terminalNameExtra" ;
130
120
String userName = "userName" ;
131
121
String actionName = "action" ;
132
122
HttpClientMock httpClient = new HttpClientMock (200 , AUTH_REQUEST_JSON );
133
123
ToopherAPI toopherApi = new ToopherAPI ("key" , "secret" ,
134
- createURI ("https://api.toopher.test/v1/" ), httpClient );
135
- toopherApi .authenticateByUserName (userName , extraTerminalName , actionName , null );
124
+ createURI ("https://api.toopher.test/v1/" ), httpClient );
125
+ toopherApi .authenticateByUserName (userName , extraTerminalName , actionName , null );
136
126
assertEquals (httpClient .getLastCalledData ("user_name" ), userName );
137
127
assertEquals (httpClient .getLastCalledData ("terminal_name_extra" ), extraTerminalName );
138
128
assertEquals (httpClient .getLastCalledData ("action_name" ), actionName );
@@ -147,7 +137,7 @@ public void testAuthenticateByUserNameWithExtras() throws InterruptedException,
147
137
HttpClientMock httpClient = new HttpClientMock (200 , AUTH_REQUEST_JSON );
148
138
ToopherAPI toopherApi = new ToopherAPI ("key" , "secret" ,
149
139
createURI ("https://api.toopher.test/v1/" ), httpClient );
150
- toopherApi .authenticateByUserName (userName , extraTerminalName , actionName , extras );
140
+ toopherApi .authenticateByUserName (userName , extraTerminalName , actionName , extras );
151
141
assertEquals (httpClient .getLastCalledData ("user_name" ), userName );
152
142
assertEquals (httpClient .getLastCalledData ("terminal_name_extra" ), extraTerminalName );
153
143
assertEquals (httpClient .getLastCalledData ("action_name" ), actionName );
@@ -174,9 +164,11 @@ public void testGetAuthenticationStatusThrowRequestError() throws InterruptedExc
174
164
HttpClientMock httpClient = new HttpClientMock (200 , "{'id':'1'}" );
175
165
ToopherAPI toopherApi = new ToopherAPI ("key" , "secret" ,
176
166
createURI ("https://api.toopher.test/v1/" ), httpClient );
177
- try {
167
+ try {
178
168
toopherApi .getAuthenticationStatus ("1" );
179
- } catch (RequestError re ){}
169
+ fail ("My method didn't throw when I expected it to" );
170
+ } catch (RequestError re ) {
171
+ }
180
172
}
181
173
182
174
@ Test
@@ -200,22 +192,21 @@ public void testGetAuthenticationStatusWithOTPThrowRequestError() throws Interru
200
192
HttpClientMock httpClient = new HttpClientMock (200 , "{'id':'1'}" );
201
193
ToopherAPI toopherApi = new ToopherAPI ("key" , "secret" ,
202
194
createURI ("https://api.toopher.test/v1/" ), httpClient );
203
- try {
195
+ try {
204
196
toopherApi .getAuthenticationStatusWithOTP ("1" , "ImAPassword" );
205
- } catch (RequestError re ){}
197
+ } catch (RequestError re ) {
198
+ }
206
199
}
207
200
208
201
@ Test
209
202
public void testAssignUserFriendlyNameToTerminal () throws InterruptedException , RequestError {
210
203
HttpClientMock httpClient = new HttpClientMock (200 , AUTH_REQUEST_JSON );
211
204
ToopherAPI toopherApi = new ToopherAPI ("key" , "secret" ,
212
205
createURI ("https://api.toopher.test/v1/" ), httpClient );
213
- String userName = "some user" ;
214
- String terminalName = "my computer" ;
215
- String extraTerminalName = "my extra computer" ;
216
- toopherApi .assignUserFriendlyNameToTerminal (userName , terminalName , extraTerminalName );
217
- assertEquals (httpClient .getLastCalledData ("user_name" ), userName );
218
- assertEquals (httpClient .getLastCalledData ("name" ), terminalName );
206
+ final String extraTerminalName = "my extra computer" ;
207
+ toopherApi .assignUserFriendlyNameToTerminal (USER_NAME , TERMINAL_NAME , extraTerminalName );
208
+ assertEquals (httpClient .getLastCalledData ("user_name" ), USER_NAME );
209
+ assertEquals (httpClient .getLastCalledData ("name" ), TERMINAL_NAME );
219
210
assertEquals (httpClient .getLastCalledData ("name_extra" ), extraTerminalName );
220
211
}
221
212
@@ -247,7 +238,8 @@ public void testEnableToopherForUserWhenUserNameIsNotPresent() throws Interrupte
247
238
try {
248
239
toopherApi .setToopherEnabledForUser ("1" , true );
249
240
fail ();
250
- } catch (RequestError re ) {}
241
+ } catch (RequestError re ) {
242
+ }
251
243
}
252
244
253
245
@ Test
@@ -261,7 +253,8 @@ public void testEnableToopherForUserWithDuplicateUserName() throws InterruptedEx
261
253
try {
262
254
toopherApi .setToopherEnabledForUser ("1" , true );
263
255
fail ();
264
- } catch (RequestError re ) {}
256
+ } catch (RequestError re ) {
257
+ }
265
258
}
266
259
267
260
@ Test
@@ -279,7 +272,7 @@ public void testCreateQrPairing() throws InterruptedException, RequestError {
279
272
assertTrue (pairing .enabled );
280
273
}
281
274
282
- public URI createURI (String url ) {
275
+ private URI createURI (String url ) {
283
276
try {
284
277
return new URL (url ).toURI ();
285
278
} catch (MalformedURLException e ) {
@@ -305,7 +298,7 @@ public void testVersion() {
305
298
}
306
299
307
300
@ Test
308
- public void testAuthenticationStatusFactory () throws InterruptedException , URISyntaxException {
301
+ public void testAuthenticationStatusFactoryBuildsValidJSON () throws InterruptedException , URISyntaxException {
309
302
HttpClientMock clientMock = new HttpClientMock (200 , "{}" );
310
303
AuthenticationStatusFactoryMock factoryMock = new AuthenticationStatusFactoryMock ();
311
304
@@ -317,7 +310,9 @@ public void testAuthenticationStatusFactory() throws InterruptedException, URISy
317
310
318
311
try {
319
312
api .authenticate (PAIRING_ID , TERMINAL_NAME );
320
- } catch (RequestError re ) { fail (); }
313
+ } catch (RequestError re ) {
314
+ fail ();
315
+ }
321
316
}
322
317
323
318
@ Test
@@ -337,7 +332,8 @@ public void testParseRequestErrorUserDisabled() throws InterruptedException, URI
337
332
try {
338
333
toopherApi .authenticateByUserName (USER_NAME , TERMINAL_NAME , ACTION_NAME , null );
339
334
fail ();
340
- } catch (ToopherUserDisabledError toopherUserDisabledError ){}
335
+ } catch (ToopherUserDisabledError toopherUserDisabledError ) {
336
+ }
341
337
342
338
}
343
339
@@ -358,7 +354,8 @@ public void testParseRequestErrorUnknownUser() throws InterruptedException, URIS
358
354
try {
359
355
toopherApi .authenticateByUserName (USER_NAME , TERMINAL_NAME , ACTION_NAME , null );
360
356
fail ();
361
- } catch (ToopherUnknownUserError toopherUnknownUserError ){}
357
+ } catch (ToopherUnknownUserError toopherUnknownUserError ) {
358
+ }
362
359
363
360
}
364
361
@@ -379,7 +376,8 @@ public void testParseRequestErrorUnknownTerminal() throws InterruptedException,
379
376
try {
380
377
toopherApi .authenticateByUserName (USER_NAME , TERMINAL_NAME , ACTION_NAME , null );
381
378
fail ();
382
- } catch (ToopherUnknownTerminalError toopherUnknownTerminalError ){}
379
+ } catch (ToopherUnknownTerminalError toopherUnknownTerminalError ) {
380
+ }
383
381
384
382
}
385
383
@@ -400,7 +398,8 @@ public void testParseRequestErrorClient() throws InterruptedException, URISyntax
400
398
try {
401
399
toopherApi .authenticateByUserName (USER_NAME , TERMINAL_NAME , ACTION_NAME , null );
402
400
fail ();
403
- } catch (ToopherClientError toopherClientError ){}
401
+ } catch (ToopherClientError toopherClientError ) {
402
+ }
404
403
405
404
}
406
405
@@ -421,7 +420,8 @@ public void testParseRequestErrorNotJSON() throws InterruptedException, URISynta
421
420
try {
422
421
toopherApi .authenticateByUserName (USER_NAME , TERMINAL_NAME , ACTION_NAME , null );
423
422
fail ();
424
- } catch (RequestError re ){}
423
+ } catch (RequestError re ) {
424
+ }
425
425
426
426
}
427
427
0 commit comments