You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2021/11/14 01:19:21 UTC

[commons-lang] branch master updated: Sort test methods.

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-lang.git


The following commit(s) were added to refs/heads/master by this push:
     new bef0c8a  Sort test methods.
bef0c8a is described below

commit bef0c8a5728d9eed36a08c431be036370553c602
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Nov 13 20:19:18 2021 -0500

    Sort test methods.
---
 .../org/apache/commons/lang3/function/Objects.java | 80 ++++++++++----------
 .../apache/commons/lang3/function/ObjectsTest.java | 86 +++++++++++-----------
 2 files changed, 83 insertions(+), 83 deletions(-)

diff --git a/src/test/java/org/apache/commons/lang3/function/Objects.java b/src/test/java/org/apache/commons/lang3/function/Objects.java
index 9bec191..b919c7f 100755
--- a/src/test/java/org/apache/commons/lang3/function/Objects.java
+++ b/src/test/java/org/apache/commons/lang3/function/Objects.java
@@ -75,19 +75,37 @@ public class Objects {
         return requireNonNull(value, "The value must not be null.");
     }
 
-    /**
-     * Checks, whether the given object is non-null. If so, returns the non-null
-     * object as a result value. Otherwise, a NullPointerException is thrown.
-     * @param <T> The type of parameter {@code value}, also the result type.
+    /** Checks, whether the given object is non-null. If so, returns the non-null
+     * object as a result value. Otherwise, invokes the given {@link Supplier},
+     * and returns the suppliers result value.
+     * @param <T> The type of parameter {@code value}, also the result type of
+     *    the default value supplier, and of the method itself.
+     * @param <E> The type of exception, that the {@code default value supplier},
+     *    may throw.
      * @param value The value, which is being checked.
-     * @param defaultValue The default value, which is being returned, if the
-     *   check fails, and the {@code value} is null.
-     * @throws NullPointerException The input value, and the default value are null.
-     * @return The given input value, if it was found to be non-null.
-     * @see java.util.Objects#requireNonNull(Object)
+     * @param defaultValueSupplier The supplier, which returns the default value. This default
+     *   value <em>must</em> be non-null. The supplier will only be invoked, if
+     *   necessary. (If the {@code value} parameter is null, that is.)
+     * @return The given input value, if it was found to be non-null. Otherwise,
+     *   the value, that has been returned by the default value supplier.
+     * @see #requireNonNull(Object)
+     * @see #requireNonNull(Object, String)
+     * @see #requireNonNull(Object, Supplier)
+     * @throws NullPointerException The default value supplier is null, or the default
+     *   value supplier has returned null.
      */
