11package com .baeldung .temporaladjusters ;
22
3- import java .time .DayOfWeek ;
3+ import com .baeldung .temporaladjuster .CustomTemporalAdjuster ;
4+ import org .junit .Assert ;
5+ import org .junit .Test ;
6+
47import java .time .LocalDate ;
58import java .time .Period ;
69import java .time .temporal .TemporalAdjuster ;
7- import java .time .temporal .TemporalAdjusters ;
8-
9- import org .junit .Assert ;
10- import org .junit .Test ;
1110
12- import com . baeldung . temporaladjuster . CustomTemporalAdjuster ;
11+ import static org . junit . Assert . assertEquals ;
1312
1413public class CustomTemporalAdjusterTest {
1514
15+ private static final TemporalAdjuster NEXT_WORKING_DAY = new CustomTemporalAdjuster ();
16+
1617 @ Test
1718 public void whenAdjustAndImplementInterface_thenNextWorkingDay () {
1819 LocalDate localDate = LocalDate .of (2017 , 07 , 8 );
1920 CustomTemporalAdjuster temporalAdjuster = new CustomTemporalAdjuster ();
2021 LocalDate nextWorkingDay = localDate .with (temporalAdjuster );
2122
22- Assert . assertEquals ("2017-07-10" , nextWorkingDay .toString ());
23+ assertEquals ("2017-07-10" , nextWorkingDay .toString ());
2324 }
2425
2526 @ Test
2627 public void whenAdjust_thenNextWorkingDay () {
2728 LocalDate localDate = LocalDate .of (2017 , 07 , 8 );
28- TemporalAdjuster temporalAdjuster = NEXT_WORKING_DAY ;
29- LocalDate date = localDate .with (temporalAdjuster );
29+ LocalDate date = localDate .with (NEXT_WORKING_DAY );
3030
31- Assert . assertEquals ("2017-07-10" , date .toString ());
31+ assertEquals ("2017-07-10" , date .toString ());
3232 }
3333
3434 @ Test
@@ -39,18 +39,6 @@ public void whenAdjust_thenFourteenDaysAfterDate() {
3939
4040 String fourteenDaysAfterDate = "2017-07-22" ;
4141
42- Assert . assertEquals (fourteenDaysAfterDate , result .toString ());
42+ assertEquals (fourteenDaysAfterDate , result .toString ());
4343 }
44-
45- static TemporalAdjuster NEXT_WORKING_DAY = TemporalAdjusters .ofDateAdjuster (date -> {
46- DayOfWeek dayOfWeek = date .getDayOfWeek ();
47- int daysToAdd ;
48- if (dayOfWeek == DayOfWeek .FRIDAY )
49- daysToAdd = 3 ;
50- else if (dayOfWeek == DayOfWeek .SATURDAY )
51- daysToAdd = 2 ;
52- else
53- daysToAdd = 1 ;
54- return date .plusDays (daysToAdd );
55- });
5644}
0 commit comments