diff --git a/core-java-modules/core-java-8-datetime-2/src/test/java/com/baeldung/zoneoffsetandzoneidof/ZoneOffSetAndZoneIdOfUnitTest.java b/core-java-modules/core-java-8-datetime-2/src/test/java/com/baeldung/zoneoffsetandzoneidof/ZoneOffSetAndZoneIdOfUnitTest.java new file mode 100644 index 0000000000..84f40c3cd5 --- /dev/null +++ b/core-java-modules/core-java-8-datetime-2/src/test/java/com/baeldung/zoneoffsetandzoneidof/ZoneOffSetAndZoneIdOfUnitTest.java @@ -0,0 +1,25 @@ +package com.baeldung.zoneoffsetandzoneidof; + +import org.junit.jupiter.api.Test; + +import java.time.OffsetDateTime; +import java.time.ZoneId; +import java.time.ZoneOffset; +import java.time.ZonedDateTime; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class ZoneOffSetAndZoneIdOfUnitTest { + + @Test + public void givenOffsetDateTimeWithUTCZoneOffset_thenOffsetShouldBeUTC() { + OffsetDateTime dateTimeWithOffset = OffsetDateTime.now(ZoneOffset.UTC); + assertEquals(dateTimeWithOffset.getOffset(), ZoneOffset.UTC); + } + + @Test + public void givenZonedDateTimeWithUTCZoneId_thenZoneShouldBeUTC() { + ZonedDateTime zonedDateTime = ZonedDateTime.now(ZoneId.of("UTC")); + assertEquals(zonedDateTime.getZone(), ZoneId.of("UTC")); + } +}