Split the first 2 modules: java-dates-conversion and java-dates-string.
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
package com.baeldung.zonedatetime;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class ZoneDateTimeExampleUnitTest {
|
||||
|
||||
ZoneDateTimeExample zoneDateTimeExample = new ZoneDateTimeExample();
|
||||
|
||||
@Test
|
||||
public void givenZone_whenGetCurrentTime_thenResultHasZone() {
|
||||
String zone = "Europe/Berlin";
|
||||
ZonedDateTime time = zoneDateTimeExample.getCurrentTimeByZoneId(zone);
|
||||
|
||||
assertTrue(time.getZone()
|
||||
.equals(ZoneId.of(zone)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenZones_whenConvertDateByZone_thenGetConstantDiff() {
|
||||
String sourceZone = "Europe/Berlin";
|
||||
String destZone = "Asia/Tokyo";
|
||||
ZonedDateTime sourceDate = zoneDateTimeExample.getCurrentTimeByZoneId(sourceZone);
|
||||
ZonedDateTime destDate = zoneDateTimeExample.convertZonedDateTime(sourceDate, destZone);
|
||||
|
||||
assertTrue(sourceDate.toInstant()
|
||||
.compareTo(destDate.toInstant()) == 0);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user