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 5499cef9c Test modernization, clean up utility classes.
5499cef9c is described below
commit 5499cef9c8d441d85f64fdbaf087f63f01cc4973
Author: James Bognar <[email protected]>
AuthorDate: Mon Aug 25 17:05:58 2025 -0400
Test modernization, clean up utility classes.
---
.../juneau/common/internal/ThrowableUtils.java | 35 +--------------------
.../org/apache/juneau/common/internal/Utils.java | 36 ++++++++++++++++++++++
.../java/org/apache/juneau/BeanPropertyMeta.java | 2 +-
.../apache/juneau/annotation/AnnotationImpl.java | 3 +-
.../apache/juneau/internal/AnnotationUtils.java | 6 ++--
.../org/apache/juneau/reflect/AnnotationInfo.java | 2 +-
.../java/org/apache/juneau/reflect/ClassInfo.java | 2 +-
.../org/apache/juneau/rest/client/RestClient.java | 3 +-
8 files changed, 48 insertions(+), 41 deletions(-)
diff --git
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/internal/ThrowableUtils.java
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/internal/ThrowableUtils.java
index fa3ae14dc..280042680 100644
---
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/internal/ThrowableUtils.java
+++
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/internal/ThrowableUtils.java
@@ -22,7 +22,7 @@ import org.apache.juneau.common.utils.*;
public class ThrowableUtils {
/**
- * Interface used with {@link #safeSupplier(SupplierWithThrowable)}.
+ * Interface used with {@link
Utils#safeSupplier(SupplierWithThrowable)}.
*/
@FunctionalInterface
public interface SupplierWithThrowable<T> {
@@ -113,37 +113,4 @@ public class ThrowableUtils {
}
return i;
}
-
- /**
- * Runs a snippet of code and encapsulates any throwable inside a
{@link RuntimeException}.
- *
- * @param snippet The snippet of code to run.
- */
- public static void safeRun(Snippet snippet) {
- try {
- snippet.run();
- } catch (RuntimeException t) {
- throw t;
- } catch (Throwable t) {
- throw asRuntimeException(t);
- }
- }
-
- /**
- * Allows you to wrap a supplier that throws an exception so that it
can be used in a fluent interface.
- *
- * @param <T> The supplier type.
- * @param supplier The supplier throwing an exception.
- * @return The supplied result.
- * @throws RuntimeException if supplier threw an exception.
- */
- public static <T> T safeSupplier(SupplierWithThrowable<T> supplier) {
- try {
- return supplier.get();
- } catch (RuntimeException t) {
- throw t;
- } catch (Throwable t) {
- throw asRuntimeException(t);
- }
- }
}
\ No newline at end of file
diff --git
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/internal/Utils.java
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/internal/Utils.java
index 1fc65897f..03511f346 100644
---
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/internal/Utils.java
+++
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/internal/Utils.java
@@ -26,6 +26,9 @@ import java.util.function.*;
import java.util.regex.*;
import java.util.stream.*;
+import org.apache.juneau.common.internal.ThrowableUtils.*;
+import org.apache.juneau.common.utils.*;
+
public class Utils {
@@ -1435,4 +1438,37 @@ public class Utils {
public static <T> Set<T> u(Set<? extends T> value) {
return value == null ? null :
Collections.unmodifiableSet(value);
}
+
+ /**
+ * Allows you to wrap a supplier that throws an exception so that it
can be used in a fluent interface.
+ *
+ * @param <T> The supplier type.
+ * @param supplier The supplier throwing an exception.
+ * @return The supplied result.
+ * @throws RuntimeException if supplier threw an exception.
+ */
+ public static <T> T
safeSupplier(ThrowableUtils.SupplierWithThrowable<T> supplier) {
+ try {
+ return supplier.get();
+ } catch (RuntimeException t) {
+ throw t;
+ } catch (Throwable t) {
+ throw ThrowableUtils.asRuntimeException(t);
+ }
+ }
+
+ /**
+ * Runs a snippet of code and encapsulates any throwable inside a
{@link RuntimeException}.
+ *
+ * @param snippet The snippet of code to run.
+ */
+ public static void safe(Snippet snippet) {
+ try {
+ snippet.run();
+ } catch (RuntimeException t) {
+ throw t;
+ } catch (Throwable t) {
+ throw ThrowableUtils.asRuntimeException(t);
+ }
+ }
}
\ No newline at end of file
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanPropertyMeta.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanPropertyMeta.java
index 086616cdf..2bf0e1cdf 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanPropertyMeta.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanPropertyMeta.java
@@ -899,7 +899,7 @@ public final class BeanPropertyMeta implements
Comparable<BeanPropertyMeta> {
if (isDyna) {
if (extraKeys != null && getter != null && !
isDynaGetterMap) {
Map<String,Object> m = map();
-
((Collection<String>)extraKeys.invoke(bean)).forEach(x -> safeRun(()->m.put(x,
getter.invoke(bean, x))));
+
((Collection<String>)extraKeys.invoke(bean)).forEach(x -> safe(()->m.put(x,
getter.invoke(bean, x))));
return m;
}
if (getter != null && isDynaGetterMap)
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/annotation/AnnotationImpl.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/annotation/AnnotationImpl.java
index 858efe3e8..42fe212ac 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/annotation/AnnotationImpl.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/annotation/AnnotationImpl.java
@@ -22,6 +22,7 @@ import java.lang.reflect.*;
import java.util.*;
import org.apache.juneau.collections.*;
+import org.apache.juneau.common.internal.*;
import org.apache.juneau.internal.*;
/**
@@ -108,7 +109,7 @@ public class AnnotationImpl implements Annotation {
stream(annotationType().getDeclaredMethods())
.filter(x->x.getParameterCount() == 0 &&
x.getDeclaringClass().isAnnotation())
.sorted(Comparator.comparing(Method::getName))
- .forEach(x -> m.append(x.getName(),
safeSupplier(()->x.invoke(this))));
+ .forEach(x -> m.append(x.getName(),
Utils.safeSupplier(()->x.invoke(this))));
return m;
}
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/AnnotationUtils.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/AnnotationUtils.java
index 0ff8e3a59..f24d1268f 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/AnnotationUtils.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/AnnotationUtils.java
@@ -19,6 +19,8 @@ import java.lang.reflect.*;
import java.util.*;
import java.util.stream.*;
+import org.apache.juneau.common.internal.*;
+
/**
* Annotation utilities.
*
@@ -47,7 +49,7 @@ public class AnnotationUtils {
return false;
boolean b= getAnnotationMethods(t1)
- .anyMatch(x -> ! memberEquals(x.getReturnType(),
safeSupplier(()->x.invoke(a1)), safeSupplier(()->x.invoke(a2))));
+ .anyMatch(x -> ! memberEquals(x.getReturnType(),
Utils.safeSupplier(()->x.invoke(a1)), Utils.safeSupplier(()->x.invoke(a2))));
if (b)
return false;
@@ -64,7 +66,7 @@ public class AnnotationUtils {
*/
public static int hashCode(Annotation a) {
return getAnnotationMethods(a.annotationType())
- .mapToInt(x -> hashMember(x.getName(),
safeSupplier(()->x.invoke(a))))
+ .mapToInt(x -> hashMember(x.getName(),
Utils.safeSupplier(()->x.invoke(a))))
.sum();
}
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/AnnotationInfo.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/AnnotationInfo.java
index 31301aca9..1618a343b 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/AnnotationInfo.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/AnnotationInfo.java
@@ -307,7 +307,7 @@ public final class AnnotationInfo<T extends Annotation> {
public <V> AnnotationInfo<?> forEachValue(Class<V> type, String name,
Predicate<V> test, Consumer<V> action) {
for (Method m : _getMethods())
if (m.getName().equals(name) &&
m.getReturnType().equals(type))
- safeRun(() -> consume(test, action,
(V)m.invoke(a)));
+ Utils.safe(() -> consume(test, action,
(V)m.invoke(a)));
return this;
}
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/ClassInfo.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/ClassInfo.java
index 7045896fd..5d2ef279d 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/ClassInfo.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/ClassInfo.java
@@ -149,7 +149,7 @@ public final class ClassInfo {
Value<Class<?>> v = Value.empty();
ClassInfo.of(c).forEachPublicMethod(
m -> m.hasName("getTargetClass") && m.hasNoParams() &&
m.hasReturnType(Class.class),
- m -> safeRun(() -> v.set(m.invoke(o)))
+ m -> safe(() -> v.set(m.invoke(o)))
);
return v.orElse(null);
}
diff --git
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestClient.java
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestClient.java
index a3b7f2703..698088d47 100644
---
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestClient.java
+++
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestClient.java
@@ -64,6 +64,7 @@ import org.apache.juneau.*;
import org.apache.juneau.annotation.*;
import org.apache.juneau.collections.*;
import org.apache.juneau.common.internal.*;
+import org.apache.juneau.common.internal.Utils;
import org.apache.juneau.cp.*;
import org.apache.juneau.html.*;
import org.apache.juneau.http.remote.RemoteReturn;
@@ -7379,7 +7380,7 @@ public class RestClient extends BeanContextable
implements HttpClient, Closeable
Object bean =
args[rmba.getIndex()];
if (bean != null) {
for
(RequestBeanPropertyMeta p : rbm.getProperties()) {
- Object
val = safeSupplier(()->p.getGetter().invoke(bean));
+ Object
val = Utils.safeSupplier(()->p.getGetter().invoke(bean));
HttpPartType pt = p.getPartType();
String
pn = p.getPartName();
HttpPartSchema schema = p.getSchema();