Add and use ObjectUtils.requireNonEmpty().
This is a different implementation of the ideas and discussion in PR #716.
This commit is contained in:
parent
43f0424827
commit
ea34486551
|
@ -96,6 +96,7 @@ The <action> type attribute can be add,update,fix,remove.
|
||||||
<action type="add" dev="ggregory" due-to="Gary Gregory">Add DurationUtils.</action>
|
<action type="add" dev="ggregory" due-to="Gary Gregory">Add DurationUtils.</action>
|
||||||
<action type="add" dev="jochen">Introduce the use of @Nonnull, and @Nullable, and the Objects class as a helper tool.</action>
|
<action type="add" dev="jochen">Introduce the use of @Nonnull, and @Nullable, and the Objects class as a helper tool.</action>
|
||||||
<action type="add" dev="ggregory" due-to="Arturo Bernal, Gary Gregory">Add and use true and false String constants #714.</action>
|
<action type="add" dev="ggregory" due-to="Arturo Bernal, Gary Gregory">Add and use true and false String constants #714.</action>
|
||||||
|
<action type="add" dev="ggregory" due-to="Arturo Bernal, Gary Gregory">Add and use ObjectUtils.requireNonEmpty() #716.</action>
|
||||||
<!-- UPDATE -->
|
<!-- UPDATE -->
|
||||||
<action type="update" dev="ggregory" due-to="Gary Gregory">Enable Dependabot #587.</action>
|
<action type="update" dev="ggregory" due-to="Gary Gregory">Enable Dependabot #587.</action>
|
||||||
<action type="update" dev="chtompki">Bump junit-jupiter from 5.6.2 to 5.7.0.</action>
|
<action type="update" dev="chtompki">Bump junit-jupiter from 5.6.2 to 5.7.0.</action>
|
||||||
|
|
|
@ -29,7 +29,6 @@
|
||||||
* @since 2.0
|
* @since 2.0
|
||||||
*/
|
*/
|
||||||
public class BooleanUtils {
|
public class BooleanUtils {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The false String {@code "false"}.
|
* The false String {@code "false"}.
|
||||||
*
|
*
|
||||||
|
@ -86,18 +85,12 @@ public class BooleanUtils {
|
||||||
* @param array an array of {@code boolean}s
|
* @param array an array of {@code boolean}s
|
||||||
* @return the result of the logical 'and' operation. That is {@code false}
|
* @return the result of the logical 'and' operation. That is {@code false}
|
||||||
* if any of the parameters is {@code false} and {@code true} otherwise.
|
* if any of the parameters is {@code false} and {@code true} otherwise.
|
||||||
* @throws IllegalArgumentException if {@code array} is {@code null}
|
* @throws NullPointerException if {@code array} is {@code null}
|
||||||
* @throws IllegalArgumentException if {@code array} is empty.
|
* @throws IllegalArgumentException if {@code array} is empty.
|
||||||
* @since 3.0.1
|
* @since 3.0.1
|
||||||
*/
|
*/
|
||||||
public static boolean and(final boolean... array) {
|
public static boolean and(final boolean... array) {
|
||||||
// Validates input
|
ObjectUtils.requireNonEmpty(array, "array");
|
||||||
if (array == null) {
|
|
||||||
throw new IllegalArgumentException("The Array must not be null");
|
|
||||||
}
|
|
||||||
if (array.length == 0) {
|
|
||||||
throw new IllegalArgumentException("Array is empty");
|
|
||||||
}
|
|
||||||
for (final boolean element : array) {
|
for (final boolean element : array) {
|
||||||
if (!element) {
|
if (!element) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -121,18 +114,13 @@ public static boolean and(final boolean... array) {
|
||||||
* @param array an array of {@code Boolean}s
|
* @param array an array of {@code Boolean}s
|
||||||
* @return the result of the logical 'and' operation. That is {@code false}
|
* @return the result of the logical 'and' operation. That is {@code false}
|
||||||
* if any of the parameters is {@code false} and {@code true} otherwise.
|
* if any of the parameters is {@code false} and {@code true} otherwise.
|
||||||
* @throws IllegalArgumentException if {@code array} is {@code null}
|
* @throws NullPointerException if {@code array} is {@code null}
|
||||||
* @throws IllegalArgumentException if {@code array} is empty.
|
* @throws IllegalArgumentException if {@code array} is empty.
|
||||||
* @throws IllegalArgumentException if {@code array} contains a {@code null}
|
* @throws IllegalArgumentException if {@code array} contains a {@code null}
|
||||||
* @since 3.0.1
|
* @since 3.0.1
|
||||||
*/
|
*/
|
||||||
public static Boolean and(final Boolean... array) {
|
public static Boolean and(final Boolean... array) {
|
||||||
if (array == null) {
|
ObjectUtils.requireNonEmpty(array, "array");
|
||||||
throw new IllegalArgumentException("The Array must not be null");
|
|
||||||
}
|
|
||||||
if (array.length == 0) {
|
|
||||||
throw new IllegalArgumentException("Array is empty");
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
final boolean[] primitive = ArrayUtils.toPrimitive(array);
|
final boolean[] primitive = ArrayUtils.toPrimitive(array);
|
||||||
return and(primitive) ? Boolean.TRUE : Boolean.FALSE;
|
return and(primitive) ? Boolean.TRUE : Boolean.FALSE;
|
||||||
|
@ -262,7 +250,6 @@ public static Boolean negate(final Boolean bool) {
|
||||||
}
|
}
|
||||||
return bool.booleanValue() ? Boolean.FALSE : Boolean.TRUE;
|
return bool.booleanValue() ? Boolean.FALSE : Boolean.TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>Performs an 'or' operation on a set of booleans.</p>
|
* <p>Performs an 'or' operation on a set of booleans.</p>
|
||||||
*
|
*
|
||||||
|
@ -277,17 +264,12 @@ public static Boolean negate(final Boolean bool) {
|
||||||
*
|
*
|
||||||
* @param array an array of {@code boolean}s
|
* @param array an array of {@code boolean}s
|
||||||
* @return {@code true} if any of the arguments is {@code true}, and it returns {@code false} otherwise.
|
* @return {@code true} if any of the arguments is {@code true}, and it returns {@code false} otherwise.
|
||||||
* @throws IllegalArgumentException if {@code array} is {@code null}
|
* @throws NullPointerException if {@code array} is {@code null}
|
||||||
* @throws IllegalArgumentException if {@code array} is empty.
|
* @throws IllegalArgumentException if {@code array} is empty.
|
||||||
* @since 3.0.1
|
* @since 3.0.1
|
||||||
*/
|
*/
|
||||||
public static boolean or(final boolean... array) {
|
public static boolean or(final boolean... array) {
|
||||||
if (array == null) {
|
ObjectUtils.requireNonEmpty(array, "array");
|
||||||
throw new IllegalArgumentException("The Array must not be null");
|
|
||||||
}
|
|
||||||
if (array.length == 0) {
|
|
||||||
throw new IllegalArgumentException("Array is empty");
|
|
||||||
}
|
|
||||||
for (final boolean element : array) {
|
for (final boolean element : array) {
|
||||||
if (element) {
|
if (element) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -311,18 +293,13 @@ public static boolean or(final boolean... array) {
|
||||||
*
|
*
|
||||||
* @param array an array of {@code Boolean}s
|
* @param array an array of {@code Boolean}s
|
||||||
* @return {@code true} if any of the arguments is {@code true}, and it returns {@code false} otherwise.
|
* @return {@code true} if any of the arguments is {@code true}, and it returns {@code false} otherwise.
|
||||||
* @throws IllegalArgumentException if {@code array} is {@code null}
|
* @throws NullPointerException if {@code array} is {@code null}
|
||||||
* @throws IllegalArgumentException if {@code array} is empty.
|
* @throws IllegalArgumentException if {@code array} is empty.
|
||||||
* @throws IllegalArgumentException if {@code array} contains a {@code null}
|
* @throws IllegalArgumentException if {@code array} contains a {@code null}
|
||||||
* @since 3.0.1
|
* @since 3.0.1
|
||||||
*/
|
*/
|
||||||
public static Boolean or(final Boolean... array) {
|
public static Boolean or(final Boolean... array) {
|
||||||
if (array == null) {
|
ObjectUtils.requireNonEmpty(array, "array");
|
||||||
throw new IllegalArgumentException("The Array must not be null");
|
|
||||||
}
|
|
||||||
if (array.length == 0) {
|
|
||||||
throw new IllegalArgumentException("Array is empty");
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
final boolean[] primitive = ArrayUtils.toPrimitive(array);
|
final boolean[] primitive = ArrayUtils.toPrimitive(array);
|
||||||
return or(primitive) ? Boolean.TRUE : Boolean.FALSE;
|
return or(primitive) ? Boolean.TRUE : Boolean.FALSE;
|
||||||
|
@ -1109,17 +1086,11 @@ public static String toStringYesNo(final Boolean bool) {
|
||||||
*
|
*
|
||||||
* @param array an array of {@code boolean}s
|
* @param array an array of {@code boolean}s
|
||||||
* @return the result of the xor operations
|
* @return the result of the xor operations
|
||||||
* @throws IllegalArgumentException if {@code array} is {@code null}
|
* @throws NullPointerException if {@code array} is {@code null}
|
||||||
* @throws IllegalArgumentException if {@code array} is empty.
|
* @throws IllegalArgumentException if {@code array} is empty.
|
||||||
*/
|
*/
|
||||||
public static boolean xor(final boolean... array) {
|
public static boolean xor(final boolean... array) {
|
||||||
if (array == null) {
|
ObjectUtils.requireNonEmpty(array, "array");
|
||||||
throw new IllegalArgumentException("The Array must not be null");
|
|
||||||
}
|
|
||||||
if (array.length == 0) {
|
|
||||||
throw new IllegalArgumentException("Array is empty");
|
|
||||||
}
|
|
||||||
|
|
||||||
// false if the neutral element of the xor operator
|
// false if the neutral element of the xor operator
|
||||||
boolean result = false;
|
boolean result = false;
|
||||||
for (final boolean element : array) {
|
for (final boolean element : array) {
|
||||||
|
@ -1141,17 +1112,12 @@ public static boolean xor(final boolean... array) {
|
||||||
*
|
*
|
||||||
* @param array an array of {@code Boolean}s
|
* @param array an array of {@code Boolean}s
|
||||||
* @return the result of the xor operations
|
* @return the result of the xor operations
|
||||||
* @throws IllegalArgumentException if {@code array} is {@code null}
|
* @throws NullPointerException if {@code array} is {@code null}
|
||||||
* @throws IllegalArgumentException if {@code array} is empty.
|
* @throws IllegalArgumentException if {@code array} is empty.
|
||||||
* @throws IllegalArgumentException if {@code array} contains a {@code null}
|
* @throws IllegalArgumentException if {@code array} contains a {@code null}
|
||||||
*/
|
*/
|
||||||
public static Boolean xor(final Boolean... array) {
|
public static Boolean xor(final Boolean... array) {
|
||||||
if (array == null) {
|
ObjectUtils.requireNonEmpty(array, "array");
|
||||||
throw new IllegalArgumentException("The Array must not be null");
|
|
||||||
}
|
|
||||||
if (array.length == 0) {
|
|
||||||
throw new IllegalArgumentException("Array is empty");
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
final boolean[] primitive = ArrayUtils.toPrimitive(array);
|
final boolean[] primitive = ArrayUtils.toPrimitive(array);
|
||||||
return xor(primitive) ? Boolean.TRUE : Boolean.FALSE;
|
return xor(primitive) ? Boolean.TRUE : Boolean.FALSE;
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
@ -108,32 +109,6 @@ private Object readResolve() {
|
||||||
*/
|
*/
|
||||||
public static final Null NULL = new Null();
|
public static final Null NULL = new Null();
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if all values in the given array are {@code null}.
|
|
||||||
*
|
|
||||||
* <p>
|
|
||||||
* If all the values are {@code null} or the array is {@code null}
|
|
||||||
* or empty, then {@code true} is returned, otherwise {@code false} is returned.
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* <pre>
|
|
||||||
* ObjectUtils.allNull(*) = false
|
|
||||||
* ObjectUtils.allNull(*, null) = false
|
|
||||||
* ObjectUtils.allNull(null, *) = false
|
|
||||||
* ObjectUtils.allNull(null, null, *, *) = false
|
|
||||||
* ObjectUtils.allNull(null) = true
|
|
||||||
* ObjectUtils.allNull(null, null) = true
|
|
||||||
* </pre>
|
|
||||||
*
|
|
||||||
* @param values the values to test, may be {@code null} or empty
|
|
||||||
* @return {@code true} if all values in the array are {@code null}s,
|
|
||||||
* {@code false} if there is at least one non-null value in the array.
|
|
||||||
* @since 3.11
|
|
||||||
*/
|
|
||||||
public static boolean allNull(final Object... values) {
|
|
||||||
return !anyNotNull(values);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if all values in the array are not {@code nulls}.
|
* Checks if all values in the array are not {@code nulls}.
|
||||||
*
|
*
|
||||||
|
@ -174,31 +149,29 @@ public static boolean allNotNull(final Object... values) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if any value in the given array is {@code null}.
|
* Checks if all values in the given array are {@code null}.
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>
|
||||||
* If any of the values are {@code null} or the array is {@code null},
|
* If all the values are {@code null} or the array is {@code null}
|
||||||
* then {@code true} is returned, otherwise {@code false} is returned.
|
* or empty, then {@code true} is returned, otherwise {@code false} is returned.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* <pre>
|
* <pre>
|
||||||
* ObjectUtils.anyNull(*) = false
|
* ObjectUtils.allNull(*) = false
|
||||||
* ObjectUtils.anyNull(*, *) = false
|
* ObjectUtils.allNull(*, null) = false
|
||||||
* ObjectUtils.anyNull(null) = true
|
* ObjectUtils.allNull(null, *) = false
|
||||||
* ObjectUtils.anyNull(null, null) = true
|
* ObjectUtils.allNull(null, null, *, *) = false
|
||||||
* ObjectUtils.anyNull(null, *) = true
|
* ObjectUtils.allNull(null) = true
|
||||||
* ObjectUtils.anyNull(*, null) = true
|
* ObjectUtils.allNull(null, null) = true
|
||||||
* ObjectUtils.anyNull(*, *, null, *) = true
|
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* @param values the values to test, may be {@code null} or empty
|
* @param values the values to test, may be {@code null} or empty
|
||||||
* @return {@code true} if there is at least one {@code null} value in the array,
|
* @return {@code true} if all values in the array are {@code null}s,
|
||||||
* {@code false} if all the values are non-null.
|
* {@code false} if there is at least one non-null value in the array.
|
||||||
* If the array is {@code null} or empty, {@code true} is also returned.
|
|
||||||
* @since 3.11
|
* @since 3.11
|
||||||
*/
|
*/
|
||||||
public static boolean anyNull(final Object... values) {
|
public static boolean allNull(final Object... values) {
|
||||||
return !allNotNull(values);
|
return !anyNotNull(values);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -228,6 +201,34 @@ public static boolean anyNotNull(final Object... values) {
|
||||||
return firstNonNull(values) != null;
|
return firstNonNull(values) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if any value in the given array is {@code null}.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* If any of the values are {@code null} or the array is {@code null},
|
||||||
|
* then {@code true} is returned, otherwise {@code false} is returned.
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* ObjectUtils.anyNull(*) = false
|
||||||
|
* ObjectUtils.anyNull(*, *) = false
|
||||||
|
* ObjectUtils.anyNull(null) = true
|
||||||
|
* ObjectUtils.anyNull(null, null) = true
|
||||||
|
* ObjectUtils.anyNull(null, *) = true
|
||||||
|
* ObjectUtils.anyNull(*, null) = true
|
||||||
|
* ObjectUtils.anyNull(*, *, null, *) = true
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* @param values the values to test, may be {@code null} or empty
|
||||||
|
* @return {@code true} if there is at least one {@code null} value in the array,
|
||||||
|
* {@code false} if all the values are non-null.
|
||||||
|
* If the array is {@code null} or empty, {@code true} is also returned.
|
||||||
|
* @since 3.11
|
||||||
|
*/
|
||||||
|
public static boolean anyNull(final Object... values) {
|
||||||
|
return !allNotNull(values);
|
||||||
|
}
|
||||||
|
|
||||||
// cloning
|
// cloning
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
/**
|
/**
|
||||||
|
@ -1184,6 +1185,64 @@ public static boolean notEqual(final Object object1, final Object object2) {
|
||||||
return !equals(object1, object2);
|
return !equals(object1, object2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks that the specified object reference is not {@code null} or empty per {@link #isEmpty(Object)}. Use this
|
||||||
|
* method for validation, for example:
|
||||||
|
*
|
||||||
|
* <blockquote>
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* public Foo(Bar bar) {
|
||||||
|
* this.bar = Objects.requireNonEmpty(bar);
|
||||||
|
* }
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* </blockquote>
|
||||||
|
*
|
||||||
|
* @param <T> the type of the reference.
|
||||||
|
* @param obj the object reference to check for nullity.
|
||||||
|
* @return {@code obj} if not {@code null}.
|
||||||
|
* @throws NullPointerException if {@code obj} is {@code null}.
|
||||||
|
* @throws IllegalArgumentException if {@code obj} is empty per {@link #isEmpty(Object)}.
|
||||||
|
* @see #isEmpty(Object)
|
||||||
|
* @since 3.12.0
|
||||||
|
*/
|
||||||
|
public static <T> T requireNonEmpty(final T obj) {
|
||||||
|
return requireNonEmpty(obj, "object");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks that the specified object reference is not {@code null} or empty per {@link #isEmpty(Object)}. Use this
|
||||||
|
* method for validation, for example:
|
||||||
|
*
|
||||||
|
* <blockquote>
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* public Foo(Bar bar) {
|
||||||
|
* this.bar = Objects.requireNonEmpty(bar, "bar");
|
||||||
|
* }
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* </blockquote>
|
||||||
|
*
|
||||||
|
* @param <T> the type of the reference.
|
||||||
|
* @param obj the object reference to check for nullity.
|
||||||
|
* @param message the exception message.
|
||||||
|
* @return {@code obj} if not {@code null}.
|
||||||
|
* @throws NullPointerException if {@code obj} is {@code null}.
|
||||||
|
* @throws IllegalArgumentException if {@code obj} is empty per {@link #isEmpty(Object)}.
|
||||||
|
* @see #isEmpty(Object)
|
||||||
|
* @since 3.12.0
|
||||||
|
*/
|
||||||
|
public static <T> T requireNonEmpty(final T obj, final String message) {
|
||||||
|
// check for null first to give the most precise exception.
|
||||||
|
Objects.requireNonNull(obj, message);
|
||||||
|
if (isEmpty(obj)) {
|
||||||
|
throw new IllegalArgumentException(message);
|
||||||
|
}
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
// ToString
|
// ToString
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
/**
|
/**
|
||||||
|
@ -1210,7 +1269,6 @@ public static boolean notEqual(final Object object1, final Object object2) {
|
||||||
public static String toString(final Object obj) {
|
public static String toString(final Object obj) {
|
||||||
return obj == null ? StringUtils.EMPTY : obj.toString();
|
return obj == null ? StringUtils.EMPTY : obj.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>Gets the {@code toString} of an {@code Object} returning
|
* <p>Gets the {@code toString} of an {@code Object} returning
|
||||||
* a specified text if {@code null} input.</p>
|
* a specified text if {@code null} input.</p>
|
||||||
|
|
|
@ -441,7 +441,7 @@ public void testAnd_object_nullElementInput() {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAnd_object_nullInput() {
|
public void testAnd_object_nullInput() {
|
||||||
assertThrows(IllegalArgumentException.class, () -> BooleanUtils.and((Boolean[]) null));
|
assertThrows(NullPointerException.class, () -> BooleanUtils.and((Boolean[]) null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -553,7 +553,7 @@ public void testAnd_primitive_emptyInput() {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAnd_primitive_nullInput() {
|
public void testAnd_primitive_nullInput() {
|
||||||
assertThrows(IllegalArgumentException.class, () -> BooleanUtils.and((boolean[]) null));
|
assertThrows(NullPointerException.class, () -> BooleanUtils.and((boolean[]) null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -640,7 +640,7 @@ public void testOr_object_nullElementInput() {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOr_object_nullInput() {
|
public void testOr_object_nullInput() {
|
||||||
assertThrows(IllegalArgumentException.class, () -> BooleanUtils.or((Boolean[]) null));
|
assertThrows(NullPointerException.class, () -> BooleanUtils.or((Boolean[]) null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -752,7 +752,7 @@ public void testOr_primitive_emptyInput() {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOr_primitive_nullInput() {
|
public void testOr_primitive_nullInput() {
|
||||||
assertThrows(IllegalArgumentException.class, () -> BooleanUtils.or((boolean[]) null));
|
assertThrows(NullPointerException.class, () -> BooleanUtils.or((boolean[]) null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -822,7 +822,7 @@ public void testXor_object_nullElementInput() {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testXor_object_nullInput() {
|
public void testXor_object_nullInput() {
|
||||||
assertThrows(IllegalArgumentException.class, () -> BooleanUtils.xor((Boolean[]) null));
|
assertThrows(NullPointerException.class, () -> BooleanUtils.xor((Boolean[]) null));
|
||||||
}
|
}
|
||||||
@Test
|
@Test
|
||||||
public void testXor_object_validInput_2items() {
|
public void testXor_object_validInput_2items() {
|
||||||
|
@ -940,7 +940,7 @@ public void testXor_primitive_emptyInput() {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testXor_primitive_nullInput() {
|
public void testXor_primitive_nullInput() {
|
||||||
assertThrows(IllegalArgumentException.class, () -> BooleanUtils.xor((boolean[]) null));
|
assertThrows(NullPointerException.class, () -> BooleanUtils.xor((boolean[]) null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -740,10 +740,23 @@ public void testPossibleCloneOfNotCloneable() {
|
||||||
@Test
|
@Test
|
||||||
public void testPossibleCloneOfUncloneable() {
|
public void testPossibleCloneOfUncloneable() {
|
||||||
final UncloneableString string = new UncloneableString("apache");
|
final UncloneableString string = new UncloneableString("apache");
|
||||||
final CloneFailedException e = assertThrows(CloneFailedException.class, () -> ObjectUtils.cloneIfPossible(string));
|
final CloneFailedException e = assertThrows(CloneFailedException.class,
|
||||||
|
() -> ObjectUtils.cloneIfPossible(string));
|
||||||
assertEquals(NoSuchMethodException.class, e.getCause().getClass());
|
assertEquals(NoSuchMethodException.class, e.getCause().getClass());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRequireNonEmpty() {
|
||||||
|
assertEquals("foo", ObjectUtils.requireNonEmpty("foo"));
|
||||||
|
assertEquals("foo", ObjectUtils.requireNonEmpty("foo", "foo"));
|
||||||
|
//
|
||||||
|
assertThrows(NullPointerException.class, () -> ObjectUtils.requireNonEmpty(null));
|
||||||
|
assertThrows(NullPointerException.class, () -> ObjectUtils.requireNonEmpty(null, "foo"));
|
||||||
|
//
|
||||||
|
assertThrows(IllegalArgumentException.class, () -> ObjectUtils.requireNonEmpty(""));
|
||||||
|
assertThrows(IllegalArgumentException.class, () -> ObjectUtils.requireNonEmpty("", "foo"));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testToString_Object() {
|
public void testToString_Object() {
|
||||||
assertEquals("", ObjectUtils.toString(null) );
|
assertEquals("", ObjectUtils.toString(null) );
|
||||||
|
|
Loading…
Reference in New Issue