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 86ca045528 Unit tests
86ca045528 is described below
commit 86ca04552896288ea5b567277e061ea846e7c19f
Author: James Bognar <[email protected]>
AuthorDate: Thu Dec 4 10:53:54 2025 -0800
Unit tests
---
.../org/apache/juneau/bean/atom/CommonEntry.java | 1 -
.../java/org/apache/juneau/bean/atom/Entry.java | 1 -
.../commons/function/ResettableSupplier.java | 31 ++++++++++-
.../juneau/commons/time/GranularZonedDateTime.java | 61 +++++++++++++++++++---
.../apache/juneau/commons/time/TimeProvider.java | 49 +++++++++++++++--
.../org/apache/juneau/commons/utils/Utils.java | 2 +-
.../microservice/resources/LogsResource.java | 1 -
.../apache/juneau/rest/arg/ResponseCodeArg.java | 2 -
.../a/rttests/RoundTripTransformBeans_Test.java | 2 -
.../httppart/OpenApiPartSerializer_Test.java | 1 -
.../java/org/apache/juneau/oapi/OpenApi_Test.java | 1 -
11 files changed, 128 insertions(+), 24 deletions(-)
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 661bb2ba53..ecf3db13e6 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
@@ -23,7 +23,6 @@ import static org.apache.juneau.xml.annotation.XmlFormat.*;
import java.util.*;
import org.apache.juneau.commons.time.*;
-import org.apache.juneau.commons.utils.*;
import org.apache.juneau.xml.annotation.*;
/**
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 8db35d282a..0c8be3e2da 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
@@ -23,7 +23,6 @@ import java.util.*;
import org.apache.juneau.annotation.*;
import org.apache.juneau.commons.time.*;
-import org.apache.juneau.commons.utils.*;
/**
* Represents an individual entry within an Atom feed or as a standalone Atom
document.
diff --git
a/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/function/ResettableSupplier.java
b/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/function/ResettableSupplier.java
index 6c655448ec..68bece2bda 100644
---
a/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/function/ResettableSupplier.java
+++
b/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/function/ResettableSupplier.java
@@ -19,7 +19,6 @@ package org.apache.juneau.commons.function;
import static org.apache.juneau.commons.utils.AssertionUtils.*;
import static org.apache.juneau.commons.utils.Utils.*;
-import java.time.*;
import java.util.*;
import java.util.concurrent.atomic.*;
import java.util.function.*;
@@ -110,6 +109,36 @@ public class ResettableSupplier<T> implements Supplier<T> {
cache.set(null);
}
+ /**
+ * Sets the cached value directly without invoking the underlying
supplier.
+ *
+ * <p>
+ * This method allows you to override the cached value, bypassing the
supplier.
+ * Subsequent calls to {@link #get()} will return the set value until
{@link #reset()} is called
+ * or the value is set again.
+ *
+ * <p>
+ * This method is thread-safe and is particularly useful for testing
when you need to
+ * inject a specific value without invoking the supplier.
+ *
+ * <h5 class='section'>Example:</h5>
+ * <p class='bjava'>
+ * <jc>// Create a supplier</jc>
+ * ResettableSupplier<String> <jv>supplier</jv> =
<jk>new</jk> ResettableSupplier<>(() -> <js>"computed"</js>);
+ *
+ * <jc>// Set a value directly without invoking the supplier</jc>
+ * <jv>supplier</jv>.<jsm>set</jsm>(<js>"injected"</js>);
+ *
+ * <jc>// get() returns the injected value</jc>
+ * assertEquals(<js>"injected"</js>,
<jv>supplier</jv>.<jsm>get</jsm>());
+ *
+ * <jc>// Reset clears the cache, next get() will invoke the
supplier</jc>
+ * <jv>supplier</jv>.<jsm>reset</jsm>();
+ * assertEquals(<js>"computed"</js>,
<jv>supplier</jv>.<jsm>get</jsm>());
+ * </p>
+ *
+ * @param value The value to cache. Can be <jk>null</jk>.
+ */
public void set(T value) {
cache.set(opt(value));
}
diff --git
a/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/time/GranularZonedDateTime.java
b/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/time/GranularZonedDateTime.java
index 0dc380462f..e01f5cd639 100644
---
a/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/time/GranularZonedDateTime.java
+++
b/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/time/GranularZonedDateTime.java
@@ -172,45 +172,90 @@ public class GranularZonedDateTime {
return of(value, null, null);
}
+ /**
+ * Parses an ISO8601 timestamp string into a GranularZonedDateTime with
a custom time provider.
+ *
+ * <p>
+ * This method is similar to {@link #of(String)}, but allows you to
specify a custom
+ * {@link TimeProvider} to use for obtaining the system default
timezone and current time.
+ * This is useful for testing or when you need deterministic time
behavior.
+ *
+ * <p>
+ * The time provider is used when:
+ * <ul>
+ * <li>No timezone is specified in the string - uses {@link
TimeProvider#getSystemDefaultZoneId()}
+ * <li>Time-only formats (starting with "T") - uses {@link
TimeProvider#now(ZoneId)} to get the current date
+ * </ul>
+ *
+ * <h5 class='section'>Example:</h5>
+ * <p class='bjava'>
+ * <jc>// Parse with custom time provider for testing</jc>
+ * <jk>var</jk> <jv>timeProvider</jv> = <jk>new</jk>
FakeTimeProvider();
+ * GranularZonedDateTime <jv>gdt</jv> =
GranularZonedDateTime.<jsm>of</jsm>(
+ * <js>"T12:30:45"</js>,
+ * <jv>timeProvider</jv>
+ * );
+ * <jc>// Result uses the time provider's current date and
timezone</jc>
+ * </p>
+ *
+ * @param value The ISO8601 timestamp string to parse.
+ * @param timeProvider The time provider to use for system default
timezone and current time.
+ * If null, {@link TimeProvider#INSTANCE} is used.
+ * @return A new GranularZonedDateTime instance.
+ * @throws IllegalArgumentException if value is null.
+ * @throws DateTimeParseException if the timestamp format is invalid.
+ */
public static GranularZonedDateTime of(String value, TimeProvider
timeProvider) {
return of(value, null, timeProvider);
}
/**
- * Parses an ISO8601 timestamp string into a GranularZonedDateTime with
a default timezone.
+ * Parses an ISO8601 timestamp string into a GranularZonedDateTime with
a default timezone and custom time provider.
*
* <p>
- * This method is similar to {@link #of(String)}, but allows you to
specify a default
- * timezone to use when no timezone is present in the timestamp string.
+ * This method is similar to {@link #of(String)}, but allows you to
specify both a default
+ * timezone and a custom {@link TimeProvider} to use when no timezone
is present in the timestamp string.
*
* <p>
* If the timestamp string contains a timezone (Z, +HH:mm, -HH:mm,
etc.), that timezone
* takes precedence over the defaultZoneId parameter. The defaultZoneId
is only used when
* no timezone is specified in the string.
*
+ * <p>
+ * The time provider is used when:
+ * <ul>
+ * <li>No timezone is specified and defaultZoneId is null - uses
{@link TimeProvider#getSystemDefaultZoneId()}
+ * <li>Time-only formats (starting with "T") - uses {@link
TimeProvider#now(ZoneId)} to get the current date
+ * </ul>
+ *
* <h5 class='section'>Example:</h5>
* <p class='bjava'>
- * <jc>// Parse with default timezone</jc>
+ * <jc>// Parse with default timezone and custom time provider</jc>
+ * <jk>var</jk> <jv>timeProvider</jv> = <jk>new</jk>
FakeTimeProvider();
* GranularZonedDateTime <jv>gdt1</jv> =
GranularZonedDateTime.<jsm>of</jsm>(
* <js>"2011-01-15T12:30:45"</js>,
- *
<jv>ZoneId</jv>.<jsm>of</jsm>(<js>"America/New_York"</js>)
+ *
<jv>ZoneId</jv>.<jsm>of</jsm>(<js>"America/New_York"</js>),
+ * <jv>timeProvider</jv>
* );
* <jc>// Result uses America/New_York timezone</jc>
*
* <jc>// Parse with timezone in string (defaultZoneId is
ignored)</jc>
* GranularZonedDateTime <jv>gdt2</jv> =
GranularZonedDateTime.<jsm>of</jsm>(
* <js>"2011-01-15T12:30:45Z"</js>,
- *
<jv>ZoneId</jv>.<jsm>of</jsm>(<js>"America/New_York"</js>)
+ *
<jv>ZoneId</jv>.<jsm>of</jsm>(<js>"America/New_York"</js>),
+ * <jv>timeProvider</jv>
* );
* <jc>// Result uses UTC (Z), not America/New_York</jc>
* </p>
*
* @param value The ISO8601 timestamp string to parse.
* @param defaultZoneId The default timezone to use if no timezone is
specified in the string.
- * If null, {@link ZoneId#systemDefault()} is used.
+ * If null, the time provider's system default timezone is used.
+ * @param timeProvider The time provider to use for system default
timezone and current time.
+ * If null, {@link TimeProvider#INSTANCE} is used.
* @return A new GranularZonedDateTime instance.
- * @throws IllegalArgumentException if seg is null.
+ * @throws IllegalArgumentException if value is null.
* @throws DateTimeParseException if the timestamp format is invalid.
*/
public static GranularZonedDateTime of(String value, ZoneId
defaultZoneId, TimeProvider timeProvider) {
diff --git
a/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/time/TimeProvider.java
b/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/time/TimeProvider.java
index fd76196d3d..a6b8454771 100644
---
a/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/time/TimeProvider.java
+++
b/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/time/TimeProvider.java
@@ -16,25 +16,64 @@
*/
package org.apache.juneau.commons.time;
-import static org.apache.juneau.commons.utils.Utils.*;
-
import java.time.*;
-import java.util.function.*;
-
-import org.apache.juneau.commons.function.*;
+/**
+ * Provides access to system time and timezone information.
+ *
+ * <p>
+ * This class abstracts time-related operations to allow for easier testing
and customization.
+ * By default, it delegates to the system's time and timezone, but can be
extended or replaced
+ * for testing purposes (e.g., using a {@link
org.apache.juneau.utest.utils.FakeTimeProvider}).
+ *
+ * <h5 class='section'>Usage:</h5>
+ * <p class='bjava'>
+ * <jc>// Use the default instance</jc>
+ * ZoneId <jv>zone</jv> =
TimeProvider.<jsf>INSTANCE</jsf>.<jsm>getSystemDefaultZoneId</jsm>();
+ * ZonedDateTime <jv>now</jv> =
TimeProvider.<jsf>INSTANCE</jsf>.<jsm>now</jsm>();
+ *
+ * <jc>// Or create a custom implementation for testing</jc>
+ * TimeProvider <jv>testProvider</jv> = <jk>new</jk> FakeTimeProvider();
+ * ZonedDateTime <jv>fixedTime</jv> =
<jv>testProvider</jv>.<jsm>now</jsm>();
+ * </p>
+ *
+ * <h5 class='section'>See Also:</h5>
+ * <ul>
+ * <li class='jm'>{@link org.apache.juneau.utest.utils.FakeTimeProvider}
+ * <li class='jm'>{@link GranularZonedDateTime}
+ * </ul>
+ */
public class TimeProvider {
+ /**
+ * The default instance that uses the system's time and timezone.
+ */
public static final TimeProvider INSTANCE = new TimeProvider();
+ /**
+ * Returns the system default timezone.
+ *
+ * @return The system default {@link ZoneId}.
+ */
public ZoneId getSystemDefaultZoneId() {
return ZoneId.systemDefault();
}
+ /**
+ * Returns the current date and time in the system default timezone.
+ *
+ * @return The current {@link ZonedDateTime} in the system default
timezone.
+ */
public ZonedDateTime now() {
return ZonedDateTime.now();
}
+ /**
+ * Returns the current date and time in the specified timezone.
+ *
+ * @param zoneId The timezone to use. Must not be <jk>null</jk>.
+ * @return The current {@link ZonedDateTime} in the specified timezone.
+ */
public ZonedDateTime now(ZoneId zoneId) {
return ZonedDateTime.now(zoneId);
}
diff --git
a/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/utils/Utils.java
b/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/utils/Utils.java
index 73c7422fc6..5598f1cb8d 100644
---
a/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/utils/Utils.java
+++
b/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/utils/Utils.java
@@ -1400,7 +1400,7 @@ public class Utils {
public static void quiet(Snippet snippet) {
try {
snippet.run();
- } catch (Throwable t) { /* Ignore */ }
+ } catch (@SuppressWarnings("unused") Throwable t) { /* Ignore
*/ }
}
/**
diff --git
a/juneau-microservice/juneau-microservice-core/src/main/java/org/apache/juneau/microservice/resources/LogsResource.java
b/juneau-microservice/juneau-microservice-core/src/main/java/org/apache/juneau/microservice/resources/LogsResource.java
index 17fc3a8d28..3becc5f0fc 100644
---
a/juneau-microservice/juneau-microservice-core/src/main/java/org/apache/juneau/microservice/resources/LogsResource.java
+++
b/juneau-microservice/juneau-microservice-core/src/main/java/org/apache/juneau/microservice/resources/LogsResource.java
@@ -26,7 +26,6 @@ import java.util.*;
import org.apache.juneau.annotation.*;
import org.apache.juneau.bean.*;
import org.apache.juneau.commons.time.*;
-import org.apache.juneau.commons.utils.*;
import org.apache.juneau.config.*;
import org.apache.juneau.html.annotation.*;
import org.apache.juneau.http.annotation.*;
diff --git
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/arg/ResponseCodeArg.java
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/arg/ResponseCodeArg.java
index b5f748502a..6ecdac1951 100644
---
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/arg/ResponseCodeArg.java
+++
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/arg/ResponseCodeArg.java
@@ -16,8 +16,6 @@
*/
package org.apache.juneau.rest.arg;
-import static org.apache.juneau.commons.utils.ClassUtils.*;
-
import java.lang.reflect.*;
import org.apache.juneau.http.annotation.*;
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/a/rttests/RoundTripTransformBeans_Test.java
b/juneau-utest/src/test/java/org/apache/juneau/a/rttests/RoundTripTransformBeans_Test.java
index ac8566c3dd..69415e1767 100755
---
a/juneau-utest/src/test/java/org/apache/juneau/a/rttests/RoundTripTransformBeans_Test.java
+++
b/juneau-utest/src/test/java/org/apache/juneau/a/rttests/RoundTripTransformBeans_Test.java
@@ -18,7 +18,6 @@ package org.apache.juneau.a.rttests;
import static org.apache.juneau.TestUtils.*;
import static org.apache.juneau.commons.utils.CollectionUtils.*;
-import static org.apache.juneau.commons.utils.DateUtils.*;
import static org.apache.juneau.commons.utils.IoUtils.*;
import static org.apache.juneau.commons.utils.StringUtils.*;
import static org.apache.juneau.junit.bct.BctAssertions.*;
@@ -32,7 +31,6 @@ import javax.xml.datatype.*;
import org.apache.juneau.*;
import org.apache.juneau.annotation.*;
import org.apache.juneau.commons.time.*;
-import org.apache.juneau.commons.utils.*;
import org.apache.juneau.html.*;
import org.apache.juneau.json.*;
import org.apache.juneau.msgpack.*;
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/httppart/OpenApiPartSerializer_Test.java
b/juneau-utest/src/test/java/org/apache/juneau/httppart/OpenApiPartSerializer_Test.java
index ef85f126b3..949984b168 100644
---
a/juneau-utest/src/test/java/org/apache/juneau/httppart/OpenApiPartSerializer_Test.java
+++
b/juneau-utest/src/test/java/org/apache/juneau/httppart/OpenApiPartSerializer_Test.java
@@ -28,7 +28,6 @@ import java.util.*;
import org.apache.juneau.*;
import org.apache.juneau.collections.*;
import org.apache.juneau.commons.time.*;
-import org.apache.juneau.commons.utils.*;
import org.apache.juneau.oapi.*;
import org.apache.juneau.serializer.*;
import org.junit.jupiter.api.*;
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 dcc3c288ec..447c6fd5eb 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
@@ -28,7 +28,6 @@ import java.util.*;
import org.apache.juneau.*;
import org.apache.juneau.collections.*;
import org.apache.juneau.commons.time.*;
-import org.apache.juneau.commons.utils.*;
import org.apache.juneau.httppart.*;
import org.apache.juneau.serializer.*;
import org.apache.juneau.utest.utils.FakeTimeProvider;