BAEL-994 - TemporalAdjuster in Java
This commit is contained in:
		
							parent
							
								
									62efeccfd0
								
							
						
					
					
						commit
						dc9ee11a79
					
				| @ -10,41 +10,40 @@ import org.junit.Assert; | |||||||
| import org.junit.Test; | import org.junit.Test; | ||||||
| 
 | 
 | ||||||
| import com.baeldung.temporaladjuster.CustomTemporalAdjuster; | import com.baeldung.temporaladjuster.CustomTemporalAdjuster; | ||||||
| import com.baeldung.temporaladjuster.TemporalAdjusterUtil; |  | ||||||
| 
 | 
 | ||||||
| public class CustomTemporalAdjusterTest { | public class CustomTemporalAdjusterTest { | ||||||
| 
 | 
 | ||||||
|     @Test |     @Test | ||||||
|     public void whenAdjustAndImplementInterface_thenNextWorkingDay() { |     public void whenAdjustAndImplementInterface_thenNextWorkingDay() { | ||||||
|         LocalDate localDate = LocalDate.now(); |         LocalDate localDate = LocalDate.of(2017, 07, 8); | ||||||
|         CustomTemporalAdjuster temporalAdjuster = new CustomTemporalAdjuster(); |         CustomTemporalAdjuster temporalAdjuster = new CustomTemporalAdjuster(); | ||||||
|         LocalDate nextWorkingDay = localDate.with(temporalAdjuster); |         LocalDate nextWorkingDay = localDate.with(temporalAdjuster); | ||||||
| 
 | 
 | ||||||
|         Assert.assertEquals(TemporalAdjusterUtil.getNextWorkingDay(), nextWorkingDay.toString()); |         Assert.assertEquals("2017-07-10", nextWorkingDay.toString()); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @Test |     @Test | ||||||
|     public void whenAdjust_thenNextWorkingDay() { |     public void whenAdjust_thenNextWorkingDay() { | ||||||
|         LocalDate localDate = LocalDate.now(); |         LocalDate localDate = LocalDate.of(2017, 07, 8); | ||||||
|         TemporalAdjuster temporalAdjuster = NEXT_WORKING_DAY; |         TemporalAdjuster temporalAdjuster = NEXT_WORKING_DAY; | ||||||
|         LocalDate date = localDate.with(temporalAdjuster); |         LocalDate date = localDate.with(temporalAdjuster); | ||||||
| 
 | 
 | ||||||
|         Assert.assertEquals(TemporalAdjusterUtil.getNextWorkingDay(), date.toString()); |         Assert.assertEquals("2017-07-10", date.toString()); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @Test |     @Test | ||||||
|     public void whenAdjust_thenFourteenDaysFromToday() { |     public void whenAdjust_thenFourteenDaysAfterDate() { | ||||||
|         LocalDate localDate = LocalDate.now(); |         LocalDate localDate = LocalDate.of(2017, 07, 8); | ||||||
|         TemporalAdjuster temporalAdjuster = (t) -> t.plus(Period.ofDays(14)); |         TemporalAdjuster temporalAdjuster = (t) -> t.plus(Period.ofDays(14)); | ||||||
|         LocalDate result = localDate.with(temporalAdjuster); |         LocalDate result = localDate.with(temporalAdjuster); | ||||||
| 
 | 
 | ||||||
|         String fourteenDaysFromToday = "2017-07-22"; |         String fourteenDaysAfterDate = "2017-07-22"; | ||||||
| 
 | 
 | ||||||
|         Assert.assertEquals(fourteenDaysFromToday, result.toString()); |         Assert.assertEquals(fourteenDaysAfterDate, result.toString()); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     static TemporalAdjuster NEXT_WORKING_DAY = TemporalAdjusters.ofDateAdjuster(today -> { |     static TemporalAdjuster NEXT_WORKING_DAY = TemporalAdjusters.ofDateAdjuster(date -> { | ||||||
|         DayOfWeek dayOfWeek = today.getDayOfWeek(); |         DayOfWeek dayOfWeek = date.getDayOfWeek(); | ||||||
|         int daysToAdd; |         int daysToAdd; | ||||||
|         if (dayOfWeek == DayOfWeek.FRIDAY) |         if (dayOfWeek == DayOfWeek.FRIDAY) | ||||||
|             daysToAdd = 3; |             daysToAdd = 3; | ||||||
| @ -52,6 +51,6 @@ public class CustomTemporalAdjusterTest { | |||||||
|             daysToAdd = 2; |             daysToAdd = 2; | ||||||
|         else |         else | ||||||
|             daysToAdd = 1; |             daysToAdd = 1; | ||||||
|         return today.plusDays(daysToAdd); |         return date.plusDays(daysToAdd); | ||||||
|     }); |     }); | ||||||
| } | } | ||||||
|  | |||||||
| @ -11,7 +11,7 @@ public class TemporalAdjustersTest { | |||||||
| 
 | 
 | ||||||
|     @Test |     @Test | ||||||
|     public void whenAdjust_thenNextSunday() { |     public void whenAdjust_thenNextSunday() { | ||||||
|         LocalDate localDate = LocalDate.now(); |         LocalDate localDate = LocalDate.of(2017, 07, 8); | ||||||
|         LocalDate nextSunday = localDate.with(TemporalAdjusters.next(DayOfWeek.SUNDAY)); |         LocalDate nextSunday = localDate.with(TemporalAdjusters.next(DayOfWeek.SUNDAY)); | ||||||
| 
 | 
 | ||||||
|         String expected = "2017-07-09"; |         String expected = "2017-07-09"; | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user