[duration-improvement] isNegative, isZero Tests (#14791)
This commit is contained in:
		
							parent
							
								
									82c4b59059
								
							
						
					
					
						commit
						8ea2cc9703
					
				| @ -3,9 +3,11 @@ package com.baeldung.dateapi; | |||||||
| import static org.assertj.core.api.Assertions.assertThat; | import static org.assertj.core.api.Assertions.assertThat; | ||||||
| import static org.junit.Assert.assertEquals; | import static org.junit.Assert.assertEquals; | ||||||
| import static org.junit.Assert.assertFalse; | import static org.junit.Assert.assertFalse; | ||||||
|  | import static org.junit.jupiter.api.Assertions.assertTrue; | ||||||
| 
 | 
 | ||||||
| import java.time.Duration; | import java.time.Duration; | ||||||
| import java.time.Instant; | import java.time.Instant; | ||||||
|  | import java.time.LocalDateTime; | ||||||
| import java.time.LocalTime; | import java.time.LocalTime; | ||||||
| import java.time.temporal.ChronoUnit; | import java.time.temporal.ChronoUnit; | ||||||
| 
 | 
 | ||||||
| @ -34,6 +36,22 @@ public class JavaDurationUnitTest { | |||||||
|         assertThat(seconds).isEqualTo(30); |         assertThat(seconds).isEqualTo(30); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     @Test | ||||||
|  |     public void givenADuration_whenCallingisZeroAndisNegative_thenGetExpectedResult() { | ||||||
|  |         LocalDateTime start = LocalDateTime.parse("2020-01-01T08:00:00"); | ||||||
|  |         LocalDateTime end = LocalDateTime.parse("2020-01-01T12:00:00"); | ||||||
|  |         assertFalse(Duration.between(start, end) | ||||||
|  |           .isNegative()); | ||||||
|  |         assertTrue(Duration.between(end, start) | ||||||
|  |           .isNegative()); | ||||||
|  | 
 | ||||||
|  |         LocalDateTime theTime = LocalDateTime.parse("2023-09-09T08:00:00"); | ||||||
|  |         assertTrue(Duration.between(theTime, theTime) | ||||||
|  |           .isZero()); | ||||||
|  |         assertFalse(Duration.between(theTime, theTime) | ||||||
|  |           .isNegative()); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     @Test |     @Test | ||||||
|     public void test2() { |     public void test2() { | ||||||
|         Instant start = Instant.parse("2017-10-03T10:15:30.00Z"); |         Instant start = Instant.parse("2017-10-03T10:15:30.00Z"); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user