@@ -82,7 +82,9 @@ public class UserServiceTest {
82
82
83
83
@ Before
84
84
public void setUp () {
85
- when (encoder .encodePassword (anyString (), anyString ())).thenReturn (TEST_HASH );
85
+ User user = getValidUser ();
86
+
87
+ when (encoder .encodePassword (anyString (), anyString ())).thenReturn (user .getHash ());
86
88
87
89
UsersActivation activation = TestObjects .createUsersActivation ();
88
90
when (usersActivationDao .findOne (anyString ())).thenReturn (activation );
@@ -91,9 +93,9 @@ public void setUp() {
91
93
registrationForm .setEmail ("john.dou@example.org" );
92
94
93
95
activationForm = new ActivateAccountForm ();
94
- activationForm .setLogin (TEST_LOGIN );
96
+ activationForm .setLogin (user . getLogin () );
95
97
activationForm .setPassword (TEST_PASSWORD );
96
- activationForm .setName (TEST_NAME );
98
+ activationForm .setName (user . getName () );
97
99
activationForm .setActivationKey (activation .getActivationKey ());
98
100
99
101
service = new UserServiceImpl (userDao , usersActivationDao , encoder );
@@ -240,33 +242,37 @@ public void registerUserShouldDoNothingWhenRegistrationRequestNotFound() {
240
242
241
243
@ Test
242
244
public void registerUserShouldPassNameToDao () {
245
+ String expectedUserName = activationForm .getName ();
246
+
243
247
service .registerUser (activationForm );
244
248
245
249
verify (userDao ).save (userCaptor .capture ());
246
250
247
- assertThat (userCaptor .getValue ().getName ()).isEqualTo (TEST_NAME );
251
+ assertThat (userCaptor .getValue ().getName ()).isEqualTo (expectedUserName );
248
252
}
249
253
250
254
@ Test
251
255
public void registerUserShouldPassLoginInsteadOfNameWhenNameIsNull () {
256
+ String expectedUserLogin = activationForm .getLogin ();
252
257
activationForm .setName (null );
253
258
254
259
service .registerUser (activationForm );
255
260
256
261
verify (userDao ).save (userCaptor .capture ());
257
262
258
- assertThat (userCaptor .getValue ().getName ()).isEqualTo (TEST_LOGIN );
263
+ assertThat (userCaptor .getValue ().getName ()).isEqualTo (expectedUserLogin );
259
264
}
260
265
261
266
@ Test
262
267
public void registerUserShouldPassLoginInsteadOfNameWhenNameIsEmpty () {
268
+ String expectedUserLogin = activationForm .getLogin ();
263
269
activationForm .setName ("" );
264
270
265
271
service .registerUser (activationForm );
266
272
267
273
verify (userDao ).save (userCaptor .capture ());
268
274
269
- assertThat (userCaptor .getValue ().getName ()).isEqualTo (TEST_LOGIN );
275
+ assertThat (userCaptor .getValue ().getName ()).isEqualTo (expectedUserLogin );
270
276
}
271
277
272
278
@ Test
@@ -326,7 +332,7 @@ public void registerUserShouldThrowExceptionWhenPasswordIsNull() {
326
332
327
333
@ Test
328
334
public void registerUserShouldGetsHashFromEncoder () {
329
- String expectedHash = TEST_HASH ;
335
+ String expectedHash = getValidUser (). getHash () ;
330
336
331
337
when (encoder .encodePassword (anyString (), anyString ())).thenReturn (expectedHash );
332
338
@@ -355,11 +361,13 @@ public void registerUserShouldThrowExceptionWhenLoginIsNull() {
355
361
356
362
@ Test
357
363
public void registerUserShouldPassLoginToDao () {
364
+ String expectedUserLogin = activationForm .getLogin ();
365
+
358
366
service .registerUser (activationForm );
359
367
360
368
verify (userDao ).save (userCaptor .capture ());
361
369
362
- assertThat (userCaptor .getValue ().getLogin ()).isEqualTo (TEST_LOGIN );
370
+ assertThat (userCaptor .getValue ().getLogin ()).isEqualTo (expectedUserLogin );
363
371
}
364
372
365
373
@ Test
@@ -385,15 +393,16 @@ public void findByLoginShouldCallDao() {
385
393
User expectedUser = getValidUser ();
386
394
when (userDao .findByLogin (anyString ())).thenReturn (expectedUser );
387
395
388
- User user = service .findByLogin (TEST_LOGIN );
396
+ User user = service .findByLogin ("any-login" );
389
397
390
398
assertThat (user ).isEqualTo (expectedUser );
391
399
}
392
400
393
401
@ Test
394
402
public void findByLoginShouldPassLoginToDao () {
395
- service .findByLogin (TEST_LOGIN );
396
- verify (userDao ).findByLogin (TEST_LOGIN );
403
+ service .findByLogin ("john" );
404
+
405
+ verify (userDao ).findByLogin ("john" );
397
406
}
398
407
399
408
static User getValidUser () {
0 commit comments