-    public static <T> @Nonnull T requireNonNull(@Nullable final T value, @Nonnull final T defaultValue) throws NullPointerException {
-        return value == null ? requireNonNull(defaultValue) : value;
+    public static <T, E extends Throwable> @Nonnull T requireNonNull(@Nullable final T value, @Nonnull final FailableSupplier<T, E> defaultValueSupplier) throws NullPointerException {
+        if (value == null) {
+            final FailableSupplier<T, ?> supplier = requireNonNull(defaultValueSupplier, "The supplier must not be null");
+            final T defaultValue;
+            try {
+                defaultValue = supplier.get();
+            } catch (final Throwable t) {
+                throw Failable.rethrow(t);
+            }
+            return requireNonNull(defaultValue, "The supplier must not return null.");
+        }
+        return value;
     }
 
     /**
@@ -128,36 +146,18 @@ public class Objects {
         return value;
     }
 
-    /** Checks, whether the given object is non-null. If so, returns the non-null
-     * object as a result value. Otherwise, invokes the given {@link Supplier},
-     * and returns the suppliers result value.
-     * @param <T> The type of parameter {@code value}, also the result type of
-     *    the default value supplier, and of the method itself.
-     * @param <E> The type of exception, that the {@code default value supplier},
-     *    may throw.
+    /**
+     * Checks, whether the given object is non-null. If so, returns the non-null
+     * object as a result value. Otherwise, a NullPointerException is thrown.
+     * @param <T> The type of parameter {@code value}, also the result type.
      * @param value The value, which is being checked.
-     * @param defaultValueSupplier The supplier, which returns the default value. This default
-     *   value <em>must</em> be non-null. The supplier will only be invoked, if
-     *   necessary. (If the {@code value} parameter is null, that is.)
-     * @return The given input value, if it was found to be non-null. Otherwise,
-     *   the value, that has been returned by the default value supplier.
-     * @see #requireNonNull(Object)
-     * @see #requireNonNull(Object, String)
-     * @see #requireNonNull(Object, Supplier)
-     * @throws NullPointerException The default value supplier is null, or the default
-     *   value supplier has returned null.
+     * @param defaultValue The default value, which is being returned, if the
+     *   check fails, and the {@code value} is null.
+     * @throws NullPointerException The input value, and the default value are null.
+     * @return The given input value, if it was found to be non-null.
+     * @see java.util.Objects#requireNonNull(Object)
      */
-    public static <T, E extends Throwable> @Nonnull T requireNonNull(@Nullable final T value, @Nonnull final FailableSupplier<T, E> defaultValueSupplier) throws NullPointerException {
-        if (value == null) {
-            final FailableSupplier<T, ?> supplier = requireNonNull(defaultValueSupplier, "The supplier must not be null");
-            final T defaultValue;
-            try {
-                defaultValue = supplier.get();
-            } catch (final Throwable t) {
-                throw Failable.rethrow(t);
-            }
-            return requireNonNull(defaultValue, "The supplier must not return null.");
-        }
-        return value;
+    public static <T> @Nonnull T requireNonNull(@Nullable final T value, @Nonnull final T defaultValue) throws NullPointerException {
+        return value == null ? requireNonNull(defaultValue) : value;
     }
 }
diff --git a/src/test/java/org/apache/commons/lang3/function/ObjectsTest.java b/src/test/java/org/apache/commons/lang3/function/ObjectsTest.java
index e03cbaa..6803384 100755
--- a/src/test/java/org/apache/commons/lang3/function/ObjectsTest.java
+++ b/src/test/java/org/apache/commons/lang3/function/ObjectsTest.java
@@ -29,25 +29,22 @@ import org.junit.jupiter.api.Test;
 
 
 class ObjectsTest {
-    @Test
-    void testRequireNonNullObject() {
-        assertSame("foo", Objects.requireNonNull("foo"));
-        try {
-            Objects.requireNonNull(null);
-            fail("Expected Exception");
-        } catch (final NullPointerException e) {
-            assertEquals("The value must not be null.", e.getMessage());
+    public static class TestableFailableSupplier<O, E extends Exception> implements FailableSupplier<O, E> {
+        private final FailableSupplier<O, E> supplier;
+        private boolean invoked;
+
+        TestableFailableSupplier(final FailableSupplier<O, E> pSupplier) {
+            this.supplier = pSupplier;
         }
-    }
 
-    @Test
-    void testRequireNonNullObjectString() {
-        assertSame("foo", Objects.requireNonNull("foo", "bar"));
-        try {
-            Objects.requireNonNull(null, "bar");
-            fail("Expected Exception");
-        } catch (final NullPointerException e) {
-            assertEquals("bar", e.getMessage());
+        @Override
+        public O get() throws E {
+            invoked = true;
+            return supplier.get();
+        }
+
+        public boolean isInvoked() {
+            return invoked;
         }
     }
 
@@ -71,35 +68,13 @@ class ObjectsTest {
     }
 
     @Test
-    void testRequireNonNullObjectSupplierString() {
-        final TestableSupplier<String> supplier = new TestableSupplier<>(() -> "bar");
-        assertSame("foo", Objects.requireNonNull("foo", supplier));
-        assertFalse(supplier.isInvoked());
+    void testRequireNonNullObject() {
+        assertSame("foo", Objects.requireNonNull("foo"));
         try {
-            Objects.requireNonNull(null, supplier);
+            Objects.requireNonNull(null);
             fail("Expected Exception");
         } catch (final NullPointerException e) {
-            assertEquals("bar", e.getMessage());
-            assertTrue(supplier.isInvoked());
-        }
-    }
-
-    public static class TestableFailableSupplier<O, E extends Exception> implements FailableSupplier<O, E> {
-        private final FailableSupplier<O, E> supplier;
-        private boolean invoked;
-
-        TestableFailableSupplier(final FailableSupplier<O, E> pSupplier) {
-            this.supplier = pSupplier;
-        }
-
-        @Override
-        public O get() throws E {
-            invoked = true;
-            return supplier.get();
-        }
-
-        public boolean isInvoked() {
-            return invoked;
+            assertEquals("The value must not be null.", e.getMessage());
         }
     }
 
@@ -137,4 +112,29 @@ class ObjectsTest {
             assertTrue(supplier4.isInvoked());
         }
     }
+
+    @Test
+    void testRequireNonNullObjectString() {
+        assertSame("foo", Objects.requireNonNull("foo", "bar"));
+        try {
+            Objects.requireNonNull(null, "bar");
+            fail("Expected Exception");
+        } catch (final NullPointerException e) {
+            assertEquals("bar", e.getMessage());
+        }
+    }
+
+    @Test
+    void testRequireNonNullObjectSupplierString() {
+        final TestableSupplier<String> supplier = new TestableSupplier<>(() -> "bar");
+        assertSame("foo", Objects.requireNonNull("foo", supplier));
+        assertFalse(supplier.isInvoked());
+        try {
+            Objects.requireNonNull(null, supplier);
+            fail("Expected Exception");
+        } catch (final NullPointerException e) {
+            assertEquals("bar", e.getMessage());
+            assertTrue(supplier.isInvoked());
+        }
+    }
 }