From a94bf971f5ae3fcf4e4df86de4dc9a0b8fed0823 Mon Sep 17 00:00:00 2001 From: DiegoMarti2 <150871541+DiegoMarti2@users.noreply.github.com> Date: Wed, 10 Jan 2024 00:13:10 +0200 Subject: [PATCH] baeldung-articles : BAEL-7403 (#15573) * baeldung-articles : BAEL-7403 Convert Joda-Time DateTime to Date and Vice Versa * (Move) baeldung-articles : BAEL-7403 Move the code to this module. --- ...odaDateTimeToDateAndViceVersaUnitTest.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 core-java-modules/core-java-datetime-conversion/src/test/java/com/baeldung/jodadatetimetostandarddate/JodaDateTimeToDateAndViceVersaUnitTest.java diff --git a/core-java-modules/core-java-datetime-conversion/src/test/java/com/baeldung/jodadatetimetostandarddate/JodaDateTimeToDateAndViceVersaUnitTest.java b/core-java-modules/core-java-datetime-conversion/src/test/java/com/baeldung/jodadatetimetostandarddate/JodaDateTimeToDateAndViceVersaUnitTest.java new file mode 100644 index 0000000000..e84dfff3ef --- /dev/null +++ b/core-java-modules/core-java-datetime-conversion/src/test/java/com/baeldung/jodadatetimetostandarddate/JodaDateTimeToDateAndViceVersaUnitTest.java @@ -0,0 +1,22 @@ +package com.baeldung.jodadatetimetostandarddate; + +import org.joda.time.DateTime; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class JodaDateTimeToDateAndViceVersaUnitTest { + @Test + public void givenJodaDateTime_whenConvertingToJavaDate_thenConversionIsCorrect() { + DateTime jodaDateTime = new DateTime(); + java.util.Date javaDate = jodaDateTime.toDate(); + assertEquals(jodaDateTime, new DateTime(javaDate)); + } + + @Test + public void givenJavaDate_whenConvertingToJodaDateTime_thenConversionIsCorrect() { + java.util.Date javaDate = new java.util.Date(); + DateTime jodaDateTime = new DateTime(javaDate); + assertEquals(javaDate, jodaDateTime.toDate()); + } +}