Add missing javadoc/tests for some null arguments (#869)
This commit is contained in:
parent
3da149382f
commit
680f9d5492
|
@ -3772,6 +3772,7 @@ public class ArrayUtils {
|
|||
* @param comparator the {@link Comparator} to compare over
|
||||
* @param <T> the datatype of the array
|
||||
* @return whether the array is sorted
|
||||
* @throws NullPointerException if {@code comparator} is {@code null}
|
||||
* @since 3.4
|
||||
*/
|
||||
public static <T> boolean isSorted(final T[] array, final Comparator<T> comparator) {
|
||||
|
|
|
@ -274,6 +274,7 @@ public class Range<T> implements Serializable {
|
|||
*
|
||||
* @param element the element to check for, not null
|
||||
* @return -1, 0 or +1 depending on the element's location relative to the range
|
||||
* @throws NullPointerException if {@code element} is {@code null}
|
||||
*/
|
||||
public int elementCompareTo(final T element) {
|
||||
// Comparable API says throw NPE on null
|
||||
|
@ -329,6 +330,7 @@ public class Range<T> implements Serializable {
|
|||
* </pre>
|
||||
* @param element the element to check for, not null
|
||||
* @return the minimum, the element, or the maximum depending on the element's location relative to the range
|
||||
* @throws NullPointerException if {@code element} is {@code null}
|
||||
* @since 3.10
|
||||
*/
|
||||
public T fit(final T element) {
|
||||
|
|
|
@ -907,6 +907,7 @@ public class ToStringBuilder implements Builder<String> {
|
|||
*
|
||||
* @param srcObject the {@link Object} whose class name and id to output
|
||||
* @return this
|
||||
* @throws NullPointerException if {@code srcObject} is {@code null}
|
||||
* @since 2.0
|
||||
*/
|
||||
public ToStringBuilder appendAsObjectToString(final Object srcObject) {
|
||||
|
|
|
@ -1543,6 +1543,7 @@ public class TypeUtils {
|
|||
* @param rawClass the raw class to create a parameterized type instance for
|
||||
* @param typeVariableMap the map used for parameterization
|
||||
* @return {@link ParameterizedType}
|
||||
* @throws NullPointerException if either {@code rawClass} or {@code typeVariableMap} is {@code null}
|
||||
* @since 3.2
|
||||
*/
|
||||
public static final ParameterizedType parameterize(final Class<?> rawClass,
|
||||
|
@ -1559,6 +1560,7 @@ public class TypeUtils {
|
|||
* @param rawClass the raw class to create a parameterized type instance for
|
||||
* @param typeArguments the types used for parameterization
|
||||
* @return {@link ParameterizedType}
|
||||
* @throws NullPointerException if {@code rawClass} is {@code null}
|
||||
* @since 3.2
|
||||
*/
|
||||
public static final ParameterizedType parameterize(final Class<?> rawClass, final Type... typeArguments) {
|
||||
|
@ -1607,6 +1609,8 @@ public class TypeUtils {
|
|||
* @param rawClass the raw class to create a parameterized type instance for
|
||||
* @param typeVariableMap the map used for parameterization
|
||||
* @return {@link ParameterizedType}
|
||||
* @throws NullPointerException if either {@code rawClass} or {@code typeVariableMap}
|
||||
* is {@code null}
|
||||
* @since 3.2
|
||||
*/
|
||||
public static final ParameterizedType parameterizeWithOwner(final Type owner, final Class<?> rawClass,
|
||||
|
@ -1625,6 +1629,7 @@ public class TypeUtils {
|
|||
* @param typeArguments the types used for parameterization
|
||||
*
|
||||
* @return {@link ParameterizedType}
|
||||
* @throws NullPointerException if {@code rawClass} is {@code null}
|
||||
* @since 3.2
|
||||
*/
|
||||
public static final ParameterizedType parameterizeWithOwner(final Type owner, final Class<?> rawClass,
|
||||
|
|
|
@ -609,6 +609,13 @@ public class ToStringBuilderTest extends AbstractLangTest {
|
|||
new ToStringBuilder(base).appendAsObjectToString(objectToAppend3).toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAppendAsObjectToStringNullPointerException() {
|
||||
ToStringBuilder builder = new ToStringBuilder(1);
|
||||
assertThrows(NullPointerException.class, () -> builder.appendAsObjectToString(null));
|
||||
builder.toString();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAppendBooleanArrayWithFieldName() {
|
||||
final boolean[] array = { true, false, false };
|
||||
|
|
|
@ -20,6 +20,7 @@ import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
|||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.awt.Insets;
|
||||
|
@ -947,6 +948,18 @@ public class TypeUtilsTest<B> extends AbstractLangTest {
|
|||
assertEquals(TypeUtils.parameterize(ArrayList.class, String.class), unrolled);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParameterizeNullPointerException() {
|
||||
assertThrows(NullPointerException.class, () -> TypeUtils.parameterize(null, Collections.emptyMap()));
|
||||
final Map<TypeVariable<?>, Type> nullTypeVariableMap = null;
|
||||
assertThrows(NullPointerException.class, () -> TypeUtils.parameterize(String.class, nullTypeVariableMap));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParameterizeVarArgsNullPointerException() {
|
||||
assertThrows(NullPointerException.class, () -> TypeUtils.parameterize(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParameterizeWithOwner() throws Exception {
|
||||
final Type owner = TypeUtils.parameterize(TypeUtilsTest.class, String.class);
|
||||
|
@ -954,6 +967,20 @@ public class TypeUtilsTest<B> extends AbstractLangTest {
|
|||
assertTrue(TypeUtils.equals(getClass().getField("dat2").getGenericType(), dat2Type));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParameterizeWithOwner3ArgsNullPointerException() {
|
||||
final Type owner = TypeUtils.parameterize(TypeUtilsTest.class, String.class);
|
||||
assertThrows(NullPointerException.class, () -> TypeUtils.parameterizeWithOwner(owner, null, String.class));
|
||||
final Map<TypeVariable<?>, Type> nullTypeVariableMap = null;
|
||||
assertThrows(NullPointerException.class, () -> TypeUtils.parameterizeWithOwner(owner, That.class, nullTypeVariableMap));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParameterizeWithOwnerVarArgsNullPointerException() {
|
||||
final Type owner = TypeUtils.parameterize(TypeUtilsTest.class, String.class);
|
||||
assertThrows(NullPointerException.class, () -> TypeUtils.parameterizeWithOwner(owner, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToLongString() {
|
||||
assertEquals(getClass().getName() + ":B", TypeUtils.toLongString(getClass().getTypeParameters()[0]));
|
||||
|
|
|
@ -143,6 +143,11 @@ public class DurationUtilsTest extends AbstractLangTest {
|
|||
assertEquals(Integer.MAX_VALUE, DurationUtils.toMillisInt(Duration.ofNanos(Long.MAX_VALUE)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToMillisIntNullDuration() {
|
||||
assertThrows(NullPointerException.class, () -> DurationUtils.toMillisInt(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testZeroIfNull() {
|
||||
assertEquals(Duration.ZERO, DurationUtils.zeroIfNull(null));
|
||||
|
|
Loading…
Reference in New Issue