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 com.baeldung.temporaladjuster.CustomTemporalAdjuster; | ||||
| import com.baeldung.temporaladjuster.TemporalAdjusterUtil; | ||||
| 
 | ||||
| public class CustomTemporalAdjusterTest { | ||||
| 
 | ||||
|     @Test | ||||
|     public void whenAdjustAndImplementInterface_thenNextWorkingDay() { | ||||
|         LocalDate localDate = LocalDate.now(); | ||||
|         LocalDate localDate = LocalDate.of(2017, 07, 8); | ||||
|         CustomTemporalAdjuster temporalAdjuster = new CustomTemporalAdjuster(); | ||||
|         LocalDate nextWorkingDay = localDate.with(temporalAdjuster); | ||||
| 
 | ||||
|         Assert.assertEquals(TemporalAdjusterUtil.getNextWorkingDay(), nextWorkingDay.toString()); | ||||
|         Assert.assertEquals("2017-07-10", nextWorkingDay.toString()); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void whenAdjust_thenNextWorkingDay() { | ||||
|         LocalDate localDate = LocalDate.now(); | ||||
|         LocalDate localDate = LocalDate.of(2017, 07, 8); | ||||
|         TemporalAdjuster temporalAdjuster = NEXT_WORKING_DAY; | ||||
|         LocalDate date = localDate.with(temporalAdjuster); | ||||
| 
 | ||||
|         Assert.assertEquals(TemporalAdjusterUtil.getNextWorkingDay(), date.toString()); | ||||
|         Assert.assertEquals("2017-07-10", date.toString()); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void whenAdjust_thenFourteenDaysFromToday() { | ||||
|         LocalDate localDate = LocalDate.now(); | ||||
|     public void whenAdjust_thenFourteenDaysAfterDate() { | ||||
|         LocalDate localDate = LocalDate.of(2017, 07, 8); | ||||
|         TemporalAdjuster temporalAdjuster = (t) -> t.plus(Period.ofDays(14)); | ||||
|         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 -> { | ||||
|         DayOfWeek dayOfWeek = today.getDayOfWeek(); | ||||
|     static TemporalAdjuster NEXT_WORKING_DAY = TemporalAdjusters.ofDateAdjuster(date -> { | ||||
|         DayOfWeek dayOfWeek = date.getDayOfWeek(); | ||||
|         int daysToAdd; | ||||
|         if (dayOfWeek == DayOfWeek.FRIDAY) | ||||
|             daysToAdd = 3; | ||||
| @ -52,6 +51,6 @@ public class CustomTemporalAdjusterTest { | ||||
|             daysToAdd = 2; | ||||
|         else | ||||
|             daysToAdd = 1; | ||||
|         return today.plusDays(daysToAdd); | ||||
|         return date.plusDays(daysToAdd); | ||||
|     }); | ||||
| } | ||||
|  | ||||
| @ -11,7 +11,7 @@ public class TemporalAdjustersTest { | ||||
| 
 | ||||
|     @Test | ||||
|     public void whenAdjust_thenNextSunday() { | ||||
|         LocalDate localDate = LocalDate.now(); | ||||
|         LocalDate localDate = LocalDate.of(2017, 07, 8); | ||||
|         LocalDate nextSunday = localDate.with(TemporalAdjusters.next(DayOfWeek.SUNDAY)); | ||||
| 
 | ||||
|         String expected = "2017-07-09"; | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user