BAEL-7109 - added code to demostrate how to get max date in java (#14944)
* BAEL-7109 - added code to demostrate how to get max date in java * BAEL-7109 Fix test case typo * BAEL-7109 Fix test case file name * Fix the test method * Fix the test method * Fix the test method * Remove public * add new line
This commit is contained in:
		
							parent
							
								
									de50130c74
								
							
						
					
					
						commit
						5787183a36
					
				| @ -0,0 +1,18 @@ | |||||||
|  | package com.baeldung.maxdate; | ||||||
|  | 
 | ||||||
|  | import java.util.Date; | ||||||
|  | 
 | ||||||
|  | public class DateComparison { | ||||||
|  |     public int compareTodayWithMaxDate() { | ||||||
|  |         Date today = new Date(); | ||||||
|  |         Date maxDate = new Date(Long.MAX_VALUE); | ||||||
|  | 
 | ||||||
|  |         int comparisonResult = today.compareTo(maxDate); | ||||||
|  |         return comparisonResult; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public static void main(String[] args) { | ||||||
|  |         DateComparison comparator = new DateComparison(); | ||||||
|  |         System.out.println(comparator.compareTodayWithMaxDate()); | ||||||
|  |     } | ||||||
|  | } | ||||||
| @ -0,0 +1,18 @@ | |||||||
|  | package com.baeldung.maxdate; | ||||||
|  | 
 | ||||||
|  | import java.util.Date; | ||||||
|  | import java.text.SimpleDateFormat; | ||||||
|  | 
 | ||||||
|  | public class MaxDateDisplay { | ||||||
|  |     public String getMaxDateValue() { | ||||||
|  |         Date maxDate = new Date(Long.MAX_VALUE); | ||||||
|  |         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); | ||||||
|  |         return "The maximum date value in Java is: " + sdf.format(maxDate); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public static void main(String[] args) { | ||||||
|  |         MaxDateDisplay display = new MaxDateDisplay(); | ||||||
|  |         System.out.println(display.getMaxDateValue()); | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
| @ -0,0 +1,16 @@ | |||||||
|  | package com.baeldung.maxdate; | ||||||
|  | 
 | ||||||
|  | import static org.junit.jupiter.api.Assertions.assertTrue; | ||||||
|  | 
 | ||||||
|  | import org.junit.jupiter.api.Test; | ||||||
|  | 
 | ||||||
|  | class DateComparisonUnitTest { | ||||||
|  | 
 | ||||||
|  |   @Test | ||||||
|  |   void whenCompareTodayWithMaxDate_thenCorrectResult() { | ||||||
|  |     DateComparison comparator = new DateComparison(); | ||||||
|  |     int result = comparator.compareTodayWithMaxDate(); | ||||||
|  | 
 | ||||||
|  |     assertTrue(result < 0); | ||||||
|  |   } | ||||||
|  | } | ||||||
| @ -0,0 +1,18 @@ | |||||||
|  | package com.baeldung.maxdate; | ||||||
|  | 
 | ||||||
|  | import static org.junit.jupiter.api.Assertions.assertEquals; | ||||||
|  | 
 | ||||||
|  | import org.junit.jupiter.api.Test; | ||||||
|  | 
 | ||||||
|  | class MaxDateDisplayUnitTest { | ||||||
|  | 
 | ||||||
|  |   @Test | ||||||
|  |   void whenGetMaxDate_thenCorrectResult() { | ||||||
|  |     MaxDateDisplay display = new MaxDateDisplay(); | ||||||
|  |     String result = display.getMaxDateValue(); | ||||||
|  |     assertEquals( | ||||||
|  |       "The maximum date value in Java is: 292278994-08-17 07:12:55.807", | ||||||
|  |       result | ||||||
|  |     ); | ||||||
|  |   } | ||||||
|  | } | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user