Skip to content

Commit 7ba2146

Browse files
committed
Extracted method: SiteServiceTest.getAuthFailedType() -> TestObjects.createAuthFailedActivityType()
No functional changes.
1 parent 8f2f6e7 commit 7ba2146

File tree

2 files changed

+32
-20
lines changed

2 files changed

+32
-20
lines changed

src/test/java/ru/mystamps/web/service/SiteServiceTest.java

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,8 @@ public void logAboutAbsentPageShouldPassEmptyStringToDaoForUnknownUserAgent() {
233233

234234
@Test
235235
public void logAboutFailedAuthenticationShouldCallDao() {
236-
when(suspiciousActivityTypeDao.findByName(anyString())).thenReturn(getAuthFailedType());
236+
when(suspiciousActivityTypeDao.findByName(anyString()))
237+
.thenReturn(TestObjects.createAuthFailedActivityType());
237238

238239
service.logAboutFailedAuthentication(TEST_PAGE, null, null, null, null);
239240

@@ -249,7 +250,7 @@ public void logAboutFailedAuthenticationShouldThrowExceptionWhenActivityTypeNotF
249250

250251
@Test
251252
public void logAboutFailedAuthenticationShouldPassActivityTypeToDao() {
252-
SuspiciousActivityType expectedType = getAuthFailedType();
253+
SuspiciousActivityType expectedType = TestObjects.createAuthFailedActivityType();
253254
when(suspiciousActivityTypeDao.findByName(anyString())).thenReturn(expectedType);
254255

255256
service.logAboutFailedAuthentication(TEST_PAGE, null, null, null, null);
@@ -261,7 +262,8 @@ public void logAboutFailedAuthenticationShouldPassActivityTypeToDao() {
261262

262263
@Test
263264
public void logAboutFailedAuthenticationShouldAssignOccuredAtToCurrentDate() {
264-
when(suspiciousActivityTypeDao.findByName(anyString())).thenReturn(getAuthFailedType());
265+
when(suspiciousActivityTypeDao.findByName(anyString()))
266+
.thenReturn(TestObjects.createAuthFailedActivityType());
265267

266268
service.logAboutFailedAuthentication(TEST_PAGE, null, null, null, null);
267269

@@ -272,14 +274,16 @@ public void logAboutFailedAuthenticationShouldAssignOccuredAtToCurrentDate() {
272274

273275
@Test(expected = IllegalArgumentException.class)
274276
public void logAboutFailedAuthenticationShouldThrowExceptionWhenPageIsNull() {
275-
when(suspiciousActivityTypeDao.findByName(anyString())).thenReturn(getAuthFailedType());
277+
when(suspiciousActivityTypeDao.findByName(anyString()))
278+
.thenReturn(TestObjects.createAuthFailedActivityType());
276279

277280
service.logAboutFailedAuthentication(null, null, null, null, null);
278281
}
279282

280283
@Test
281284
public void logAboutFailedAuthenticationShouldPassPageToDao() {
282-
when(suspiciousActivityTypeDao.findByName(anyString())).thenReturn(getAuthFailedType());
285+
when(suspiciousActivityTypeDao.findByName(anyString()))
286+
.thenReturn(TestObjects.createAuthFailedActivityType());
283287

284288
service.logAboutFailedAuthentication(TEST_PAGE, null, null, null, null);
285289

@@ -290,7 +294,8 @@ public void logAboutFailedAuthenticationShouldPassPageToDao() {
290294

291295
@Test
292296
public void logAboutFailedAuthenticationShouldPassNullToDaoForUnknownUser() {
293-
when(suspiciousActivityTypeDao.findByName(anyString())).thenReturn(getAuthFailedType());
297+
when(suspiciousActivityTypeDao.findByName(anyString()))
298+
.thenReturn(TestObjects.createAuthFailedActivityType());
294299

295300
service.logAboutFailedAuthentication(TEST_PAGE, null, null, null, null);
296301

@@ -302,7 +307,8 @@ public void logAboutFailedAuthenticationShouldPassNullToDaoForUnknownUser() {
302307
@Test
303308
public void logAboutFailedAuthenticationShouldPassUserToDao() {
304309
User user = getUser();
305-
when(suspiciousActivityTypeDao.findByName(anyString())).thenReturn(getAuthFailedType());
310+
when(suspiciousActivityTypeDao.findByName(anyString()))
311+
.thenReturn(TestObjects.createAuthFailedActivityType());
306312

307313
service.logAboutFailedAuthentication(TEST_PAGE, user, null, null, null);
308314

@@ -313,7 +319,8 @@ public void logAboutFailedAuthenticationShouldPassUserToDao() {
313319

314320
@Test
315321
public void logAboutFailedAuthenticationShouldPassIpToDao() {
316-
when(suspiciousActivityTypeDao.findByName(anyString())).thenReturn(getAuthFailedType());
322+
when(suspiciousActivityTypeDao.findByName(anyString()))
323+
.thenReturn(TestObjects.createAuthFailedActivityType());
317324

318325
service.logAboutFailedAuthentication(TEST_PAGE, null, TEST_IP, null, null);
319326

@@ -324,7 +331,8 @@ public void logAboutFailedAuthenticationShouldPassIpToDao() {
324331

325332
@Test
326333
public void logAboutFailedAuthenticationShouldPassEmptyStringToDaoForUnknownIp() {
327-
when(suspiciousActivityTypeDao.findByName(anyString())).thenReturn(getAuthFailedType());
334+
when(suspiciousActivityTypeDao.findByName(anyString()))
335+
.thenReturn(TestObjects.createAuthFailedActivityType());
328336

329337
service.logAboutFailedAuthentication(TEST_PAGE, null, null, null, null);
330338

@@ -335,7 +343,8 @@ public void logAboutFailedAuthenticationShouldPassEmptyStringToDaoForUnknownIp()
335343

336344
@Test
337345
public void logAboutFailedAuthenticationShouldPassRefererToDao() {
338-
when(suspiciousActivityTypeDao.findByName(anyString())).thenReturn(getAuthFailedType());
346+
when(suspiciousActivityTypeDao.findByName(anyString()))
347+
.thenReturn(TestObjects.createAuthFailedActivityType());
339348

340349
service.logAboutFailedAuthentication(TEST_PAGE, null, null, TEST_REFERER_PAGE, null);
341350

@@ -346,7 +355,8 @@ public void logAboutFailedAuthenticationShouldPassRefererToDao() {
346355

347356
@Test
348357
public void logAboutFailedAuthenticationShouldPassEmptyStringToDaoForUnknownReferer() {
349-
when(suspiciousActivityTypeDao.findByName(anyString())).thenReturn(getAuthFailedType());
358+
when(suspiciousActivityTypeDao.findByName(anyString()))
359+
.thenReturn(TestObjects.createAuthFailedActivityType());
350360

351361
service.logAboutFailedAuthentication(TEST_PAGE, null, null, null, null);
352362

@@ -357,7 +367,8 @@ public void logAboutFailedAuthenticationShouldPassEmptyStringToDaoForUnknownRefe
357367

358368
@Test
359369
public void logAboutFailedAuthenticationShouldPassUserAgentToDao() {
360-
when(suspiciousActivityTypeDao.findByName(anyString())).thenReturn(getAuthFailedType());
370+
when(suspiciousActivityTypeDao.findByName(anyString()))
371+
.thenReturn(TestObjects.createAuthFailedActivityType());
361372

362373
service.logAboutFailedAuthentication(TEST_PAGE, null, null, null, TEST_USER_AGENT);
363374

@@ -368,7 +379,8 @@ public void logAboutFailedAuthenticationShouldPassUserAgentToDao() {
368379

369380
@Test
370381
public void logAboutFailedAuthenticationShouldPassEmptyStringToDaoForUnknownUserAgent() {
371-
when(suspiciousActivityTypeDao.findByName(anyString())).thenReturn(getAuthFailedType());
382+
when(suspiciousActivityTypeDao.findByName(anyString()))
383+
.thenReturn(TestObjects.createAuthFailedActivityType());
372384

373385
service.logAboutFailedAuthentication(TEST_PAGE, null, null, null, null);
374386

@@ -377,13 +389,6 @@ public void logAboutFailedAuthenticationShouldPassEmptyStringToDaoForUnknownUser
377389
assertThat(activityCaptor.getValue().getUserAgent()).isEmpty();
378390
}
379391

380-
private SuspiciousActivityType getAuthFailedType() {
381-
SuspiciousActivityType type = new SuspiciousActivityType();
382-
type.setId(2);
383-
type.setName("AuthenticationFailed");
384-
return type;
385-
}
386-
387392
private User getUser() {
388393
final Integer anyId = 777;
389394
User user = new User();

src/test/java/ru/mystamps/web/service/TestObjects.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,11 @@ public static SuspiciousActivityType createPageNotFoundActivityType() {
5959
return type;
6060
}
6161

62+
public static SuspiciousActivityType createAuthFailedActivityType() {
63+
SuspiciousActivityType type = new SuspiciousActivityType();
64+
type.setId(2);
65+
type.setName("AuthenticationFailed");
66+
return type;
67+
}
68+
6269
}

0 commit comments

Comments
 (0)