This is an automated email from the ASF dual-hosted git repository.
jamesbognar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/juneau.git
The following commit(s) were added to refs/heads/master by this push:
new ef19da8f46 Utility class cleanup
ef19da8f46 is described below
commit ef19da8f469f7b8a3b5e182b69bf1cee6afe6fd7
Author: James Bognar <[email protected]>
AuthorDate: Wed Oct 29 13:53:37 2025 -0400
Utility class cleanup
---
TODO.md | 12 +-
.../org/apache/juneau/bean/atom/CommonEntry.java | 4 +-
.../java/org/apache/juneau/bean/atom/Entry.java | 5 +-
.../org/apache/juneau/assertions/Assertion.java | 11 -
.../juneau/assertions/FluentObjectAssertion.java | 4 +-
.../assertions/FluentThrowableAssertion.java | 4 +-
.../org/apache/juneau/common/utils/ClassUtils.java | 4 +-
.../org/apache/juneau/common/utils/DateUtils.java | 2 +-
.../juneau/common/utils/GranularZonedDateTime.java | 7 +-
.../apache/juneau/common/utils/StringUtils.java | 6 +
.../main/java/org/apache/juneau/BeanSession.java | 5 +-
.../org/apache/juneau/encoders/GzipEncoder.java | 2 -
.../apache/juneau/encoders/IdentityEncoder.java | 2 -
.../juneau/jsonschema/BasicBeanDefMapper.java | 2 -
.../java/org/apache/juneau/svl/MultipartVar.java | 2 -
.../apache/juneau/swaps/TemporalCalendarSwap.java | 5 +-
.../org/apache/juneau/swaps/TemporalDateSwap.java | 5 +-
.../java/org/apache/juneau/swaps/TemporalSwap.java | 5 +-
.../apache/juneau/rest/mock/MockRestRequest.java | 2 -
.../juneau/rest/mock/MockServletResponse.java | 6 +-
.../apache/juneau/common/utils/DateUtils_Test.java | 99 +--
.../org/apache/juneau/internal/DateUtils_Test.java | 767 ---------------------
.../java/org/apache/juneau/oapi/OpenApi_Test.java | 4 +-
.../juneau/objecttools/ObjectSearcher_Test.java | 3 +-
24 files changed, 97 insertions(+), 871 deletions(-)
diff --git a/TODO.md b/TODO.md
index b8dfdfce5e..3037ae90ae 100644
--- a/TODO.md
+++ b/TODO.md
@@ -15,12 +15,12 @@ This file tracks pending tasks for the Apache Juneau
project. For completed item
- [ ] TODO-15 It appears StringUtils is going to become a commonly-used
external class. Let's see if we can enhance it with commonly used string
utility methods.
- [ ] TODO-27 Determine if there are any other good candidates for
Stringifiers and Listifiers.
- [ ] TODO-29 Finish setting up SonarQube analysis in git workflow.
-- [ ] TODO-39 Use static imports for all method calls to AnnotationUtils.
-- [ ] TODO-40 Use static imports for all method calls to ArrayUtils.
-- [ ] TODO-41 Use static imports for all method calls to AssertionUtils.
-- [ ] TODO-42 Use static imports for all method calls to ClassUtils.
-- [ ] TODO-43 Use static imports for all method calls to CollectionUtils.
-- [ ] TODO-44 Use static imports for all method calls to DateUtils.
+- [x] TODO-39 Use static imports for all method calls to AnnotationUtils.
+- [x] TODO-40 Use static imports for all method calls to ArrayUtils.
+- [x] TODO-41 Use static imports for all method calls to AssertionUtils.
+- [x] TODO-42 Use static imports for all method calls to ClassUtils.
+- [x] TODO-43 Use static imports for all method calls to CollectionUtils.
+- [x] TODO-44 Use static imports for all method calls to DateUtils.
- [ ] TODO-45 Use static imports for all method calls to FileUtils.
- [ ] TODO-46 Use static imports for all method calls to IOUtils.
- [ ] TODO-47 Use static imports for all method calls to PredicateUtils.
diff --git
a/juneau-bean/juneau-bean-atom/src/main/java/org/apache/juneau/bean/atom/CommonEntry.java
b/juneau-bean/juneau-bean-atom/src/main/java/org/apache/juneau/bean/atom/CommonEntry.java
index ccf56b6741..61ebe6d837 100644
---
a/juneau-bean/juneau-bean-atom/src/main/java/org/apache/juneau/bean/atom/CommonEntry.java
+++
b/juneau-bean/juneau-bean-atom/src/main/java/org/apache/juneau/bean/atom/CommonEntry.java
@@ -16,11 +16,11 @@
*/
package org.apache.juneau.bean.atom;
+import static org.apache.juneau.common.utils.DateUtils.*;
import static org.apache.juneau.xml.annotation.XmlFormat.*;
import java.util.*;
-import org.apache.juneau.common.utils.*;
import org.apache.juneau.xml.annotation.*;
/**
@@ -372,7 +372,7 @@ public class CommonEntry extends Common {
* @return This object.
*/
public CommonEntry setUpdated(String value) {
- setUpdated(DateUtils.fromIso8601Calendar(value));
+ setUpdated(fromIso8601Calendar(value));
return this;
}
}
\ No newline at end of file
diff --git
a/juneau-bean/juneau-bean-atom/src/main/java/org/apache/juneau/bean/atom/Entry.java
b/juneau-bean/juneau-bean-atom/src/main/java/org/apache/juneau/bean/atom/Entry.java
index c9b3caf214..557cb7df8c 100644
---
a/juneau-bean/juneau-bean-atom/src/main/java/org/apache/juneau/bean/atom/Entry.java
+++
b/juneau-bean/juneau-bean-atom/src/main/java/org/apache/juneau/bean/atom/Entry.java
@@ -16,10 +16,11 @@
*/
package org.apache.juneau.bean.atom;
+import static org.apache.juneau.common.utils.DateUtils.*;
+
import java.util.*;
import org.apache.juneau.annotation.*;
-import org.apache.juneau.common.utils.*;
/**
* Represents an individual entry within an Atom feed or as a standalone Atom
document.
@@ -328,7 +329,7 @@ public class Entry extends CommonEntry {
* @return This object.
*/
public Entry setPublished(String value) {
- setPublished(DateUtils.fromIso8601Calendar(value));
+ setPublished(fromIso8601Calendar(value));
return this;
}
diff --git
a/juneau-core/juneau-assertions/src/main/java/org/apache/juneau/assertions/Assertion.java
b/juneau-core/juneau-assertions/src/main/java/org/apache/juneau/assertions/Assertion.java
index 59aed25364..a88d089acb 100644
---
a/juneau-core/juneau-assertions/src/main/java/org/apache/juneau/assertions/Assertion.java
+++
b/juneau-core/juneau-assertions/src/main/java/org/apache/juneau/assertions/Assertion.java
@@ -24,7 +24,6 @@ import java.lang.reflect.*;
import org.apache.juneau.*;
import org.apache.juneau.common.reflect.*;
-import org.apache.juneau.common.utils.*;
import org.apache.juneau.cp.*;
/**
@@ -81,16 +80,6 @@ public class Assertion {
return (Class<E[]>)Array.newInstance(c, 0).getClass();
}
- /**
- * Convenience method for getting the class name for an object.
- *
- * @param o The object to get the class name for.
- * @return The class name for an object.
- */
- protected static String className(Object o) {
- return ClassUtils.className(o);
- }
-
private String msg;
private Object[] msgArgs;
diff --git
a/juneau-core/juneau-assertions/src/main/java/org/apache/juneau/assertions/FluentObjectAssertion.java
b/juneau-core/juneau-assertions/src/main/java/org/apache/juneau/assertions/FluentObjectAssertion.java
index e99462cddc..91dbbeab6c 100644
---
a/juneau-core/juneau-assertions/src/main/java/org/apache/juneau/assertions/FluentObjectAssertion.java
+++
b/juneau-core/juneau-assertions/src/main/java/org/apache/juneau/assertions/FluentObjectAssertion.java
@@ -334,7 +334,7 @@ public class FluentObjectAssertion<T,R> extends
FluentAssertion<R> {
public R isExactType(Class<?> type) throws AssertionError {
assertArgNotNull("parent", type);
if (value().getClass() != type)
- throw error(MSG_unexpectedType, className(type),
className(value));
+ throw error(MSG_unexpectedType, cn(type), cn(value));
return returns();
}
@@ -506,7 +506,7 @@ public class FluentObjectAssertion<T,R> extends
FluentAssertion<R> {
public R isType(Class<?> parent) throws AssertionError {
assertArgNotNull("parent", parent);
if (!ClassInfo.of(value()).isChildOf(parent))
- throw error(MSG_unexpectedType, className(parent),
className(value));
+ throw error(MSG_unexpectedType, cn(parent), cn(value));
return returns();
}
diff --git
a/juneau-core/juneau-assertions/src/main/java/org/apache/juneau/assertions/FluentThrowableAssertion.java
b/juneau-core/juneau-assertions/src/main/java/org/apache/juneau/assertions/FluentThrowableAssertion.java
index 451dbba974..0ea9717f20 100644
---
a/juneau-core/juneau-assertions/src/main/java/org/apache/juneau/assertions/FluentThrowableAssertion.java
+++
b/juneau-core/juneau-assertions/src/main/java/org/apache/juneau/assertions/FluentThrowableAssertion.java
@@ -358,7 +358,7 @@ public class FluentThrowableAssertion<T extends
Throwable,R> extends FluentObjec
public R isExactType(Class<?> type) {
assertArgNotNull("type", type);
if (type != value().getClass())
- throw error(MSG_exceptionWasNotExpectedType,
className(type), className(value()));
+ throw error(MSG_exceptionWasNotExpectedType, cn(type),
cn(value()));
return returns();
}
@@ -397,7 +397,7 @@ public class FluentThrowableAssertion<T extends
Throwable,R> extends FluentObjec
public R isType(Class<?> parent) {
assertArgNotNull("parent", parent);
if (!parent.isInstance(value()))
- throw error(MSG_exceptionWasNotExpectedType,
className(parent), className(value()));
+ throw error(MSG_exceptionWasNotExpectedType,
cn(parent), cn(value()));
return returns();
}
diff --git
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/utils/ClassUtils.java
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/utils/ClassUtils.java
index 7eee10157a..d308f43d82 100644
---
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/utils/ClassUtils.java
+++
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/utils/ClassUtils.java
@@ -97,7 +97,7 @@ public class ClassUtils {
} else if (t instanceof Class) {
Class<?> c = (Class<?>)t;
if (Value.class.isAssignableFrom(c)) {
- return ClassUtils.getParameterType(c, 0,
Value.class);
+ return getParameterType(c, 0, Value.class);
}
}
@@ -262,7 +262,7 @@ public class ClassUtils {
*/
@SuppressWarnings("rawtypes")
public static boolean isNotVoid(Class c) {
- return ! ClassUtils.isVoid(c);
+ return ! isVoid(c);
}
/**
diff --git
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/utils/DateUtils.java
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/utils/DateUtils.java
index 23c5a6bb31..4626752c3b 100644
---
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/utils/DateUtils.java
+++
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/utils/DateUtils.java
@@ -143,7 +143,7 @@ public class DateUtils {
* @param pattern The pattern (e.g. <js>"yyyy-MM-dd"</js>) or pattern
name (e.g. <js>"ISO_INSTANT"</js>).
* @return The formatter.
*/
- public static DateTimeFormatter getFormatter(String pattern) {
+ public static DateTimeFormatter getDateTimeFormatter(String pattern) {
if (StringUtils.isEmpty(pattern))
return DateTimeFormatter.ISO_INSTANT;
try {
diff --git
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/utils/GranularZonedDateTime.java
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/utils/GranularZonedDateTime.java
index a122c70d3d..a449e018a9 100644
---
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/utils/GranularZonedDateTime.java
+++
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/utils/GranularZonedDateTime.java
@@ -16,6 +16,7 @@
*/
package org.apache.juneau.common.utils;
+import static org.apache.juneau.common.utils.DateUtils.*;
import static org.apache.juneau.common.utils.Utils.*;
import java.time.*;
@@ -114,7 +115,7 @@ public class GranularZonedDateTime {
*/
public GranularZonedDateTime roll(ChronoField field, int amount) {
// Use DateUtils utility method to convert ChronoField to
ChronoUnit
- ChronoUnit unit = DateUtils.toChronoUnit(field);
+ ChronoUnit unit = toChronoUnit(field);
if (nn(unit)) {
ZonedDateTime newZdt = zdt.plus(amount, unit);
return new GranularZonedDateTime(newZdt, precision);
@@ -135,10 +136,10 @@ public class GranularZonedDateTime {
*/
public static GranularZonedDateTime parse(String seg) {
// Try DateUtils.fromIso8601 first for consistency
- ZonedDateTime zdt = DateUtils.fromIso8601(seg);
+ ZonedDateTime zdt = fromIso8601(seg);
if (nn(zdt)) {
// Determine precision based on the input string
- var precision = DateUtils.getPrecisionFromString(seg);
+ var precision = getPrecisionFromString(seg);
return new GranularZonedDateTime(zdt, precision);
}
diff --git
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/utils/StringUtils.java
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/utils/StringUtils.java
index 8f8631ce8d..d49d70d167 100644
---
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/utils/StringUtils.java
+++
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/utils/StringUtils.java
@@ -1945,6 +1945,12 @@ public class StringUtils {
return Integer.decode(s.substring(0, s.length() - 1).trim()) *
m; // NOSONAR - NPE not possible here.
}
+ // TODO: See if we can remove StringUtils.parseIsoCalendar.
+ // Currently used by:
+ // - OpenApiParserSession.java for DATE/DATE_TIME format parsing
+ // - StringUtils.parseIsoDate() (which wraps this method)
+ // Investigation needed: Can we replace this with java.time APIs or
other standard date parsing?
+
/**
* Parses an ISO8601 string into a calendar.
*
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanSession.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanSession.java
index 4e5e323f60..cef9bef531 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanSession.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanSession.java
@@ -18,6 +18,7 @@ package org.apache.juneau;
import static org.apache.juneau.common.utils.AssertionUtils.*;
import static org.apache.juneau.common.utils.CollectionUtils.*;
+import static org.apache.juneau.common.utils.DateUtils.*;
import static org.apache.juneau.common.utils.IOUtils.*;
import static org.apache.juneau.common.utils.StringUtils.*;
import static org.apache.juneau.common.utils.Utils.*;
@@ -1552,13 +1553,13 @@ public class BeanSession extends ContextSession {
return (T)c2;
}
}
- return
(T)GregorianCalendar.from(DateUtils.fromIso8601(value.toString()));
+ return
(T)GregorianCalendar.from(fromIso8601(value.toString()));
}
if (to.isDate() && to.getInnerClass() == Date.class) {
if (from.isCalendar())
return (T)((Calendar)value).getTime();
- return
(T)GregorianCalendar.from(DateUtils.fromIso8601(value.toString())).getTime();
+ return
(T)GregorianCalendar.from(fromIso8601(value.toString())).getTime();
}
if (to.hasMutaterFrom(from))
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/encoders/GzipEncoder.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/encoders/GzipEncoder.java
index 6d4c7cd658..d9b5e0daed 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/encoders/GzipEncoder.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/encoders/GzipEncoder.java
@@ -17,8 +17,6 @@
package org.apache.juneau.encoders;
import static org.apache.juneau.common.utils.CollectionUtils.*;
-import static org.apache.juneau.common.utils.Utils.*;
-
import java.io.*;
import java.util.zip.*;
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/encoders/IdentityEncoder.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/encoders/IdentityEncoder.java
index 4bdd9f3451..6f4f05af54 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/encoders/IdentityEncoder.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/encoders/IdentityEncoder.java
@@ -17,8 +17,6 @@
package org.apache.juneau.encoders;
import static org.apache.juneau.common.utils.CollectionUtils.*;
-import static org.apache.juneau.common.utils.Utils.*;
-
import java.io.*;
/**
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/jsonschema/BasicBeanDefMapper.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/jsonschema/BasicBeanDefMapper.java
index e76b37e7b7..4551871466 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/jsonschema/BasicBeanDefMapper.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/jsonschema/BasicBeanDefMapper.java
@@ -17,8 +17,6 @@
package org.apache.juneau.jsonschema;
import static org.apache.juneau.common.utils.CollectionUtils.*;
-import static org.apache.juneau.common.utils.Utils.*;
-
import java.net.*;
import java.text.*;
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/svl/MultipartVar.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/svl/MultipartVar.java
index e92e0ba48e..cc1ca0c415 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/svl/MultipartVar.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/svl/MultipartVar.java
@@ -17,8 +17,6 @@
package org.apache.juneau.svl;
import static org.apache.juneau.common.utils.CollectionUtils.*;
-import static org.apache.juneau.common.utils.Utils.*;
-
import org.apache.juneau.common.utils.*;
/**
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/swaps/TemporalCalendarSwap.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/swaps/TemporalCalendarSwap.java
index 5ab7e59563..11f9826b41 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/swaps/TemporalCalendarSwap.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/swaps/TemporalCalendarSwap.java
@@ -16,13 +16,14 @@
*/
package org.apache.juneau.swaps;
+import static org.apache.juneau.common.utils.DateUtils.*;
+
import java.time.*;
import java.time.format.*;
import java.time.temporal.*;
import java.util.*;
import org.apache.juneau.*;
-import org.apache.juneau.common.utils.*;
import org.apache.juneau.swap.*;
/**
@@ -286,7 +287,7 @@ public class TemporalCalendarSwap extends
StringSwap<Calendar> {
*/
public TemporalCalendarSwap(String pattern) {
super(Calendar.class);
- this.formatter = DateUtils.getFormatter(pattern);
+ this.formatter = getDateTimeFormatter(pattern);
}
@Override /* Overridden from ObjectSwap */
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/swaps/TemporalDateSwap.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/swaps/TemporalDateSwap.java
index 7283b18e19..21b2aeb602 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/swaps/TemporalDateSwap.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/swaps/TemporalDateSwap.java
@@ -16,13 +16,14 @@
*/
package org.apache.juneau.swaps;
+import static org.apache.juneau.common.utils.DateUtils.*;
+
import java.time.*;
import java.time.format.*;
import java.time.temporal.*;
import java.util.*;
import org.apache.juneau.*;
-import org.apache.juneau.common.utils.*;
import org.apache.juneau.swap.*;
/**
@@ -286,7 +287,7 @@ public class TemporalDateSwap extends StringSwap<Date> {
*/
public TemporalDateSwap(String pattern) {
super(Date.class);
- this.formatter = DateUtils.getFormatter(pattern);
+ this.formatter = getDateTimeFormatter(pattern);
}
@Override /* Overridden from ObjectSwap */
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/swaps/TemporalSwap.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/swaps/TemporalSwap.java
index d380e73a34..8f86cd3a3c 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/swaps/TemporalSwap.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/swaps/TemporalSwap.java
@@ -16,6 +16,8 @@
*/
package org.apache.juneau.swaps;
+import static org.apache.juneau.common.utils.DateUtils.*;
+
import java.lang.reflect.*;
import java.time.*;
import java.time.chrono.*;
@@ -26,7 +28,6 @@ import java.util.concurrent.*;
import org.apache.juneau.*;
import org.apache.juneau.common.reflect.*;
-import org.apache.juneau.common.utils.*;
import org.apache.juneau.reflect.*;
import org.apache.juneau.swap.*;
@@ -366,7 +367,7 @@ public class TemporalSwap extends StringSwap<Temporal> {
*/
public TemporalSwap(String pattern, boolean zoneOptional) {
super(Temporal.class);
- this.formatter = DateUtils.getFormatter(pattern);
+ this.formatter = getDateTimeFormatter(pattern);
this.zoneOptional = zoneOptional;
}
diff --git
a/juneau-rest/juneau-rest-mock/src/main/java/org/apache/juneau/rest/mock/MockRestRequest.java
b/juneau-rest/juneau-rest-mock/src/main/java/org/apache/juneau/rest/mock/MockRestRequest.java
index 457931372f..6c8fd0dace 100644
---
a/juneau-rest/juneau-rest-mock/src/main/java/org/apache/juneau/rest/mock/MockRestRequest.java
+++
b/juneau-rest/juneau-rest-mock/src/main/java/org/apache/juneau/rest/mock/MockRestRequest.java
@@ -17,8 +17,6 @@
package org.apache.juneau.rest.mock;
import static org.apache.juneau.common.utils.CollectionUtils.*;
-import static org.apache.juneau.common.utils.Utils.*;
-
import java.net.*;
import java.security.*;
import java.util.*;
diff --git
a/juneau-rest/juneau-rest-mock/src/main/java/org/apache/juneau/rest/mock/MockServletResponse.java
b/juneau-rest/juneau-rest-mock/src/main/java/org/apache/juneau/rest/mock/MockServletResponse.java
index aec250db87..fb0d313b2e 100644
---
a/juneau-rest/juneau-rest-mock/src/main/java/org/apache/juneau/rest/mock/MockServletResponse.java
+++
b/juneau-rest/juneau-rest-mock/src/main/java/org/apache/juneau/rest/mock/MockServletResponse.java
@@ -17,12 +17,12 @@
package org.apache.juneau.rest.mock;
import static org.apache.juneau.common.utils.CollectionUtils.*;
+import static org.apache.juneau.common.utils.DateUtils.*;
import static org.apache.juneau.common.utils.Utils.*;
import java.io.*;
import java.util.*;
-import org.apache.juneau.common.utils.*;
import org.apache.juneau.rest.util.*;
import jakarta.servlet.*;
@@ -60,7 +60,7 @@ public class MockServletResponse implements
HttpServletResponse {
@Override /* Overridden from HttpServletResponse */
public void addDateHeader(String name, long date) {
- headerMap.put(name, a(DateUtils.formatDate(new Date(date),
DateUtils.PATTERN_RFC1123)));
+ headerMap.put(name, a(formatDate(new Date(date),
PATTERN_RFC1123)));
}
@Override /* Overridden from HttpServletResponse */
@@ -205,7 +205,7 @@ public class MockServletResponse implements
HttpServletResponse {
@Override /* Overridden from HttpServletResponse */
public void setDateHeader(String name, long date) {
- headerMap.put(name, a(DateUtils.formatDate(new Date(date),
DateUtils.PATTERN_RFC1123)));
+ headerMap.put(name, a(formatDate(new Date(date),
PATTERN_RFC1123)));
}
@Override /* Overridden from HttpServletResponse */
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/common/utils/DateUtils_Test.java
b/juneau-utest/src/test/java/org/apache/juneau/common/utils/DateUtils_Test.java
index e3033633c0..f1a114b342 100644
---
a/juneau-utest/src/test/java/org/apache/juneau/common/utils/DateUtils_Test.java
+++
b/juneau-utest/src/test/java/org/apache/juneau/common/utils/DateUtils_Test.java
@@ -20,6 +20,7 @@ import static java.time.temporal.ChronoField.*;
import static java.time.temporal.ChronoUnit.*;
import static java.util.Calendar.*;
import static org.junit.jupiter.api.Assertions.*;
+import static org.apache.juneau.common.utils.DateUtils.*;
import java.time.*;
import java.time.temporal.*;
@@ -97,7 +98,7 @@ class DateUtils_Test extends TestBase {
@ParameterizedTest
@MethodSource("input")
void a01_basic(Input input) {
- assertEquals(input.expectedPrecision,
DateUtils.getPrecisionFromString(input.dateString));
+ assertEquals(input.expectedPrecision,
getPrecisionFromString(input.dateString));
}
}
@@ -147,7 +148,7 @@ class DateUtils_Test extends TestBase {
@ParameterizedTest
@MethodSource("input")
void d01_toChronoField(Input input) {
- ChronoField result =
DateUtils.toChronoField(input.unit);
+ ChronoField result = toChronoField(input.unit);
assertEquals(input.expectedField, result, "Test " +
input.index + ": " + input.unit);
}
}
@@ -198,7 +199,7 @@ class DateUtils_Test extends TestBase {
@ParameterizedTest
@MethodSource("input")
void e01_toChronoUnit(Input input) {
- ChronoUnit result = DateUtils.toChronoUnit(input.field);
+ ChronoUnit result = toChronoUnit(input.field);
assertEquals(input.expectedUnit, result, "Test " +
input.index + ": " + input.field);
}
}
@@ -246,7 +247,7 @@ class DateUtils_Test extends TestBase {
@ParameterizedTest
@MethodSource("input")
void f01_toCalendarField(Input input) {
- int result = DateUtils.toCalendarField(input.field);
+ int result = toCalendarField(input.field);
assertEquals(input.expectedCalendarField, result, "Test
" + input.index + ": " + input.field);
}
}
@@ -289,9 +290,9 @@ class DateUtils_Test extends TestBase {
@MethodSource("input")
void g01_chronoFieldToChronoUnitToChronoField(Input input) {
// ChronoField -> ChronoUnit -> ChronoField should be
idempotent
- ChronoUnit unit = DateUtils.toChronoUnit(input.field);
+ ChronoUnit unit = toChronoUnit(input.field);
if (unit != null) {
- ChronoField result =
DateUtils.toChronoField(unit);
+ ChronoField result = toChronoField(unit);
assertEquals(input.field, result, "Test " +
input.index + ": " + input.field + " -> " + unit + " -> " + result);
}
}
@@ -300,7 +301,7 @@ class DateUtils_Test extends TestBase {
@MethodSource("input")
void g02_chronoFieldToCalendarField(Input input) {
// ChronoField -> Calendar field should always work
- int calendarField =
DateUtils.toCalendarField(input.field);
+ int calendarField = toCalendarField(input.field);
assertTrue(calendarField >= 0, "Test " + input.index +
": Calendar field should be non-negative");
assertTrue(calendarField <= 18, "Test " + input.index +
": Calendar field should be valid Calendar constant");
}
@@ -373,7 +374,7 @@ class DateUtils_Test extends TestBase {
cal.set(Calendar.MILLISECOND, input.millisecond);
// Convert to ISO8601 string
- String result = DateUtils.toIso8601(cal);
+ String result = toIso8601(cal);
// Verify the result matches expected format
assertEquals(input.expectedIso8601, result, "Test " +
input.index + ": " + input.year + "-" + (input.month + 1) + "-" + input.day + "
" + input.timezone);
@@ -388,7 +389,7 @@ class DateUtils_Test extends TestBase {
cal.set(Calendar.MILLISECOND, input.millisecond);
// Convert to ISO8601 string
- String result = DateUtils.toIso8601(cal);
+ String result = toIso8601(cal);
// Validate format structure
assertTrue(result.matches("\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}[+-]\\d{2}:\\d{2}|\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z"),
@@ -414,7 +415,7 @@ class DateUtils_Test extends TestBase {
@Test
void i01_nullCalendar() {
assertThrows(NullPointerException.class, () -> {
- DateUtils.toIso8601(null);
+ toIso8601(null);
});
}
@@ -424,7 +425,7 @@ class DateUtils_Test extends TestBase {
cal.set(1, Calendar.JANUARY, 1, 0, 0, 0);
cal.set(Calendar.MILLISECOND, 0);
- String result = DateUtils.toIso8601(cal);
+ String result = toIso8601(cal);
assertEquals("0001-01-01T00:00:00Z", result);
}
@@ -434,7 +435,7 @@ class DateUtils_Test extends TestBase {
cal.set(9999, Calendar.DECEMBER, 31, 23, 59, 59);
cal.set(Calendar.MILLISECOND, 999);
- String result = DateUtils.toIso8601(cal);
+ String result = toIso8601(cal);
assertEquals("9999-12-31T23:59:59Z", result);
}
@@ -444,7 +445,7 @@ class DateUtils_Test extends TestBase {
cal.set(2024, Calendar.FEBRUARY, 29, 12, 0, 0);
cal.set(Calendar.MILLISECOND, 0);
- String result = DateUtils.toIso8601(cal);
+ String result = toIso8601(cal);
assertEquals("2024-02-29T12:00:00Z", result);
}
@@ -454,7 +455,7 @@ class DateUtils_Test extends TestBase {
cal.set(2023, Calendar.FEBRUARY, 28, 12, 0, 0);
cal.set(Calendar.MILLISECOND, 0);
- String result = DateUtils.toIso8601(cal);
+ String result = toIso8601(cal);
assertEquals("2023-02-28T12:00:00Z", result);
}
@@ -465,7 +466,7 @@ class DateUtils_Test extends TestBase {
cal.set(2024, Calendar.MARCH, 10, 2, 30, 0); // 2:30 AM
on DST transition day
cal.set(Calendar.MILLISECOND, 0);
- String result = DateUtils.toIso8601(cal);
+ String result = toIso8601(cal);
// The exact result depends on how Java handles the DST
transition
assertTrue(result.contains("2024-03-10T"), "Should
contain the date");
assertTrue(result.contains(":30:00"), "Should contain
the time");
@@ -532,7 +533,7 @@ class DateUtils_Test extends TestBase {
@MethodSource("input")
void j01_fromIso8601Calendar(Input input) {
// Parse the ISO8601 string
- Calendar result =
DateUtils.fromIso8601Calendar(input.iso8601String);
+ Calendar result =
fromIso8601Calendar(input.iso8601String);
// Verify the result is not null
assertNotNull(result, "Test " + input.index + ": Result
should not be null");
@@ -556,11 +557,11 @@ class DateUtils_Test extends TestBase {
@MethodSource("input")
void j02_fromIso8601Calendar_roundTrip(Input input) {
// Parse the ISO8601 string
- Calendar cal =
DateUtils.fromIso8601Calendar(input.iso8601String);
+ Calendar cal = fromIso8601Calendar(input.iso8601String);
assertNotNull(cal, "Test " + input.index + ": Calendar
should not be null");
// Convert back to ISO8601
- String result = DateUtils.toIso8601(cal);
+ String result = toIso8601(cal);
// The result should be a valid ISO8601 string
assertNotNull(result, "Test " + input.index + ": Result
should not be null");
@@ -629,7 +630,7 @@ class DateUtils_Test extends TestBase {
@MethodSource("input")
void k01_fromIso8601(Input input) {
// Parse the ISO8601 string
- ZonedDateTime result =
DateUtils.fromIso8601(input.iso8601String);
+ ZonedDateTime result = fromIso8601(input.iso8601String);
// Verify the result is not null
assertNotNull(result, "Test " + input.index + ": Result
should not be null");
@@ -653,7 +654,7 @@ class DateUtils_Test extends TestBase {
@MethodSource("input")
void k02_fromIso8601_immutability(Input input) {
// Parse the ISO8601 string
- ZonedDateTime result =
DateUtils.fromIso8601(input.iso8601String);
+ ZonedDateTime result = fromIso8601(input.iso8601String);
assertNotNull(result, "Test " + input.index + ": Result
should not be null");
// Verify immutability - operations should return new
instances
@@ -675,42 +676,42 @@ class DateUtils_Test extends TestBase {
@Test
void l01_nullInput() {
- assertNull(DateUtils.fromIso8601Calendar(null));
- assertNull(DateUtils.fromIso8601(null));
+ assertNull(fromIso8601Calendar(null));
+ assertNull(fromIso8601(null));
}
@Test
void l02_emptyInput() {
- assertNull(DateUtils.fromIso8601Calendar(""));
- assertNull(DateUtils.fromIso8601(""));
+ assertNull(fromIso8601Calendar(""));
+ assertNull(fromIso8601(""));
}
@Test
void l03_whitespaceInput() {
- assertNull(DateUtils.fromIso8601Calendar(" "));
- assertNull(DateUtils.fromIso8601(" "));
+ assertNull(fromIso8601Calendar(" "));
+ assertNull(fromIso8601(" "));
}
@Test
void l04_invalidFormat() {
// These should throw DateTimeParseException
assertThrows(Exception.class, () -> {
- DateUtils.fromIso8601Calendar("invalid-date");
+ fromIso8601Calendar("invalid-date");
});
assertThrows(Exception.class, () -> {
- DateUtils.fromIso8601("invalid-date");
+ fromIso8601("invalid-date");
});
}
@Test
void l05_minimumDate() {
- Calendar cal =
DateUtils.fromIso8601Calendar("0001-01-01T00:00:00Z");
+ Calendar cal =
fromIso8601Calendar("0001-01-01T00:00:00Z");
assertNotNull(cal);
assertEquals(1, cal.get(Calendar.YEAR));
assertEquals(Calendar.JANUARY, cal.get(Calendar.MONTH));
assertEquals(1, cal.get(Calendar.DAY_OF_MONTH));
- ZonedDateTime zdt =
DateUtils.fromIso8601("0001-01-01T00:00:00Z");
+ ZonedDateTime zdt = fromIso8601("0001-01-01T00:00:00Z");
assertNotNull(zdt);
assertEquals(1, zdt.getYear());
assertEquals(1, zdt.getMonthValue());
@@ -719,13 +720,13 @@ class DateUtils_Test extends TestBase {
@Test
void l06_maximumDate() {
- Calendar cal =
DateUtils.fromIso8601Calendar("9999-12-31T23:59:59Z");
+ Calendar cal =
fromIso8601Calendar("9999-12-31T23:59:59Z");
assertNotNull(cal);
assertEquals(9999, cal.get(Calendar.YEAR));
assertEquals(Calendar.DECEMBER,
cal.get(Calendar.MONTH));
assertEquals(31, cal.get(Calendar.DAY_OF_MONTH));
- ZonedDateTime zdt =
DateUtils.fromIso8601("9999-12-31T23:59:59Z");
+ ZonedDateTime zdt = fromIso8601("9999-12-31T23:59:59Z");
assertNotNull(zdt);
assertEquals(9999, zdt.getYear());
assertEquals(12, zdt.getMonthValue());
@@ -734,13 +735,13 @@ class DateUtils_Test extends TestBase {
@Test
void l07_leapYear() {
- Calendar cal =
DateUtils.fromIso8601Calendar("2024-02-29T12:00:00Z");
+ Calendar cal =
fromIso8601Calendar("2024-02-29T12:00:00Z");
assertNotNull(cal);
assertEquals(2024, cal.get(Calendar.YEAR));
assertEquals(Calendar.FEBRUARY,
cal.get(Calendar.MONTH));
assertEquals(29, cal.get(Calendar.DAY_OF_MONTH));
- ZonedDateTime zdt =
DateUtils.fromIso8601("2024-02-29T12:00:00Z");
+ ZonedDateTime zdt = fromIso8601("2024-02-29T12:00:00Z");
assertNotNull(zdt);
assertEquals(2024, zdt.getYear());
assertEquals(2, zdt.getMonthValue());
@@ -750,13 +751,13 @@ class DateUtils_Test extends TestBase {
@Test
void l08_dstTransition() {
// Test DST transition in America/New_York (Spring
forward)
- Calendar cal =
DateUtils.fromIso8601Calendar("2024-03-10T02:30:00-05:00");
+ Calendar cal =
fromIso8601Calendar("2024-03-10T02:30:00-05:00");
assertNotNull(cal);
assertEquals(2024, cal.get(Calendar.YEAR));
assertEquals(Calendar.MARCH, cal.get(Calendar.MONTH));
assertEquals(10, cal.get(Calendar.DAY_OF_MONTH));
- ZonedDateTime zdt =
DateUtils.fromIso8601("2024-03-10T02:30:00-05:00");
+ ZonedDateTime zdt =
fromIso8601("2024-03-10T02:30:00-05:00");
assertNotNull(zdt);
assertEquals(2024, zdt.getYear());
assertEquals(3, zdt.getMonthValue());
@@ -773,17 +774,17 @@ class DateUtils_Test extends TestBase {
cal.set(2024, Calendar.JANUARY, 15, 0, 0, 0);
cal.set(Calendar.MILLISECOND, 0);
- Calendar result = DateUtils.addSubtractDays(cal, 10);
+ Calendar result = addSubtractDays(cal, 10);
assertNotNull(result);
assertNotSame(cal, result); // Should be a clone
assertEquals(25, result.get(Calendar.DAY_OF_MONTH));
- result = DateUtils.addSubtractDays(cal, -5);
+ result = addSubtractDays(cal, -5);
assertNotNull(result);
assertEquals(10, result.get(Calendar.DAY_OF_MONTH));
// Null calendar
- assertNull(DateUtils.addSubtractDays(null, 10));
+ assertNull(addSubtractDays(null, 10));
}
@Test
@@ -793,28 +794,28 @@ class DateUtils_Test extends TestBase {
cal.set(Calendar.MILLISECOND, 0);
// Add days
- Calendar result = DateUtils.add(cal, Calendar.DAY_OF_MONTH, 5);
+ Calendar result = add(cal, Calendar.DAY_OF_MONTH, 5);
assertSame(cal, result); // Returns same instance
assertEquals(20, cal.get(Calendar.DAY_OF_MONTH));
// Add months
cal.set(2024, Calendar.JANUARY, 15, 0, 0, 0);
- DateUtils.add(cal, Calendar.MONTH, 2);
+ add(cal, Calendar.MONTH, 2);
assertEquals(Calendar.MARCH, cal.get(Calendar.MONTH));
// Add hours
cal.set(2024, Calendar.JANUARY, 15, 10, 0, 0);
- DateUtils.add(cal, Calendar.HOUR_OF_DAY, 5);
+ add(cal, Calendar.HOUR_OF_DAY, 5);
assertEquals(15, cal.get(Calendar.HOUR_OF_DAY));
}
@Test
void test_toZonedDateTime() {
Calendar cal = new GregorianCalendar(2024, Calendar.JANUARY,
15, 12, 30, 45);
-
- Optional<ZonedDateTime> result = DateUtils.toZonedDateTime(cal);
+
+ Optional<ZonedDateTime> result = toZonedDateTime(cal);
assertTrue(result.isPresent());
-
+
ZonedDateTime zdt = result.get();
assertEquals(2024, zdt.getYear());
assertEquals(1, zdt.getMonthValue());
@@ -824,7 +825,7 @@ class DateUtils_Test extends TestBase {
assertEquals(45, zdt.getSecond());
// Null calendar
- assertFalse(DateUtils.toZonedDateTime(null).isPresent());
+ assertFalse(toZonedDateTime(null).isPresent());
}
@Test
@@ -832,10 +833,10 @@ class DateUtils_Test extends TestBase {
TimeZone tz = TimeZone.getTimeZone("America/New_York");
Calendar cal = new GregorianCalendar(tz);
cal.set(2024, Calendar.JANUARY, 15, 12, 30, 45);
-
- Optional<ZonedDateTime> result = DateUtils.toZonedDateTime(cal);
+
+ Optional<ZonedDateTime> result = toZonedDateTime(cal);
assertTrue(result.isPresent());
-
+
ZonedDateTime zdt = result.get();
assertEquals(tz.toZoneId(), zdt.getZone());
}
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/internal/DateUtils_Test.java
b/juneau-utest/src/test/java/org/apache/juneau/internal/DateUtils_Test.java
deleted file mode 100644
index a994405f8b..0000000000
--- a/juneau-utest/src/test/java/org/apache/juneau/internal/DateUtils_Test.java
+++ /dev/null
@@ -1,767 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.juneau.internal;
-
-import static java.time.temporal.ChronoField.*;
-import static java.time.temporal.ChronoUnit.*;
-import static java.util.Calendar.*;
-import static org.junit.jupiter.api.Assertions.*;
-
-import java.time.*;
-import java.time.temporal.*;
-import java.util.*;
-
-import org.apache.juneau.*;
-import org.apache.juneau.common.utils.*;
-import org.junit.jupiter.api.*;
-import org.junit.jupiter.params.*;
-import org.junit.jupiter.params.provider.*;
-
-class DateUtils_Test extends TestBase {
-
-
//-----------------------------------------------------------------------------------------------------------------
- // Test getPrecisionFromString method (state machine implementation)
-
//-----------------------------------------------------------------------------------------------------------------
-
- static class A_getPrecisionFromString {
-
- private static final Input[] INPUT = {
- /* 01 */ input(1, "2011", ChronoField.YEAR),
- /* 02 */ input(2, "2024", ChronoField.YEAR),
- /* 03 */ input(3, "1999", ChronoField.YEAR),
- /* 04 */ input(4, "2011-01", MONTH_OF_YEAR),
- /* 05 */ input(5, "2024-12", MONTH_OF_YEAR),
- /* 06 */ input(6, "1999-06", MONTH_OF_YEAR),
- /* 07 */ input(7, "2011-01-01",
ChronoField.DAY_OF_MONTH),
- /* 08 */ input(8, "2024-12-31",
ChronoField.DAY_OF_MONTH),
- /* 09 */ input(9, "1999-06-15",
ChronoField.DAY_OF_MONTH),
- /* 10 */ input(10, "2011-01-01T12",
ChronoField.HOUR_OF_DAY),
- /* 11 */ input(11, "2024-12-31T23",
ChronoField.HOUR_OF_DAY),
- /* 12 */ input(12, "1999-06-15T00",
ChronoField.HOUR_OF_DAY),
- /* 13 */ input(13, "2011-01-01T12:30", MINUTE_OF_HOUR),
- /* 14 */ input(14, "2024-12-31T23:59", MINUTE_OF_HOUR),
- /* 15 */ input(15, "1999-06-15T00:00", MINUTE_OF_HOUR),
- /* 16 */ input(16, "2011-01-01T12:30:45",
SECOND_OF_MINUTE),
- /* 17 */ input(17, "2024-12-31T23:59:59",
SECOND_OF_MINUTE),
- /* 18 */ input(18, "1999-06-15T00:00:00",
SECOND_OF_MINUTE),
- /* 19 */ input(19, "2011-01-01T12:30:45.123",
MILLI_OF_SECOND),
- /* 20 */ input(20, "2024-12-31T23:59:59.999",
MILLI_OF_SECOND),
- /* 21 */ input(21, "1999-06-15T00:00:00.000",
MILLI_OF_SECOND),
- /* 22 */ input(22, "0000", ChronoField.YEAR),
- /* 23 */ input(23, "9999", ChronoField.YEAR),
- /* 24 */ input(24, "0000-01", MONTH_OF_YEAR),
- /* 25 */ input(25, "9999-12", MONTH_OF_YEAR),
- /* 26 */ input(26, "0000-01-01",
ChronoField.DAY_OF_MONTH),
- /* 27 */ input(27, "9999-12-31",
ChronoField.DAY_OF_MONTH),
- /* 28 */ input(28, "", MILLI_OF_SECOND),
- /* 35 */ input(35, "2011Z", ChronoField.YEAR),
- /* 36 */ input(36, "2011-01Z", MONTH_OF_YEAR),
- /* 37 */ input(37, "2011-01-01Z",
ChronoField.DAY_OF_MONTH),
- /* 38 */ input(38, "2011-01-01T12Z",
ChronoField.HOUR_OF_DAY),
- /* 39 */ input(39, "2011-01-01T12:30Z", MINUTE_OF_HOUR),
- /* 40 */ input(40, "2011-01-01T12:30:45Z",
SECOND_OF_MINUTE),
- /* 41 */ input(41, "2011-01-01T12:30:45.123Z",
MILLI_OF_SECOND)
- };
-
- private static Input input(int index, String dateString,
ChronoField expectedPrecision) {
- return new Input(index, dateString, expectedPrecision);
- }
-
- private static class Input {
- final String dateString;
- final ChronoField expectedPrecision;
-
- public Input(int index, String dateString, ChronoField
expectedPrecision) {
- this.dateString = dateString;
- this.expectedPrecision = expectedPrecision;
- }
- }
-
- static Input[] input() {
- return INPUT;
- }
-
- @ParameterizedTest
- @MethodSource("input")
- void a01_basic(Input input) {
- assertEquals(input.expectedPrecision,
DateUtils.getPrecisionFromString(input.dateString));
- }
- }
-
-
//-----------------------------------------------------------------------------------------------------------------
- // toChronoField(ChronoUnit) tests
-
//-----------------------------------------------------------------------------------------------------------------
-
- static class D_toChronoField {
-
- private static final Input[] INPUT = {
- /* 01 */ input(1, YEARS, ChronoField.YEAR),
- /* 02 */ input(2, MONTHS, MONTH_OF_YEAR),
- /* 03 */ input(3, DAYS, ChronoField.DAY_OF_MONTH),
- /* 04 */ input(4, HOURS, ChronoField.HOUR_OF_DAY),
- /* 05 */ input(5, MINUTES, MINUTE_OF_HOUR),
- /* 06 */ input(6, SECONDS, SECOND_OF_MINUTE),
- /* 07 */ input(7, MILLIS, MILLI_OF_SECOND),
- /* 08 */ input(8, NANOS, null),
- /* 09 */ input(9, MICROS, null),
- /* 10 */ input(10, WEEKS, null),
- /* 11 */ input(11, DECADES, null),
- /* 12 */ input(12, CENTURIES, null),
- /* 13 */ input(13, MILLENNIA, null),
- /* 14 */ input(14, ERAS, null)
- };
-
- private static Input input(int index, ChronoUnit unit,
ChronoField expectedField) {
- return new Input(index, unit, expectedField);
- }
-
- private static class Input {
- final int index;
- final ChronoUnit unit;
- final ChronoField expectedField;
-
- public Input(int index, ChronoUnit unit, ChronoField
expectedField) {
- this.index = index;
- this.unit = unit;
- this.expectedField = expectedField;
- }
- }
-
- static Input[] input() {
- return INPUT;
- }
-
- @ParameterizedTest
- @MethodSource("input")
- void d01_toChronoField(Input input) {
- ChronoField result =
DateUtils.toChronoField(input.unit);
- assertEquals(input.expectedField, result, "Test " +
input.index + ": " + input.unit);
- }
- }
-
-
//-----------------------------------------------------------------------------------------------------------------
- // toChronoUnit(ChronoField) tests
-
//-----------------------------------------------------------------------------------------------------------------
-
- static class E_toChronoUnit {
-
- private static final Input[] INPUT = {
- /* 01 */ input(1, ChronoField.YEAR, YEARS),
- /* 02 */ input(2, MONTH_OF_YEAR, MONTHS),
- /* 03 */ input(3, ChronoField.DAY_OF_MONTH, DAYS),
- /* 04 */ input(4, ChronoField.HOUR_OF_DAY, HOURS),
- /* 05 */ input(5, MINUTE_OF_HOUR, MINUTES),
- /* 06 */ input(6, SECOND_OF_MINUTE, SECONDS),
- /* 07 */ input(7, MILLI_OF_SECOND, MILLIS),
- /* 08 */ input(8, ChronoField.DAY_OF_WEEK, null),
- /* 09 */ input(9, ChronoField.DAY_OF_YEAR, null),
- /* 11 */ input(11, ALIGNED_DAY_OF_WEEK_IN_MONTH, null),
- /* 12 */ input(12, ALIGNED_WEEK_OF_MONTH, null),
- /* 13 */ input(13, ALIGNED_WEEK_OF_YEAR, null),
- /* 14 */ input(14, NANO_OF_SECOND, null),
- /* 15 */ input(15, MICRO_OF_SECOND, null)
- };
-
- private static Input input(int index, ChronoField field,
ChronoUnit expectedUnit) {
- return new Input(index, field, expectedUnit);
- }
-
- private static class Input {
- final int index;
- final ChronoField field;
- final ChronoUnit expectedUnit;
-
- public Input(int index, ChronoField field, ChronoUnit
expectedUnit) {
- this.index = index;
- this.field = field;
- this.expectedUnit = expectedUnit;
- }
- }
-
- static Input[] input() {
- return INPUT;
- }
-
- @ParameterizedTest
- @MethodSource("input")
- void e01_toChronoUnit(Input input) {
- ChronoUnit result = DateUtils.toChronoUnit(input.field);
- assertEquals(input.expectedUnit, result, "Test " +
input.index + ": " + input.field);
- }
- }
-
-
//-----------------------------------------------------------------------------------------------------------------
- // toCalendarField(ChronoField) tests
-
//-----------------------------------------------------------------------------------------------------------------
-
- static class F_toCalendarField {
-
- private static final Input[] INPUT = {
- /* 01 */ input(1, ChronoField.YEAR, Calendar.YEAR),
- /* 02 */ input(2, MONTH_OF_YEAR, MONTH),
- /* 03 */ input(3, ChronoField.DAY_OF_MONTH,
Calendar.DAY_OF_MONTH),
- /* 04 */ input(4, ChronoField.HOUR_OF_DAY,
Calendar.HOUR_OF_DAY),
- /* 05 */ input(5, MINUTE_OF_HOUR, MINUTE),
- /* 06 */ input(6, SECOND_OF_MINUTE, SECOND),
- /* 07 */ input(7, MILLI_OF_SECOND, MILLISECOND),
- /* 08 */ input(8, ChronoField.DAY_OF_WEEK,
MILLISECOND), // Should default to MILLISECOND
- /* 09 */ input(9, ChronoField.DAY_OF_YEAR,
MILLISECOND), // Should default to MILLISECOND
- /* 11 */ input(11, NANO_OF_SECOND, MILLISECOND), //
Should default to MILLISECOND
- /* 12 */ input(12, MICRO_OF_SECOND, MILLISECOND) //
Should default to MILLISECOND
- };
-
- private static Input input(int index, ChronoField field, int
expectedCalendarField) {
- return new Input(index, field, expectedCalendarField);
- }
-
- private static class Input {
- final int index;
- final ChronoField field;
- final int expectedCalendarField;
-
- public Input(int index, ChronoField field, int
expectedCalendarField) {
- this.index = index;
- this.field = field;
- this.expectedCalendarField =
expectedCalendarField;
- }
- }
-
- static Input[] input() {
- return INPUT;
- }
-
- @ParameterizedTest
- @MethodSource("input")
- void f01_toCalendarField(Input input) {
- int result = DateUtils.toCalendarField(input.field);
- assertEquals(input.expectedCalendarField, result, "Test
" + input.index + ": " + input.field);
- }
- }
-
-
//-----------------------------------------------------------------------------------------------------------------
- // Round-trip conversion tests
-
//-----------------------------------------------------------------------------------------------------------------
-
- static class G_roundTripConversions {
-
- private static final Input[] INPUT = {
- /* 01 */ input(1, ChronoField.YEAR),
- /* 02 */ input(2, MONTH_OF_YEAR),
- /* 03 */ input(3, ChronoField.DAY_OF_MONTH),
- /* 04 */ input(4, ChronoField.HOUR_OF_DAY),
- /* 05 */ input(5, MINUTE_OF_HOUR),
- /* 06 */ input(6, SECOND_OF_MINUTE),
- /* 07 */ input(7, MILLI_OF_SECOND)
- };
-
- private static Input input(int index, ChronoField field) {
- return new Input(index, field);
- }
-
- private static class Input {
- final int index;
- final ChronoField field;
-
- public Input(int index, ChronoField field) {
- this.index = index;
- this.field = field;
- }
- }
-
- static Input[] input() {
- return INPUT;
- }
-
- @ParameterizedTest
- @MethodSource("input")
- void g01_chronoFieldToChronoUnitToChronoField(Input input) {
- // ChronoField -> ChronoUnit -> ChronoField should be
idempotent
- ChronoUnit unit = DateUtils.toChronoUnit(input.field);
- if (unit != null) {
- ChronoField result =
DateUtils.toChronoField(unit);
- assertEquals(input.field, result, "Test " +
input.index + ": " + input.field + " -> " + unit + " -> " + result);
- }
- }
-
- @ParameterizedTest
- @MethodSource("input")
- void g02_chronoFieldToCalendarField(Input input) {
- // ChronoField -> Calendar field should always work
- int calendarField =
DateUtils.toCalendarField(input.field);
- assertTrue(calendarField >= 0, "Test " + input.index +
": Calendar field should be non-negative");
- assertTrue(calendarField <= 18, "Test " + input.index +
": Calendar field should be valid Calendar constant");
- }
- }
-
-
//-----------------------------------------------------------------------------------------------------------------
- // toIso8601(Calendar) tests
-
//-----------------------------------------------------------------------------------------------------------------
-
- static class H_toIso8601 {
-
- private static final Input[] INPUT = {
- /* 01 */ input(1, 2024, JANUARY, 15, 14, 30, 45, 123,
"UTC", "2024-01-15T14:30:45Z"),
- /* 02 */ input(2, 2024, JANUARY, 15, 14, 30, 45, 123,
"America/New_York", "2024-01-15T14:30:45-05:00"),
- /* 03 */ input(3, 2024, JANUARY, 15, 14, 30, 45, 123,
"America/Los_Angeles", "2024-01-15T14:30:45-08:00"),
- /* 04 */ input(4, 2024, JANUARY, 15, 14, 30, 45, 123,
"Europe/London", "2024-01-15T14:30:45Z"),
- /* 05 */ input(5, 2024, JANUARY, 15, 14, 30, 45, 123,
"Asia/Tokyo", "2024-01-15T14:30:45+09:00"),
- /* 06 */ input(6, 2024, JULY, 15, 14, 30, 45, 123,
"America/New_York", "2024-07-15T14:30:45-04:00"), // DST
- /* 07 */ input(7, 2024, JULY, 15, 14, 30, 45, 123,
"America/Los_Angeles", "2024-07-15T14:30:45-07:00"), // DST
- /* 08 */ input(8, 2024, JULY, 15, 14, 30, 45, 123,
"Europe/London", "2024-07-15T14:30:45+01:00"), // DST
- /* 09 */ input(9, 2000, FEBRUARY, 29, 12, 0, 0, 0,
"UTC", "2000-02-29T12:00:00Z"), // Leap year
- /* 10 */ input(10, 2024, DECEMBER, 31, 23, 59, 59, 999,
"UTC", "2024-12-31T23:59:59Z"), // End of year
- /* 11 */ input(11, 2024, JANUARY, 1, 0, 0, 0, 0, "UTC",
"2024-01-01T00:00:00Z"), // Start of year
- /* 12 */ input(12, 2024, JANUARY, 15, 0, 0, 0, 0,
"UTC", "2024-01-15T00:00:00Z"), // Midnight
- /* 13 */ input(13, 2024, JANUARY, 15, 23, 59, 59, 999,
"UTC", "2024-01-15T23:59:59Z"), // End of day
- /* 14 */ input(14, 2024, JANUARY, 15, 12, 0, 0, 0,
"GMT+05:30", "2024-01-15T12:00:00+05:30"), // Custom offset
- /* 15 */ input(15, 2024, JANUARY, 15, 12, 0, 0, 0,
"GMT-05:30", "2024-01-15T12:00:00-05:30") // Custom offset
- };
-
- private static Input input(int index, int year, int month, int
day, int hour, int minute, int second, int millisecond, String timezone, String
expectedIso8601) {
- return new Input(index, year, month, day, hour, minute,
second, millisecond, timezone, expectedIso8601);
- }
-
- private static class Input {
- final int index;
- final int year;
- final int month;
- final int day;
- final int hour;
- final int minute;
- final int second;
- final int millisecond;
- final String timezone;
- final String expectedIso8601;
-
- public Input(int index, int year, int month, int day,
int hour, int minute, int second, int millisecond, String timezone, String
expectedIso8601) {
- this.index = index;
- this.year = year;
- this.month = month;
- this.day = day;
- this.hour = hour;
- this.minute = minute;
- this.second = second;
- this.millisecond = millisecond;
- this.timezone = timezone;
- this.expectedIso8601 = expectedIso8601;
- }
- }
-
- static Input[] input() {
- return INPUT;
- }
-
- @ParameterizedTest
- @MethodSource("input")
- void h01_toIso8601(Input input) {
- // Create Calendar with specified timezone and date/time
- Calendar cal =
Calendar.getInstance(TimeZone.getTimeZone(input.timezone));
- cal.set(input.year, input.month, input.day, input.hour,
input.minute, input.second);
- cal.set(Calendar.MILLISECOND, input.millisecond);
-
- // Convert to ISO8601 string
- String result = DateUtils.toIso8601(cal);
-
- // Verify the result matches expected format
- assertEquals(input.expectedIso8601, result, "Test " +
input.index + ": " + input.year + "-" + (input.month + 1) + "-" + input.day + "
" + input.timezone);
- }
-
- @ParameterizedTest
- @MethodSource("input")
- void h02_toIso8601_formatValidation(Input input) {
- // Create Calendar with specified timezone and date/time
- Calendar cal =
Calendar.getInstance(TimeZone.getTimeZone(input.timezone));
- cal.set(input.year, input.month, input.day, input.hour,
input.minute, input.second);
- cal.set(Calendar.MILLISECOND, input.millisecond);
-
- // Convert to ISO8601 string
- String result = DateUtils.toIso8601(cal);
-
- // Validate format structure
-
assertTrue(result.matches("\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}[+-]\\d{2}:\\d{2}|\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z"),
- "Test " + input.index + ": Result should match
ISO8601 format: " + result);
-
- // Validate timezone format
- if (result.endsWith("Z")) {
- // UTC timezone
- assertTrue(result.endsWith("Z"), "Test " +
input.index + ": UTC timezone should end with 'Z'");
- } else {
- // Offset timezone
-
assertTrue(result.matches(".*[+-]\\d{2}:\\d{2}$"), "Test " + input.index + ":
Offset timezone should end with +/-HH:MM");
- }
- }
- }
-
-
//-----------------------------------------------------------------------------------------------------------------
- // toIso8601(Calendar) edge cases and error handling
-
//-----------------------------------------------------------------------------------------------------------------
-
- static class I_toIso8601_edgeCases {
-
- @Test
- void i01_nullCalendar() {
- assertThrows(NullPointerException.class, () -> {
- DateUtils.toIso8601(null);
- });
- }
-
- @Test
- void i02_minimumDate() {
- Calendar cal =
Calendar.getInstance(TimeZone.getTimeZone("UTC"));
- cal.set(1, Calendar.JANUARY, 1, 0, 0, 0);
- cal.set(Calendar.MILLISECOND, 0);
-
- String result = DateUtils.toIso8601(cal);
- assertEquals("0001-01-01T00:00:00Z", result);
- }
-
- @Test
- void i03_maximumDate() {
- Calendar cal =
Calendar.getInstance(TimeZone.getTimeZone("UTC"));
- cal.set(9999, Calendar.DECEMBER, 31, 23, 59, 59);
- cal.set(Calendar.MILLISECOND, 999);
-
- String result = DateUtils.toIso8601(cal);
- assertEquals("9999-12-31T23:59:59Z", result);
- }
-
- @Test
- void i04_leapYear() {
- Calendar cal =
Calendar.getInstance(TimeZone.getTimeZone("UTC"));
- cal.set(2024, Calendar.FEBRUARY, 29, 12, 0, 0);
- cal.set(Calendar.MILLISECOND, 0);
-
- String result = DateUtils.toIso8601(cal);
- assertEquals("2024-02-29T12:00:00Z", result);
- }
-
- @Test
- void i05_nonLeapYear() {
- Calendar cal =
Calendar.getInstance(TimeZone.getTimeZone("UTC"));
- cal.set(2023, Calendar.FEBRUARY, 28, 12, 0, 0);
- cal.set(Calendar.MILLISECOND, 0);
-
- String result = DateUtils.toIso8601(cal);
- assertEquals("2023-02-28T12:00:00Z", result);
- }
-
- @Test
- void i06_dstTransition() {
- // Test DST transition in America/New_York (Spring
forward)
- Calendar cal =
Calendar.getInstance(TimeZone.getTimeZone("America/New_York"));
- cal.set(2024, Calendar.MARCH, 10, 2, 30, 0); // 2:30 AM
on DST transition day
- cal.set(Calendar.MILLISECOND, 0);
-
- String result = DateUtils.toIso8601(cal);
- // The exact result depends on how Java handles the DST
transition
- assertTrue(result.contains("2024-03-10T"), "Should
contain the date");
- assertTrue(result.contains(":30:00"), "Should contain
the time");
- }
- }
-
-
//-----------------------------------------------------------------------------------------------------------------
- // fromIso8601Calendar(String) tests
-
//-----------------------------------------------------------------------------------------------------------------
-
- static class J_fromIso8601Calendar {
-
- private static final Input[] INPUT = {
- /* 01 */ input(1, "2024-01-15T14:30:45Z", "UTC", 2024,
JANUARY, 15, 14, 30, 45),
- /* 02 */ input(2, "2024-01-15T14:30:45-05:00",
"GMT-05:00", 2024, JANUARY, 15, 14, 30, 45),
- /* 03 */ input(3, "2024-01-15T14:30:45+09:00",
"GMT+09:00", 2024, JANUARY, 15, 14, 30, 45),
- /* 04 */ input(4, "2024-01-15", "System", 2024,
JANUARY, 15, 0, 0, 0),
- /* 05 */ input(5, "2024-01-15T14:30", "System", 2024,
JANUARY, 15, 14, 30, 0),
- /* 06 */ input(6, "2024-01-15T14:30:45.123Z", "UTC",
2024, JANUARY, 15, 14, 30, 45),
- /* 07 */ input(7, "2024-07-15T14:30:45-04:00",
"GMT-04:00", 2024, JULY, 15, 14, 30, 45), // DST
- /* 08 */ input(8, "2024-07-15T14:30:45-07:00",
"GMT-07:00", 2024, JULY, 15, 14, 30, 45), // DST
- /* 09 */ input(9, "2024-02-29T12:00:00Z", "UTC", 2024,
FEBRUARY, 29, 12, 0, 0), // Leap year
- /* 10 */ input(10, "2024-12-31T23:59:59Z", "UTC", 2024,
DECEMBER, 31, 23, 59, 59), // End of year
- /* 11 */ input(11, "2024-01-01T00:00:00Z", "UTC", 2024,
JANUARY, 1, 0, 0, 0), // Start of year
- /* 12 */ input(12, "2024-01-15T00:00:00Z", "UTC", 2024,
JANUARY, 15, 0, 0, 0), // Midnight
- /* 13 */ input(13, "2024-01-15T23:59:59Z", "UTC", 2024,
JANUARY, 15, 23, 59, 59), // End of day
- /* 14 */ input(14, "2024-01-15T12:00:00+05:30",
"GMT+05:30", 2024, JANUARY, 15, 12, 0, 0), // Custom offset
- /* 15 */ input(15, "2024-01-15T12:00:00-05:30",
"GMT-05:30", 2024, JANUARY, 15, 12, 0, 0) // Custom offset
- };
-
- private static Input input(int index, String iso8601String,
String expectedTimezone, int year, int month, int day, int hour, int minute,
int second) {
- return new Input(index, iso8601String,
expectedTimezone, year, month, day, hour, minute, second);
- }
-
- private static class Input {
- final int index;
- final String iso8601String;
- final String expectedTimezone;
- final int year;
- final int month;
- final int day;
- final int hour;
- final int minute;
- final int second;
-
- public Input(int index, String iso8601String, String
expectedTimezone, int year, int month, int day, int hour, int minute, int
second) {
- this.index = index;
- this.iso8601String = iso8601String;
- this.expectedTimezone = expectedTimezone;
- this.year = year;
- this.month = month;
- this.day = day;
- this.hour = hour;
- this.minute = minute;
- this.second = second;
- }
- }
-
- static Input[] input() {
- return INPUT;
- }
-
- @ParameterizedTest
- @MethodSource("input")
- void j01_fromIso8601Calendar(Input input) {
- // Parse the ISO8601 string
- Calendar result =
DateUtils.fromIso8601Calendar(input.iso8601String);
-
- // Verify the result is not null
- assertNotNull(result, "Test " + input.index + ": Result
should not be null");
-
- // Verify date components
- assertEquals(input.year, result.get(Calendar.YEAR),
"Test " + input.index + ": Year should match");
- assertEquals(input.month, result.get(Calendar.MONTH),
"Test " + input.index + ": Month should match");
- assertEquals(input.day,
result.get(Calendar.DAY_OF_MONTH), "Test " + input.index + ": Day should
match");
- assertEquals(input.hour,
result.get(Calendar.HOUR_OF_DAY), "Test " + input.index + ": Hour should
match");
- assertEquals(input.minute, result.get(Calendar.MINUTE),
"Test " + input.index + ": Minute should match");
- assertEquals(input.second, result.get(Calendar.SECOND),
"Test " + input.index + ": Second should match");
-
- // Verify timezone (for non-system timezones)
- if (!"System".equals(input.expectedTimezone)) {
- TimeZone expectedTz =
TimeZone.getTimeZone(input.expectedTimezone);
- assertEquals(expectedTz.getID(),
result.getTimeZone().getID(), "Test " + input.index + ": Timezone should
match");
- }
- }
-
- @ParameterizedTest
- @MethodSource("input")
- void j02_fromIso8601Calendar_roundTrip(Input input) {
- // Parse the ISO8601 string
- Calendar cal =
DateUtils.fromIso8601Calendar(input.iso8601String);
- assertNotNull(cal, "Test " + input.index + ": Calendar
should not be null");
-
- // Convert back to ISO8601
- String result = DateUtils.toIso8601(cal);
-
- // The result should be a valid ISO8601 string
- assertNotNull(result, "Test " + input.index + ": Result
should not be null");
-
assertTrue(result.matches("\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}[+-]\\d{2}:\\d{2}|\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z"),
- "Test " + input.index + ": Result should be
valid ISO8601 format: " + result);
- }
- }
-
-
//-----------------------------------------------------------------------------------------------------------------
- // fromIso8601(String) tests
-
//-----------------------------------------------------------------------------------------------------------------
-
- static class K_fromIso8601 {
-
- private static final Input[] INPUT = {
- /* 01 */ input(1, "2024-01-15T14:30:45Z", "Z", 2024, 1,
15, 14, 30, 45),
- /* 02 */ input(2, "2024-01-15T14:30:45-05:00",
"-05:00", 2024, 1, 15, 14, 30, 45),
- /* 03 */ input(3, "2024-01-15T14:30:45+09:00",
"+09:00", 2024, 1, 15, 14, 30, 45),
- /* 04 */ input(4, "2024-01-15", "System", 2024, 1, 15,
0, 0, 0),
- /* 05 */ input(5, "2024-01-15T14:30", "System", 2024,
1, 15, 14, 30, 0),
- /* 06 */ input(6, "2024-01-15T14:30:45.123Z", "Z",
2024, 1, 15, 14, 30, 45),
- /* 07 */ input(7, "2024-07-15T14:30:45-04:00",
"-04:00", 2024, 7, 15, 14, 30, 45), // DST
- /* 08 */ input(8, "2024-07-15T14:30:45-07:00",
"-07:00", 2024, 7, 15, 14, 30, 45), // DST
- /* 09 */ input(9, "2024-02-29T12:00:00Z", "Z", 2024, 2,
29, 12, 0, 0), // Leap year
- /* 10 */ input(10, "2024-12-31T23:59:59Z", "Z", 2024,
12, 31, 23, 59, 59), // End of year
- /* 11 */ input(11, "2024-01-01T00:00:00Z", "Z", 2024,
1, 1, 0, 0, 0), // Start of year
- /* 12 */ input(12, "2024-01-15T00:00:00Z", "Z", 2024,
1, 15, 0, 0, 0), // Midnight
- /* 13 */ input(13, "2024-01-15T23:59:59Z", "Z", 2024,
1, 15, 23, 59, 59), // End of day
- /* 14 */ input(14, "2024-01-15T12:00:00+05:30",
"+05:30", 2024, 1, 15, 12, 0, 0), // Custom offset
- /* 15 */ input(15, "2024-01-15T12:00:00-05:30",
"-05:30", 2024, 1, 15, 12, 0, 0) // Custom offset
- };
-
- private static Input input(int index, String iso8601String,
String expectedTimezone, int year, int month, int day, int hour, int minute,
int second) {
- return new Input(index, iso8601String,
expectedTimezone, year, month, day, hour, minute, second);
- }
-
- private static class Input {
- final int index;
- final String iso8601String;
- final String expectedTimezone;
- final int year;
- final int month;
- final int day;
- final int hour;
- final int minute;
- final int second;
-
- public Input(int index, String iso8601String, String
expectedTimezone, int year, int month, int day, int hour, int minute, int
second) {
- this.index = index;
- this.iso8601String = iso8601String;
- this.expectedTimezone = expectedTimezone;
- this.year = year;
- this.month = month;
- this.day = day;
- this.hour = hour;
- this.minute = minute;
- this.second = second;
- }
- }
-
- static Input[] input() {
- return INPUT;
- }
-
- @ParameterizedTest
- @MethodSource("input")
- void k01_fromIso8601(Input input) {
- // Parse the ISO8601 string
- ZonedDateTime result =
DateUtils.fromIso8601(input.iso8601String);
-
- // Verify the result is not null
- assertNotNull(result, "Test " + input.index + ": Result
should not be null");
-
- // Verify date components
- assertEquals(input.year, result.getYear(), "Test " +
input.index + ": Year should match");
- assertEquals(input.month, result.getMonthValue(), "Test
" + input.index + ": Month should match");
- assertEquals(input.day, result.getDayOfMonth(), "Test "
+ input.index + ": Day should match");
- assertEquals(input.hour, result.getHour(), "Test " +
input.index + ": Hour should match");
- assertEquals(input.minute, result.getMinute(), "Test "
+ input.index + ": Minute should match");
- assertEquals(input.second, result.getSecond(), "Test "
+ input.index + ": Second should match");
-
- // Verify timezone (for non-system timezones)
- if (!"System".equals(input.expectedTimezone)) {
- ZoneId expectedZone =
ZoneId.of(input.expectedTimezone);
- assertEquals(expectedZone, result.getZone(),
"Test " + input.index + ": Timezone should match");
- }
- }
-
- @ParameterizedTest
- @MethodSource("input")
- void k02_fromIso8601_immutability(Input input) {
- // Parse the ISO8601 string
- ZonedDateTime result =
DateUtils.fromIso8601(input.iso8601String);
- assertNotNull(result, "Test " + input.index + ": Result
should not be null");
-
- // Verify immutability - operations should return new
instances
- ZonedDateTime plusOneDay = result.plusDays(1);
- assertNotSame(result, plusOneDay, "Test " + input.index
+ ": Plus operation should return new instance");
- assertNotEquals(result, plusOneDay, "Test " +
input.index + ": Plus operation should change the value");
-
- ZonedDateTime minusOneDay = result.minusDays(1);
- assertNotSame(result, minusOneDay, "Test " +
input.index + ": Minus operation should return new instance");
- assertNotEquals(result, minusOneDay, "Test " +
input.index + ": Minus operation should change the value");
- }
- }
-
-
//-----------------------------------------------------------------------------------------------------------------
- // fromIso8601Calendar and fromIso8601 edge cases and error handling
-
//-----------------------------------------------------------------------------------------------------------------
-
- static class L_fromIso8601_edgeCases {
-
- @Test
- void l01_nullInput() {
- assertNull(DateUtils.fromIso8601Calendar(null));
- assertNull(DateUtils.fromIso8601(null));
- }
-
- @Test
- void l02_emptyInput() {
- assertNull(DateUtils.fromIso8601Calendar(""));
- assertNull(DateUtils.fromIso8601(""));
- }
-
- @Test
- void l03_whitespaceInput() {
- assertNull(DateUtils.fromIso8601Calendar(" "));
- assertNull(DateUtils.fromIso8601(" "));
- }
-
- @Test
- void l04_invalidFormat() {
- // These should throw DateTimeParseException
- assertThrows(Exception.class, () -> {
- DateUtils.fromIso8601Calendar("invalid-date");
- });
- assertThrows(Exception.class, () -> {
- DateUtils.fromIso8601("invalid-date");
- });
- }
-
- @Test
- void l05_minimumDate() {
- Calendar cal =
DateUtils.fromIso8601Calendar("0001-01-01T00:00:00Z");
- assertNotNull(cal);
- assertEquals(1, cal.get(Calendar.YEAR));
- assertEquals(Calendar.JANUARY, cal.get(Calendar.MONTH));
- assertEquals(1, cal.get(Calendar.DAY_OF_MONTH));
-
- ZonedDateTime zdt =
DateUtils.fromIso8601("0001-01-01T00:00:00Z");
- assertNotNull(zdt);
- assertEquals(1, zdt.getYear());
- assertEquals(1, zdt.getMonthValue());
- assertEquals(1, zdt.getDayOfMonth());
- }
-
- @Test
- void l06_maximumDate() {
- Calendar cal =
DateUtils.fromIso8601Calendar("9999-12-31T23:59:59Z");
- assertNotNull(cal);
- assertEquals(9999, cal.get(Calendar.YEAR));
- assertEquals(Calendar.DECEMBER,
cal.get(Calendar.MONTH));
- assertEquals(31, cal.get(Calendar.DAY_OF_MONTH));
-
- ZonedDateTime zdt =
DateUtils.fromIso8601("9999-12-31T23:59:59Z");
- assertNotNull(zdt);
- assertEquals(9999, zdt.getYear());
- assertEquals(12, zdt.getMonthValue());
- assertEquals(31, zdt.getDayOfMonth());
- }
-
- @Test
- void l07_leapYear() {
- Calendar cal =
DateUtils.fromIso8601Calendar("2024-02-29T12:00:00Z");
- assertNotNull(cal);
- assertEquals(2024, cal.get(Calendar.YEAR));
- assertEquals(Calendar.FEBRUARY,
cal.get(Calendar.MONTH));
- assertEquals(29, cal.get(Calendar.DAY_OF_MONTH));
-
- ZonedDateTime zdt =
DateUtils.fromIso8601("2024-02-29T12:00:00Z");
- assertNotNull(zdt);
- assertEquals(2024, zdt.getYear());
- assertEquals(2, zdt.getMonthValue());
- assertEquals(29, zdt.getDayOfMonth());
- }
-
- @Test
- void l08_dstTransition() {
- // Test DST transition in America/New_York (Spring
forward)
- Calendar cal =
DateUtils.fromIso8601Calendar("2024-03-10T02:30:00-05:00");
- assertNotNull(cal);
- assertEquals(2024, cal.get(Calendar.YEAR));
- assertEquals(Calendar.MARCH, cal.get(Calendar.MONTH));
- assertEquals(10, cal.get(Calendar.DAY_OF_MONTH));
-
- ZonedDateTime zdt =
DateUtils.fromIso8601("2024-03-10T02:30:00-05:00");
- assertNotNull(zdt);
- assertEquals(2024, zdt.getYear());
- assertEquals(3, zdt.getMonthValue());
- assertEquals(10, zdt.getDayOfMonth());
- }
- }
-}
\ No newline at end of file
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/oapi/OpenApi_Test.java
b/juneau-utest/src/test/java/org/apache/juneau/oapi/OpenApi_Test.java
index 0717cc40d1..54c9a822e8 100644
--- a/juneau-utest/src/test/java/org/apache/juneau/oapi/OpenApi_Test.java
+++ b/juneau-utest/src/test/java/org/apache/juneau/oapi/OpenApi_Test.java
@@ -18,6 +18,7 @@ package org.apache.juneau.oapi;
import static org.apache.juneau.TestUtils.*;
import static org.apache.juneau.common.utils.CollectionUtils.*;
+import static org.apache.juneau.common.utils.DateUtils.*;
import static org.apache.juneau.httppart.HttpPartSchema.*;
import static org.apache.juneau.junit.bct.BctAssertions.*;
import static org.junit.jupiter.api.Assertions.*;
@@ -26,7 +27,6 @@ import java.util.*;
import org.apache.juneau.*;
import org.apache.juneau.collections.*;
-import org.apache.juneau.common.utils.*;
import org.apache.juneau.httppart.*;
import org.apache.juneau.serializer.*;
import org.junit.jupiter.api.*;
@@ -860,6 +860,6 @@ public class OpenApi_Test extends TestBase {
//---------------------------------------------------------------------------------------------
private static Calendar cal(String in) {
- return DateUtils.fromIso8601Calendar(in);
+ return fromIso8601Calendar(in);
}
}
\ No newline at end of file
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/objecttools/ObjectSearcher_Test.java
b/juneau-utest/src/test/java/org/apache/juneau/objecttools/ObjectSearcher_Test.java
index 667547be56..fdad777ab5 100755
---
a/juneau-utest/src/test/java/org/apache/juneau/objecttools/ObjectSearcher_Test.java
+++
b/juneau-utest/src/test/java/org/apache/juneau/objecttools/ObjectSearcher_Test.java
@@ -18,6 +18,7 @@ package org.apache.juneau.objecttools;
import static org.apache.juneau.TestUtils.*;
import static org.apache.juneau.common.utils.CollectionUtils.*;
+import static org.apache.juneau.common.utils.DateUtils.*;
import static org.apache.juneau.junit.bct.BctAssertions.*;
import java.util.*;
@@ -386,7 +387,7 @@ public class ObjectSearcher_Test extends TestBase {
var bb = new B[dates.length];
for (var i = 0; i < dates.length; i++) {
bb[i] = new B();
- bb[i].f =
DateUtils.fromIso8601Calendar(dates[i]);
+ bb[i].f = fromIso8601Calendar(dates[i]);
}
return bb;
}