[JAVA-26719] Upgraded joda-time to latest version (#15189)

This commit is contained in:
panos-kakos 2023-11-13 10:00:45 +00:00 committed by GitHub
parent e82269d206
commit 21eb70547f
13 changed files with 30 additions and 45 deletions

View File

@ -55,7 +55,7 @@
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<joda-time.version>2.10</joda-time.version>
<joda-time.version>2.12.5</joda-time.version>
</properties>
</project>

View File

@ -7,7 +7,7 @@ import java.util.List;
public class SimpleParseDate {
public Date parseDate(String dateString, List<String> formatStrings) {
public static Date parseDate(String dateString, List<String> formatStrings) {
for (String formatString : formatStrings) {
try {
return new SimpleDateFormat(formatString).parse(dateString);

View File

@ -1,43 +1,41 @@
package com.baeldung.parsingDates;
import com.baeldung.parsingDates.SimpleDateTimeFormat;
import com.baeldung.parsingDates.SimpleDateTimeFormater;
import com.baeldung.parsingDates.SimpleDateUtils;
import com.baeldung.parsingDates.SimpleParseDate;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.time.format.DateTimeParseException;
import java.util.Arrays;
import org.junit.*;
import static org.junit.Assert.*;
import org.joda.time.LocalDate;
import org.junit.jupiter.api.Test;
public class SimpleParseDateUnitTest {
class SimpleParseDateUnitTest {
@Test
public void whenInvalidInput_thenGettingUnexpectedResult() {
SimpleParseDate simpleParseDate = new SimpleParseDate();
void whenInvalidInput_thenGettingUnexpectedResult() {
String date = "2022-40-40";
assertEquals("Sat May 10 00:00:00 UTC 2025", simpleParseDate.parseDate(date, Arrays.asList("MM/dd/yyyy", "dd.MM.yyyy", "yyyy-MM-dd")).toString());
assertEquals("Sat May 10 00:00:00 UTC 2025", SimpleParseDate.parseDate(date, Arrays.asList("MM/dd/yyyy", "dd.MM.yyyy", "yyyy-MM-dd"))
.toString());
}
@Test
public void whenInvalidDate_thenAssertThrows() {
SimpleDateTimeFormater simpleDateTimeFormater = new SimpleDateTimeFormater();
assertEquals(java.time.LocalDate.parse("2022-12-04"), simpleDateTimeFormater.parseDate("2022-12-04"));
assertThrows(DateTimeParseException.class, () -> simpleDateTimeFormater.parseDate("2022-13-04"));
void whenInvalidDate_thenAssertThrows() {
assertEquals(java.time.LocalDate.parse("2022-12-04"), SimpleDateTimeFormater.parseDate("2022-12-04"));
assertThrows(DateTimeParseException.class, () -> SimpleDateTimeFormater.parseDate("2022-13-04"));
}
@Test
public void whenDateIsCorrect_thenParseCorrect() {
SimpleDateUtils simpleDateUtils = new SimpleDateUtils();
assertNull(simpleDateUtils.parseDate("53/10/2014"));
assertEquals("Wed Sep 10 00:00:00 UTC 2014", simpleDateUtils.parseDate("10/09/2014").toString());
void whenDateIsCorrect_thenParseCorrect() {
assertNull(SimpleDateUtils.parseDate("53/10/2014"));
assertEquals("Wed Sep 10 00:00:00 UTC 2014", SimpleDateUtils.parseDate("10/09/2014")
.toString());
}
@Test
public void whenDateIsCorrect_thenResultCorrect() {
SimpleDateTimeFormat simpleDateTimeFormat = new SimpleDateTimeFormat();
assertNull(simpleDateTimeFormat.parseDate("53/10/2014"));
assertEquals(LocalDate.parse("2014-10-10"), simpleDateTimeFormat.parseDate("2014-10-10"));
void whenDateIsCorrect_thenResultCorrect() {
assertNull(SimpleDateTimeFormat.parseDate("53/10/2014"));
assertEquals(LocalDate.parse("2014-10-10"), SimpleDateTimeFormat.parseDate("2014-10-10"));
}
}

View File

@ -56,7 +56,7 @@
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<joda-time.version>2.10</joda-time.version>
<joda-time.version>2.12.5</joda-time.version>
</properties>
</project>

View File

@ -54,7 +54,7 @@
</build>
<properties>
<joda-time.version>2.10</joda-time.version>
<joda-time.version>2.12.5</joda-time.version>
<hirondelle-date4j.version>RELEASE</hirondelle-date4j.version>
<maven.compiler.source>1.9</maven.compiler.source>
<maven.compiler.target>1.9</maven.compiler.target>

View File

@ -47,7 +47,7 @@
</dependencies>
<properties>
<joda-time.version>2.10</joda-time.version>
<joda-time.version>2.12.5</joda-time.version>
<hirondelle-date4j.version>1.5.1</hirondelle-date4j.version>
<prettytime.version>3.2.7.Final</prettytime.version>
<time4j-base.version>5.9</time4j-base.version>

View File

@ -54,7 +54,7 @@
</build>
<properties>
<joda-time.version>2.10</joda-time.version>
<joda-time.version>2.12.5</joda-time.version>
<maven.compiler.source>1.9</maven.compiler.source>
<maven.compiler.target>1.9</maven.compiler.target>
</properties>

View File

@ -65,7 +65,7 @@
<properties>
<gson.version>2.10.1</gson.version>
<joda-time.version>2.9.6</joda-time.version>
<joda-time.version>2.12.5</joda-time.version>
</properties>
</project>

View File

@ -72,7 +72,7 @@
<spring-framework.version>6.0.6</spring-framework.version>
<spring-data-couchbase.version>5.0.3</spring-data-couchbase.version>
<hibernate-validator.version>8.0.1.Final</hibernate-validator.version>
<joda-time.version>2.12.2</joda-time.version>
<joda-time.version>2.12.5</joda-time.version>
</properties>
</project>

View File

@ -192,7 +192,7 @@
<mockito.version>2.21.0</mockito.version>
<maven-dependency-plugin.version>2.8</maven-dependency-plugin.version>
<wildfly-ejb.version>8.2.1.Final</wildfly-ejb.version>
<joda-time.version>2.10.12</joda-time.version>
<joda-time.version>2.12.5</joda-time.version>
</properties>
</project>

View File

@ -121,12 +121,6 @@
<artifactId>hibernate-validator</artifactId>
<version>${hibernate-validator.version}</version>
</dependency>
<!-- Joda Time Library -->
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>${joda-time.version}</version>
</dependency>
<!-- Handlebars.java -->
<dependency>
<groupId>com.github.jknack</groupId>
@ -196,7 +190,6 @@
<!-- various 1.3.2 -->
<hibernate-validator.version>6.0.10.Final</hibernate-validator.version>
<handlebars.version>4.1.0</handlebars.version>
<joda-time.version>2.10</joda-time.version>
<inject.version>1</inject.version>
<!-- Maven plugins -->
<yuicompressor-maven-plugin.version>1.5.1</yuicompressor-maven-plugin.version>

View File

@ -93,11 +93,6 @@
<artifactId>mail</artifactId>
<version>${javax.mail.version}</version>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>${joda-time.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
@ -184,7 +179,6 @@
<httpclient.version>4.5.2</httpclient.version>
<uri-template.version>0.9</uri-template.version>
<libphonenumber.version>8.0.0</libphonenumber.version>
<joda-time.version>2.9.6</joda-time.version>
<msg-simple.version>1.1</msg-simple.version>
<btf.version>1.2</btf.version>
<wiremock.version>2.27.2</wiremock.version>

View File

@ -114,7 +114,7 @@
<properties>
<!-- various -->
<joda-time.version>2.9.6</joda-time.version>
<joda-time.version>2.12.5</joda-time.version>
<gson.version>2.8.0</gson.version>
<!-- testing -->
<rest-assured.version>3.0.1</rest-assured.version>