From b9fa2e0eb2784e8f55389048f26790634f066211 Mon Sep 17 00:00:00 2001 From: Yanyan Liu Date: Wed, 26 Oct 2022 00:08:12 +1100 Subject: [PATCH 1/3] Added date format and respective test case --- .../java/org/jabref/model/entry/Date.java | 6 ++++- .../java/org/jabref/model/entry/DateTest.java | 26 +++++++------------ 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/main/java/org/jabref/model/entry/Date.java b/src/main/java/org/jabref/model/entry/Date.java index d133a80fb85..df5c5df3b1e 100644 --- a/src/main/java/org/jabref/model/entry/Date.java +++ b/src/main/java/org/jabref/model/entry/Date.java @@ -38,7 +38,10 @@ public class Date { "d.M.uuuu", // covers 15.1.2015 "uuuu.M.d", // covers 2015.1.15 "uuuu", // covers 2015 - "MMM, uuuu"); // covers Jan, 2020 + "MMM, uuuu", // covers Jan, 2020 + "uuuu/M", // covers 2020/10 + "uuuu.MM.d" // covers 2015.10.15 + ); SIMPLE_DATE_FORMATS = formatStrings.stream() .map(DateTimeFormatter::ofPattern) @@ -59,6 +62,7 @@ public Date(int year, int month) { this(YearMonth.of(year, month)); } + public Date(int year) { this(Year.of(year)); } diff --git a/src/test/java/org/jabref/model/entry/DateTest.java b/src/test/java/org/jabref/model/entry/DateTest.java index b9ea9f77cd7..40b86d6fda9 100644 --- a/src/test/java/org/jabref/model/entry/DateTest.java +++ b/src/test/java/org/jabref/model/entry/DateTest.java @@ -1,25 +1,17 @@ package org.jabref.model.entry; -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.time.Month; -import java.time.Year; -import java.time.YearMonth; -import java.time.ZoneId; -import java.time.ZoneOffset; -import java.time.ZonedDateTime; -import java.time.temporal.Temporal; -import java.util.Optional; -import java.util.stream.Stream; - import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; +import java.time.Month; +import java.time.*; +import java.time.temporal.Temporal; +import java.util.Optional; +import java.util.stream.Stream; + +import static org.junit.jupiter.api.Assertions.*; class DateTest { private static Stream validDates() { @@ -42,7 +34,9 @@ private static Stream validDates() { Arguments.of(LocalDate.of(2015, Month.JANUARY, 15), "15.1.2015"), Arguments.of(LocalDate.of(2015, Month.JANUARY, 15), "2015.1.15"), Arguments.of(Year.of(2015), "2015"), - Arguments.of(YearMonth.of(2020, Month.JANUARY), "Jan, 2020")); + Arguments.of(YearMonth.of(2020, Month.JANUARY), "Jan, 2020"), + Arguments.of(LocalDate.of(2015, Month.OCTOBER, 15), "2015.10.15") + ); } @ParameterizedTest From 67e0f3d0a4214b7f7b8d6a18e2ccf9f28c4c19ba Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Mon, 7 Nov 2022 19:41:40 +0100 Subject: [PATCH 2/3] add test for negative values as well fix checkstyle --- .../java/org/jabref/model/entry/DateTest.java | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/test/java/org/jabref/model/entry/DateTest.java b/src/test/java/org/jabref/model/entry/DateTest.java index 40b86d6fda9..1473246c362 100644 --- a/src/test/java/org/jabref/model/entry/DateTest.java +++ b/src/test/java/org/jabref/model/entry/DateTest.java @@ -1,17 +1,25 @@ package org.jabref.model.entry; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; - +import java.time.LocalDate; +import java.time.LocalDateTime; import java.time.Month; -import java.time.*; +import java.time.Year; +import java.time.YearMonth; +import java.time.ZoneId; +import java.time.ZoneOffset; +import java.time.ZonedDateTime; import java.time.temporal.Temporal; import java.util.Optional; import java.util.stream.Stream; -import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; class DateTest { private static Stream validDates() { @@ -35,7 +43,8 @@ private static Stream validDates() { Arguments.of(LocalDate.of(2015, Month.JANUARY, 15), "2015.1.15"), Arguments.of(Year.of(2015), "2015"), Arguments.of(YearMonth.of(2020, Month.JANUARY), "Jan, 2020"), - Arguments.of(LocalDate.of(2015, Month.OCTOBER, 15), "2015.10.15") + Arguments.of(LocalDate.of(2015, Month.OCTOBER, 15), "2015.10.15"), + Arguments.of(LocalDate.of(-10000,Month.OCTOBER, 15), "-10000-10-15") ); } From 2462175645be8cd8bcd48aa3170ee02104f4dfab Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Mon, 7 Nov 2022 19:56:32 +0100 Subject: [PATCH 3/3] checkstyle --- src/main/java/org/jabref/model/entry/Date.java | 1 - src/test/java/org/jabref/model/entry/DateTest.java | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/org/jabref/model/entry/Date.java b/src/main/java/org/jabref/model/entry/Date.java index df5c5df3b1e..a079c9bf486 100644 --- a/src/main/java/org/jabref/model/entry/Date.java +++ b/src/main/java/org/jabref/model/entry/Date.java @@ -62,7 +62,6 @@ public Date(int year, int month) { this(YearMonth.of(year, month)); } - public Date(int year) { this(Year.of(year)); } diff --git a/src/test/java/org/jabref/model/entry/DateTest.java b/src/test/java/org/jabref/model/entry/DateTest.java index 1473246c362..c81cbee2700 100644 --- a/src/test/java/org/jabref/model/entry/DateTest.java +++ b/src/test/java/org/jabref/model/entry/DateTest.java @@ -44,7 +44,7 @@ private static Stream validDates() { Arguments.of(Year.of(2015), "2015"), Arguments.of(YearMonth.of(2020, Month.JANUARY), "Jan, 2020"), Arguments.of(LocalDate.of(2015, Month.OCTOBER, 15), "2015.10.15"), - Arguments.of(LocalDate.of(-10000,Month.OCTOBER, 15), "-10000-10-15") + Arguments.of(LocalDate.of(-10000, Month.OCTOBER, 15), "-10000-10-15") ); }