diff --git a/src/changes/changes.xml b/src/changes/changes.xml index d3a52fe50..bc720f759 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -89,7 +89,7 @@ The type attribute can be add,update,fix,remove. EqualsBuilder.append(Object,Object) is too big to be inlined, which prevents whole builder to be scalarized NumberUtils.createNumber() behaves inconsistently with NumberUtils.isNumber() Add support for varargs in ConstructorUtils, MemberUtils, and MethodUtils - New methods for lang3.Validate + Add methods to check numbers against NaN and inifinite to Validate Fix for incorrect comment on StringUtils.containsIgnoreCase method Fix typo on appendIfMissing javadoc Add tests for missed branches in DateUtils diff --git a/src/main/java/org/apache/commons/lang3/Validate.java b/src/main/java/org/apache/commons/lang3/Validate.java index b70ddd5cf..da20da470 100644 --- a/src/main/java/org/apache/commons/lang3/Validate.java +++ b/src/main/java/org/apache/commons/lang3/Validate.java @@ -972,674 +972,6 @@ public static void finite(final double value, final String message, final Object } } - // greater - //--------------------------------------------------------------------------------- - - /** - *

Validates that the specified argument is strictly greater than a given - * reference; otherwise throwing an exception.

- * - *
Validate.greaterObject(myObject, refObject);
- * - *

The message of the exception is "The value {@code value} is not - * greater than {@code min}".

- * - * @param the type of the argument object - * @param value the object to validate - * @param min the reference value - * @throws IllegalArgumentException if {@code value} is smaller than or equal to {@code min} - * @see #greaterObject(java.lang.Object, java.lang.Comparable, java.lang.String, java.lang.Object...) - * - * @since 3.5 - */ - public static void greaterObject(final Comparable value, final T min) { - greaterObject(value, min, DEFAULT_GREATER_EX_MESSAGE, value, min); - } - - /** - *

Validates that the specified argument is strictly greater than a given - * reference; otherwise throwing an exception with the specified message.

- * - *
Validate.greaterObject(myObject, refObject, "The value must be greater than the reference");
- * - * @param the type of the argument object - * @param value the object to validate - * @param min the reference value - * @param message the {@link String#format(String, Object...)} exception message if invalid, not null - * @param values the optional values for the formatted exception message - * @throws IllegalArgumentException if {@code value} is smaller than or equal to {@code min} - * @see #greaterObject(java.lang.Object, java.lang.Comparable) - * - * @since 3.5 - */ - public static void greaterObject(final Comparable value, final T min, final String message, final Object... values) { - if (value.compareTo(min) <= 0) { - throw new IllegalArgumentException(String.format(message, values)); - } - } - - /** - *

Validates that the specified argument is strictly greater than a given - * reference; otherwise throwing an exception.

- * - *
Validate.greater(myLong, 0);
- * - *

The message of the exception is "The value {@code value} is not - * greater than {@code min}".

- * - * @param value the value to validate - * @param min the reference value - * @throws IllegalArgumentException if {@code value} is smaller than or equal to {@code min} - * @see #greater(long, long, java.lang.String, java.lang.Object...) - * - * @since 3.5 - */ - public static void greater(final long value, final long min) { - greater(value, min, DEFAULT_GREATER_EX_MESSAGE, value, min); - } - - /** - *

Validates that the specified argument is strictly greater than a given - * reference; otherwise throwing an exception with the specified message.

- * - *
Validate.greater(myLong, 0);
- * - * @param value the value to validate - * @param min the reference value - * @param message the {@link String#format(String, Object...)} exception message if invalid, not null - * @param values the optional values for the formatted exception message - * @throws IllegalArgumentException if {@code value} is smaller than or equal to {@code min} - * @see #greater(long, long) - * - * @since 3.5 - */ - public static void greater(final long value, final long min, final String message, final Object... values) { - if (value <= min) { - throw new IllegalArgumentException(String.format(message, values)); - } - } - - /** - *

Validates that the specified argument is strictly greater than a given - * reference; otherwise throwing an exception.

- * - *

If {@code min} or {@code value} is {@code NaN}, the test will fail and - * the exception will be thrown.

- * - *
Validate.greater(myDouble, 0.0);
- * - *

The message of the exception is "The value {@code value} is not - * greater than {@code min}".

- * - * @param value the value to validate - * @param min the reference value - * @throws IllegalArgumentException if {@code value} is smaller than or equal to {@code min} - * @see #greater(double, double, java.lang.String, java.lang.Object...) - * - * @since 3.5 - */ - public static void greater(final double value, final double min) { - greater(value, min, DEFAULT_GREATER_EX_MESSAGE, value, min); - } - - /** - *

Validates that the specified argument is strictly greater than a given - * reference; otherwise throwing an exception with the specified message.

- * - *

If {@code min} or {@code value} is {@code NaN}, the test will fail and - * the exception will be thrown.

- * - *
Validate.greater(myDouble, 0.0);
- * - * @param value the value to validate - * @param min the reference value - * @param message the {@link String#format(String, Object...)} exception message if invalid, not null - * @param values the optional values for the formatted exception message - * @throws IllegalArgumentException if {@code value} is smaller than or equal to {@code min} - * @see #greater(double, double) - * - * @since 3.5 - */ - public static void greater(final double value, final double min, final String message, final Object... values) { - if (!(value > min)) { - throw new IllegalArgumentException(String.format(message, values)); - } - } - - // greaterOrEqual - //--------------------------------------------------------------------------------- - - /** - *

Validates that the specified argument is greater than, or equal to, a - * given reference; otherwise throwing an exception.

- * - *
Validate.greaterOrEqualObject(myObject, refObject);
- * - *

The message of the exception is "The value {@code value} is not - * greater than or equal to {@code min}".

- * - * @param the type of the argument object - * @param value the object to validate - * @param min the reference value - * @throws IllegalArgumentException if {@code value} is smaller than {@code min} - * @see #greaterOrEqualObject(java.lang.Object, java.lang.Comparable, java.lang.String, java.lang.Object...) - * - * @since 3.5 - */ - public static void greaterOrEqualObject(final Comparable value, final T min) { - greaterOrEqualObject(value, min, DEFAULT_GREATER_OR_EQUAL_EX_MESSAGE, value, min); - } - - /** - *

Validates that the specified argument is greater than, or equal to, a - * given reference; otherwise throwing an exception.

- * - *
Validate.greaterOrEqualObject(myObject, refObject, "The value must be greater than the reference");
- * - * @param the type of the argument object - * @param value the object to validate - * @param min the reference value - * @param message the {@link String#format(String, Object...)} exception message if invalid, not null - * @param values the optional values for the formatted exception message - * @throws IllegalArgumentException if {@code value} is smaller than {@code min} - * @see #greaterOrEqualObject(java.lang.Object, java.lang.Comparable) - * - * @since 3.5 - */ - public static void greaterOrEqualObject(final Comparable value, final T min, final String message, final Object... values) { - if (value.compareTo(min) < 0) { - throw new IllegalArgumentException(String.format(message, values)); - } - } - - /** - *

Validates that the specified argument is greater than, or equal to, a - * given reference; otherwise throwing an exception.

- * - *
Validate.greaterOrEqual(myLong, 0);
- * - *

The message of the exception is "The value {@code value} is not - * greater than or equal to {@code min}".

- * - * @param value the value to validate - * @param min the reference value - * @throws IllegalArgumentException if {@code value} is smaller than {@code min} - * @see #greaterOrEqual(long, long, java.lang.String, java.lang.Object...) - * - * @since 3.5 - */ - public static void greaterOrEqual(final long value, final long min) { - greaterOrEqual(value, min, DEFAULT_GREATER_OR_EQUAL_EX_MESSAGE, value, min); - } - - /** - *

Validates that the specified argument is greater than, or equal to, a - * given reference; otherwise throwing an exception with the specified message.

- * - *
Validate.greaterOrEqual(myLong, 0);
- * - * @param value the value to validate - * @param min the reference value - * @param message the {@link String#format(String, Object...)} exception message if invalid, not null - * @param values the optional values for the formatted exception message - * @throws IllegalArgumentException if {@code value} is smaller than {@code min} - * @see #greaterOrEqual(long, long) - * - * @since 3.5 - */ - public static void greaterOrEqual(final long value, final long min, final String message, final Object... values) { - if (value < min) { - throw new IllegalArgumentException(String.format(message, values)); - } - } - - /** - *

Validates that the specified argument is greater than, or equal to, a - * given reference; otherwise throwing an exception.

- * - *

If {@code min} or {@code value} is {@code NaN}, the test will fail and - * the exception will be thrown.

- * - *
Validate.greaterOrEqual(myDouble, 0.0);
- * - *

The message of the exception is "The value {@code value} is not - * greater than or equal to {@code min}".

- * - * @param value the value to validate - * @param min the reference value - * @throws IllegalArgumentException if {@code value} is smaller than {@code min} - * @see #greaterOrEqual(double, double, java.lang.String, java.lang.Object...) - * - * @since 3.5 - */ - public static void greaterOrEqual(final double value, final double min) { - greaterOrEqual(value, min, DEFAULT_GREATER_OR_EQUAL_EX_MESSAGE, value, min); - } - - /** - *

Validates that the specified argument is greater than, or equal to, a - * given reference; otherwise throwing an exception with the specified message.

- * - *

If {@code min} or {@code value} is {@code NaN}, the test will fail and - * the exception will be thrown.

- * - *
Validate.greaterOrEqual(myDouble, 0.0);
- * - * @param value the value to validate - * @param min the reference value - * @param message the {@link String#format(String, Object...)} exception message if invalid, not null - * @param values the optional values for the formatted exception message - * @throws IllegalArgumentException if {@code value} is smaller than {@code min} - * @see #greaterOrEqual(double, double) - * - * @since 3.5 - */ - public static void greaterOrEqual(final double value, final double min, final String message, final Object... values) { - if (!(value >= min)) { - throw new IllegalArgumentException(String.format(message, values)); - } - } - - // smaller - //--------------------------------------------------------------------------------- - - /** - *

Validates that the specified argument is strictly smaller than a given - * reference; otherwise throwing an exception.

- * - *
Validate.smallerObject(myObject, refObject);
- * - *

The message of the exception is "The value {@code value} is not - * smaller than {@code max}".

- * - * @param the type of the argument object - * @param value the object to validate - * @param max the reference value - * @throws IllegalArgumentException if {@code value} is greater than or equal to {@code max} - * @see #smallerObject(java.lang.Object, java.lang.Comparable, java.lang.String, java.lang.Object...) - * - * @since 3.5 - */ - public static void smallerObject(final Comparable value, final T max) { - smallerObject(value, max, DEFAULT_SMALLER_EX_MESSAGE, value, max); - } - - /** - *

Validates that the specified argument is strictly smaller than a given - * reference; otherwise throwing an exception with the specified message.

- * - *
Validate.smallerObject(myObject, refObject, "The value must be greater than the reference");
- * - * @param the type of the argument object - * @param value the object to validate - * @param max the reference value - * @param message the {@link String#format(String, Object...)} exception message if invalid, not null - * @param values the optional values for the formatted exception message - * @throws IllegalArgumentException if {@code value} is greater than or equal to {@code max} - * @see #smallerObject(java.lang.Object, java.lang.Comparable) - * - * @since 3.5 - */ - public static void smallerObject(final Comparable value, final T max, final String message, final Object... values) { - if (value.compareTo(max) >= 0) { - throw new IllegalArgumentException(String.format(message, values)); - } - } - - /** - *

Validates that the specified argument is strictly smaller than a given - * reference; otherwise throwing an exception.

- * - *
Validate.smaller(myLong, 0);
- * - *

The message of the exception is "The value {@code value} is not - * smaller than {@code max}".

- * - * @param value the value to validate - * @param max the reference value - * @throws IllegalArgumentException if {@code value} is greater than or equal to {@code max} - * @see #smaller(long, long, java.lang.String, java.lang.Object...) - * - * @since 3.5 - */ - public static void smaller(final long value, final long max) { - smaller(value, max, DEFAULT_SMALLER_EX_MESSAGE, value, max); - } - - /** - *

Validates that the specified argument is strictly smaller than a given - * reference; otherwise throwing an exception with the specified message.

- * - *
Validate.smaller(myLong, 0);
- * - * @param value the value to validate - * @param max the reference value - * @param message the {@link String#format(String, Object...)} exception message if invalid, not null - * @param values the optional values for the formatted exception message - * @throws IllegalArgumentException if {@code value} is greater than or equal to {@code max} - * @see #smaller(long, long) - * - * @since 3.5 - */ - public static void smaller(final long value, final long max, final String message, final Object... values) { - if (value >= max) { - throw new IllegalArgumentException(String.format(message, values)); - } - } - - /** - *

Validates that the specified argument is strictly smaller than a given - * reference; otherwise throwing an exception.

- * - *

If {@code min} or {@code value} is {@code NaN}, the test will fail and - * the exception will be thrown.

- * - *
Validate.smaller(myDouble, 0.0);
- * - *

The message of the exception is "The value {@code value} is not - * smaller than {@code max}".

- * - * @param value the value to validate - * @param max the reference value - * @throws IllegalArgumentException if {@code value} is greater than or equal to {@code max} - * @see #smaller(double, double, java.lang.String, java.lang.Object...) - * - * @since 3.5 - */ - public static void smaller(final double value, final double max) { - smaller(value, max, DEFAULT_SMALLER_EX_MESSAGE, value, max); - } - - /** - *

Validates that the specified argument is strictly smaller than a given - * reference; otherwise throwing an exception with the specified message.

- * - *

If {@code min} or {@code value} is {@code NaN}, the test will fail and - * the exception will be thrown.

- * - *
Validate.smaller(myDouble, 0.0);
- * - * @param value the value to validate - * @param max the reference value - * @param message the {@link String#format(String, Object...)} exception message if invalid, not null - * @param values the optional values for the formatted exception message - * @throws IllegalArgumentException if {@code value} is greater than or equal to {@code max} - * @see #smaller(double, double) - * - * @since 3.5 - */ - public static void smaller(final double value, final double max, final String message, final Object... values) { - if (!(value < max)) { - throw new IllegalArgumentException(String.format(message, values)); - } - } - - // smallerOrEqual - //--------------------------------------------------------------------------------- - - /** - *

Validates that the specified argument is smaller than, or equal to, a - * given reference; otherwise throwing an exception.

- * - *
Validate.smallerOrEqualObject(myObject, refObject);
- * - *

The message of the exception is "The value {@code value} is not - * smaller than or equal to {@code max}".

- * - * @param the type of the argument object - * @param value the object to validate - * @param max the reference value - * @throws IllegalArgumentException if {@code value} is greater than {@code max} - * @see #smallerOrEqualObject(java.lang.Object, java.lang.Comparable, java.lang.String, java.lang.Object...) - * - * @since 3.5 - */ - public static void smallerOrEqualObject(final Comparable value, final T max) { - smallerOrEqualObject(value, max, DEFAULT_SMALLER_OR_EQUAL_EX_MESSAGE, value, max); - } - - /** - *

Validates that the specified argument is smaller than, or equal to, a - * given reference; otherwise throwing an exception with the specified message.

- * - *
Validate.smallerOrEqualObject(myObject, refObject, "The value must be greater than the reference");
- * - * @param the type of the argument object - * @param value the object to validate - * @param max the reference value - * @param message the {@link String#format(String, Object...)} exception message if invalid, not null - * @param values the optional values for the formatted exception message - * @throws IllegalArgumentException if {@code value} is greater than {@code max} - * @see #smallerOrEqualObject(java.lang.Object, java.lang.Comparable) - * - * @since 3.5 - */ - public static void smallerOrEqualObject(final Comparable value, final T max, final String message, final Object... values) { - if (value.compareTo(max) > 0) { - throw new IllegalArgumentException(String.format(message, values)); - } - } - - /** - *

Validates that the specified argument is smaller than, or equal to, a - * given reference; otherwise throwing an exception.

- * - *
Validate.smallerOrEqual(myLong, 0);
- * - *

The message of the exception is "The value {@code value} is not - * smaller than or equal to {@code max}".

- * - * @param value the value to validate - * @param max the reference value - * @throws IllegalArgumentException if {@code value} is greater than {@code max} - * @see #smallerOrEqual(long, long, java.lang.String, java.lang.Object...) - * - * @since 3.5 - */ - public static void smallerOrEqual(final long value, final long max) { - smallerOrEqual(value, max, DEFAULT_SMALLER_OR_EQUAL_EX_MESSAGE, value, max); - } - - /** - *

Validates that the specified argument is smaller than, or equal to, a - * given reference; otherwise throwing an exception with the specified message.

- * - *
Validate.smallerOrEqual(myLong, 0);
- * - * @param value the value to validate - * @param max the reference value - * @param message the {@link String#format(String, Object...)} exception message if invalid, not null - * @param values the optional values for the formatted exception message - * @throws IllegalArgumentException if {@code value} is greater than {@code max} - * @see #smallerOrEqual(long, long) - * - * @since 3.5 - */ - public static void smallerOrEqual(final long value, final long max, final String message, final Object... values) { - if (value > max) { - throw new IllegalArgumentException(String.format(message, values)); - } - } - - /** - *

Validates that the specified argument is smaller than, or equal to, a - * given reference; otherwise throwing an exception.

- * - *

If {@code min} or {@code value} is {@code NaN}, the test will fail and - * the exception will be thrown.

- * - *
Validate.smallerOrEqual(myDouble, 0.0);
- * - *

The message of the exception is "The value {@code value} is not - * smaller than or equal to {@code max}".

- * - * @param value the value to validate - * @param max the reference value - * @throws IllegalArgumentException if {@code value} is greater than {@code max} - * @see #smallerOrEqual(double, double, java.lang.String, java.lang.Object...) - * - * @since 3.5 - */ - public static void smallerOrEqual(final double value, final double max) { - smallerOrEqual(value, max, DEFAULT_SMALLER_OR_EQUAL_EX_MESSAGE, value, max); - } - - /** - *

Validates that the specified argument is smaller than, or equal to, a - * given reference; otherwise throwing an exception with the specified message.

- * - *

If {@code min} or {@code value} is {@code NaN}, the test will fail and - * the exception will be thrown.

- * - *
Validate.smallerOrEqual(myDouble, 0.0);
- * - * @param value the value to validate - * @param max the reference value - * @param message the {@link String#format(String, Object...)} exception message if invalid, not null - * @param values the optional values for the formatted exception message - * @throws IllegalArgumentException if {@code value} is greater than {@code max} - * @see #smallerOrEqual(double, double) - * - * @since 3.5 - */ - public static void smallerOrEqual(final double value, final double max, final String message, final Object... values) { - if (!(value <= max)) { - throw new IllegalArgumentException(String.format(message, values)); - } - } - - // different - //--------------------------------------------------------------------------------- - - /** - *

Validates that the specified argument is different from a given value - * (reference); otherwise throwing an exception.

- * - *

Two objects are considered different if - * {@code value.equals(reference) == false}

- * - *
Validate.differentObject(myObject, refObject);
- * - *

The message of the exception is "The value {@code value} is - * invalid".

- * - * @param the type of the argument object - * @param value the object to validate - * @param reference the reference value - * @throws IllegalArgumentException if {@code value} is equal to {@code reference} - * - * @since 3.5 - */ - public static void differentObject(final T value, final T reference) { - differentObject(value, reference, DEFAULT_DIFFERENT_EX_MESSAGE, value); - } - - /** - *

Validates that the specified argument is different from a given value - * (reference); otherwise throwing an exception with the specified message.

- * - *

Two objects are considered different if - * {@code value.equals(reference) == false}

- * - *
Validate.differentObject(myObject, refObject, "The value is invalid");
- * - * @param the type of the argument object - * @param value the object to validate - * @param reference the reference value - * @param message the {@link String#format(String, Object...)} exception message if invalid, not null - * @param values the optional values for the formatted exception message - * @throws IllegalArgumentException if {@code value} is equal to {@code reference} - * - * @since 3.5 - */ - public static void differentObject(final T value, final T reference, final String message, final Object... values) { - if (value.equals(reference)) { - throw new IllegalArgumentException(String.format(message, values)); - } - } - - /** - *

Validates that the specified argument is not equal to a given value - * (reference); otherwise throwing an exception.

- * - *
Validate.different(myLong, 0);
- * - *

The message of the exception is "The value {@code value} is - * invalid".

- * - * @param value the value to validate - * @param reference the reference value - * @throws IllegalArgumentException if {@code value} is equal to {@code reference} - * - * @since 3.5 - */ - public static void different(final long value, final long reference) { - different(value, reference, DEFAULT_DIFFERENT_EX_MESSAGE, value); - } - - /** - *

Validates that the specified argument is not equal to a given value - * (reference); otherwise throwing an exception with the specified message.

- * - *
Validate.different(myLong, 0, "The value is invalid");
- * - * @param value the value to validate - * @param reference the reference value - * @param message the {@link String#format(String, Object...)} exception message if invalid, not null - * @param values the optional values for the formatted exception message - * @throws IllegalArgumentException if {@code value} is equal to {@code reference} - * - * @since 3.5 - */ - public static void different(final long value, final long reference, final String message, final Object... values) { - if (value == reference) { - throw new IllegalArgumentException(String.format(message, values)); - } - } - - /** - *

Validates that the specified argument is not equal to a given value - * (reference); otherwise throwing an exception.

- * - *

If {@code value} or {@code reference} is {@code NaN}, no exception will be thrown.

- * - *
Validate.different(myDouble, 0.0);
- * - *

The message of the exception is "The value {@code value} is - * invalid".

- * - * @param value the value to validate - * @param reference the reference value - * @throws IllegalArgumentException if {@code value} is equal to {@code reference} - * - * @since 3.5 - */ - public static void different(final double value, final double reference) { - different(value, reference, DEFAULT_DIFFERENT_EX_MESSAGE, value); - } - - /** - *

Validates that the specified argument is not equal to a given value - * (reference); otherwise throwing an exception with the specified message.

- * - *

If {@code value} or {@code reference} is {@code NaN}, no exception will be thrown.

- * - *
Validate.different(myDouble, 0.0, "The value is invalid");
- * - * @param value the value to validate - * @param reference the reference value - * @param message the {@link String#format(String, Object...)} exception message if invalid, not null - * @param values the optional values for the formatted exception message - * @throws IllegalArgumentException if {@code value} is equal to {@code reference} - * - * @since 3.5 - */ - public static void different(final double value, final double reference, final String message, final Object... values) { - if (value == reference) { - throw new IllegalArgumentException(String.format(message, values)); - } - } - // inclusiveBetween //--------------------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/lang3/ValidateTest.java b/src/test/java/org/apache/commons/lang3/ValidateTest.java index bb294bb44..cd84ec33a 100644 --- a/src/test/java/org/apache/commons/lang3/ValidateTest.java +++ b/src/test/java/org/apache/commons/lang3/ValidateTest.java @@ -912,618 +912,6 @@ public void testFinite2() { //----------------------------------------------------------------------- //----------------------------------------------------------------------- - @Test - public void testGreaterObject1() { - Validate.greaterObject("c", "b"); - try { - Validate.greaterObject("b", "b"); - fail("Expecting IllegalArgumentException"); - } catch (final IllegalArgumentException ex) { - assertEquals("The value b is not greater than b", ex.getMessage()); - } - try { - Validate.greaterObject("a", "b"); - fail("Expecting IllegalArgumentException"); - } catch (final IllegalArgumentException ex) { - assertEquals("The value a is not greater than b", ex.getMessage()); - } - } - - @Test - public void testGreaterObject2() { - Validate.greaterObject("c", "b", "MSG"); - try { - Validate.greaterObject("b", "b", "MSG"); - fail("Expecting IllegalArgumentException"); - } catch (final IllegalArgumentException ex) { - assertEquals("MSG", ex.getMessage()); - } - try { - Validate.greaterObject("a", "b", "MSG"); - fail("Expecting IllegalArgumentException"); - } catch (final IllegalArgumentException ex) { - assertEquals("MSG", ex.getMessage()); - } - } - - @Test - public void testGreaterLong1() { - Validate.greater(1, 0); - try { - Validate.greater(0, 0); - fail("Expecting IllegalArgumentException"); - } catch (final IllegalArgumentException ex) { - assertEquals("The value 0 is not greater than 0", ex.getMessage()); - } - try { - Validate.greater(-1, 0); - fail("Expecting IllegalArgumentException"); - } catch (final IllegalArgumentException ex) { - assertEquals("The value -1 is not greater than 0", ex.getMessage()); - } - } - - @Test - public void testGreaterLong2() { - Validate.greater(1, 0, "MSG"); - try { - Validate.greater(0, 0, "MSG"); - fail("Expecting IllegalArgumentException"); - } catch (final IllegalArgumentException ex) { - assertEquals("MSG", ex.getMessage()); - } - try { - Validate.greater(-1, 0, "MSG"); - fail("Expecting IllegalArgumentException"); - } catch (final IllegalArgumentException ex) { - assertEquals("MSG", ex.getMessage()); - } - } - - @Test - public void testGreaterDouble1() { - Validate.greater(1.0, 0.0); - Validate.greater(Double.POSITIVE_INFINITY, 0.0); - try { - Validate.greater(0.0, 0.0); - fail("Expecting IllegalArgumentException"); - } catch (final IllegalArgumentException ex) { - assertEquals("The value 0.0 is not greater than 0.0", ex.getMessage()); - } - try { - Validate.greater(-1.0, 0.0); - fail("Expecting IllegalArgumentException"); - } catch (final IllegalArgumentException ex) { - assertEquals("The value -1.0 is not greater than 0.0", ex.getMessage()); - } - try { - Validate.greater(Double.NEGATIVE_INFINITY, 0.0); - fail("Expecting IllegalArgumentException"); - } catch (final IllegalArgumentException ex) { - assertEquals("The value -Infinity is not greater than 0.0", ex.getMessage()); - } - try { - Validate.greater(Double.NaN, 0.0); - fail("Expecting IllegalArgumentException"); - } catch (final IllegalArgumentException ex) { - assertEquals("The value NaN is not greater than 0.0", ex.getMessage()); - } - try { - Validate.greater(0.0, Double.NaN); - fail("Expecting IllegalArgumentException"); - } catch (final IllegalArgumentException ex) { - assertEquals("The value 0.0 is not greater than NaN", ex.getMessage()); - } - } - - @Test - public void testGreaterDouble2() { - Validate.greater(1.0, 0.0, "MSG"); - Validate.greater(Double.POSITIVE_INFINITY, 0.0, "MSG"); - try { - Validate.greater(0.0, 0.0, "MSG"); - fail("Expecting IllegalArgumentException"); - } catch (final IllegalArgumentException ex) { - assertEquals("MSG", ex.getMessage()); - } - try { - Validate.greater(-1.0, 0.0, "MSG"); - fail("Expecting IllegalArgumentException"); - } catch (final IllegalArgumentException ex) { - assertEquals("MSG", ex.getMessage()); - } - try { - Validate.greater(Double.NEGATIVE_INFINITY, 0.0, "MSG"); - fail("Expecting IllegalArgumentException"); - } catch (final IllegalArgumentException ex) { - assertEquals("MSG", ex.getMessage()); - } - try { - Validate.greater(Double.NaN, 0.0, "MSG"); - fail("Expecting IllegalArgumentException"); - } catch (final IllegalArgumentException ex) { - assertEquals("MSG", ex.getMessage()); - } - try { - Validate.greater(0.0, Double.NaN, "MSG"); - fail("Expecting IllegalArgumentException"); - } catch (final IllegalArgumentException ex) { - assertEquals("MSG", ex.getMessage()); - } - } - - //----------------------------------------------------------------------- - //----------------------------------------------------------------------- - - @Test - public void testGreaterOrEqualObject1() { - Validate.greaterOrEqualObject("c", "b"); - Validate.greaterOrEqualObject("b", "b"); - try { - Validate.greaterOrEqualObject("a", "b"); - fail("Expecting IllegalArgumentException"); - } catch (final IllegalArgumentException ex) { - assertEquals("The value a is not greater than or equal to b", ex.getMessage()); - } - } - - @Test - public void testGreaterOrEqualObject2() { - Validate.greaterOrEqualObject("c", "b", "MSG"); - Validate.greaterOrEqualObject("b", "b", "MSG"); - try { - Validate.greaterOrEqualObject("a", "b", "MSG"); - fail("Expecting IllegalArgumentException"); - } catch (final IllegalArgumentException ex) { - assertEquals("MSG", ex.getMessage()); - } - } - - @Test - public void testGreaterOrEqualLong1() { - Validate.greaterOrEqual(1, 0); - Validate.greaterOrEqual(0, 0); - try { - Validate.greaterOrEqual(-1, 0); - fail("Expecting IllegalArgumentException"); - } catch (final IllegalArgumentException ex) { - assertEquals("The value -1 is not greater than or equal to 0", ex.getMessage()); - } - } - - @Test - public void testGreaterOrEqualLong2() { - Validate.greaterOrEqual(1, 0, "MSG"); - Validate.greaterOrEqual(0, 0, "MSG"); - try { - Validate.greaterOrEqual(-1, 0, "MSG"); - fail("Expecting IllegalArgumentException"); - } catch (final IllegalArgumentException ex) { - assertEquals("MSG", ex.getMessage()); - } - } - - @Test - public void testGreaterOrEqualDouble1() { - Validate.greaterOrEqual(1.0, 0.0); - Validate.greaterOrEqual(Double.POSITIVE_INFINITY, 0.0); - Validate.greaterOrEqual(0.0, 0.0); - try { - Validate.greaterOrEqual(-1.0, 0.0); - fail("Expecting IllegalArgumentException"); - } catch (final IllegalArgumentException ex) { - assertEquals("The value -1.0 is not greater than or equal to 0.0", ex.getMessage()); - } - try { - Validate.greaterOrEqual(Double.NEGATIVE_INFINITY, 0.0); - fail("Expecting IllegalArgumentException"); - } catch (final IllegalArgumentException ex) { - assertEquals("The value -Infinity is not greater than or equal to 0.0", ex.getMessage()); - } - try { - Validate.greaterOrEqual(Double.NaN, 0.0); - fail("Expecting IllegalArgumentException"); - } catch (final IllegalArgumentException ex) { - assertEquals("The value NaN is not greater than or equal to 0.0", ex.getMessage()); - } - try { - Validate.greaterOrEqual(0.0, Double.NaN); - fail("Expecting IllegalArgumentException"); - } catch (final IllegalArgumentException ex) { - assertEquals("The value 0.0 is not greater than or equal to NaN", ex.getMessage()); - } - try { - Validate.greaterOrEqual(Double.NaN, Double.NaN); - fail("Expecting IllegalArgumentException"); - } catch (final IllegalArgumentException ex) { - assertEquals("The value NaN is not greater than or equal to NaN", ex.getMessage()); - } - } - - @Test - public void testGreaterOrEqualDouble2() { - Validate.greaterOrEqual(1.0, 0.0, "MSG"); - Validate.greaterOrEqual(Double.POSITIVE_INFINITY, 0.0, "MSG"); - Validate.greaterOrEqual(0.0, 0.0, "MSG"); - - try { - Validate.greaterOrEqual(-1.0, 0.0, "MSG"); - fail("Expecting IllegalArgumentException"); - } catch (final IllegalArgumentException ex) { - assertEquals("MSG", ex.getMessage()); - } - try { - Validate.greaterOrEqual(Double.NEGATIVE_INFINITY, 0.0, "MSG"); - fail("Expecting IllegalArgumentException"); - } catch (final IllegalArgumentException ex) { - assertEquals("MSG", ex.getMessage()); - } - try { - Validate.greaterOrEqual(Double.NaN, 0.0, "MSG"); - fail("Expecting IllegalArgumentException"); - } catch (final IllegalArgumentException ex) { - assertEquals("MSG", ex.getMessage()); - } - try { - Validate.greaterOrEqual(0.0, Double.NaN, "MSG"); - fail("Expecting IllegalArgumentException"); - } catch (final IllegalArgumentException ex) { - assertEquals("MSG", ex.getMessage()); - } - try { - Validate.greaterOrEqual(Double.NaN, Double.NaN, "MSG"); - fail("Expecting IllegalArgumentException"); - } catch (final IllegalArgumentException ex) { - assertEquals("MSG", ex.getMessage()); - } - } - - //----------------------------------------------------------------------- - //----------------------------------------------------------------------- - - @Test - public void testSmallerObject1() { - Validate.smallerObject("a", "b"); - try { - Validate.smallerObject("b", "b"); - fail("Expecting IllegalArgumentException"); - } catch (final IllegalArgumentException ex) { - assertEquals("The value b is not smaller than b", ex.getMessage()); - } - try { - Validate.smallerObject("c", "b"); - fail("Expecting IllegalArgumentException"); - } catch (final IllegalArgumentException ex) { - assertEquals("The value c is not smaller than b", ex.getMessage()); - } - } - - @Test - public void testSmallerObject2() { - Validate.smallerObject("a", "b", "MSG"); - try { - Validate.smallerObject("b", "b", "MSG"); - fail("Expecting IllegalArgumentException"); - } catch (final IllegalArgumentException ex) { - assertEquals("MSG", ex.getMessage()); - } - try { - Validate.smallerObject("c", "b", "MSG"); - fail("Expecting IllegalArgumentException"); - } catch (final IllegalArgumentException ex) { - assertEquals("MSG", ex.getMessage()); - } - } - - @Test - public void testSmallerLong1() { - Validate.smaller(-1, 0); - try { - Validate.smaller(0, 0); - fail("Expecting IllegalArgumentException"); - } catch (final IllegalArgumentException ex) { - assertEquals("The value 0 is not smaller than 0", ex.getMessage()); - } - try { - Validate.smaller(1, 0); - fail("Expecting IllegalArgumentException"); - } catch (final IllegalArgumentException ex) { - assertEquals("The value 1 is not smaller than 0", ex.getMessage()); - } - } - - @Test - public void testSmallerLong2() { - Validate.smaller(-1, 0, "MSG"); - try { - Validate.smaller(0, 0, "MSG"); - fail("Expecting IllegalArgumentException"); - } catch (final IllegalArgumentException ex) { - assertEquals("MSG", ex.getMessage()); - } - try { - Validate.smaller(1, 0, "MSG"); - fail("Expecting IllegalArgumentException"); - } catch (final IllegalArgumentException ex) { - assertEquals("MSG", ex.getMessage()); - } - } - - @Test - public void testSmallerDouble1() { - Validate.smaller(-1.0, 0.0); - Validate.smaller(Double.NEGATIVE_INFINITY, 0.0); - try { - Validate.smaller(0.0, 0.0); - fail("Expecting IllegalArgumentException"); - } catch (final IllegalArgumentException ex) { - assertEquals("The value 0.0 is not smaller than 0.0", ex.getMessage()); - } - try { - Validate.smaller(1.0, 0.0); - fail("Expecting IllegalArgumentException"); - } catch (final IllegalArgumentException ex) { - assertEquals("The value 1.0 is not smaller than 0.0", ex.getMessage()); - } - try { - Validate.smaller(Double.POSITIVE_INFINITY, 0.0); - fail("Expecting IllegalArgumentException"); - } catch (final IllegalArgumentException ex) { - assertEquals("The value Infinity is not smaller than 0.0", ex.getMessage()); - } - try { - Validate.smaller(Double.NaN, 0.0); - fail("Expecting IllegalArgumentException"); - } catch (final IllegalArgumentException ex) { - assertEquals("The value NaN is not smaller than 0.0", ex.getMessage()); - } - try { - Validate.smaller(0.0, Double.NaN); - fail("Expecting IllegalArgumentException"); - } catch (final IllegalArgumentException ex) { - assertEquals("The value 0.0 is not smaller than NaN", ex.getMessage()); - } - } - - @Test - public void testSmallerDouble2() { - Validate.smaller(-1.0, 0.0, "MSG"); - Validate.smaller(Double.NEGATIVE_INFINITY, 0.0, "MSG"); - try { - Validate.smaller(0.0, 0.0, "MSG"); - fail("Expecting IllegalArgumentException"); - } catch (final IllegalArgumentException ex) { - assertEquals("MSG", ex.getMessage()); - } - try { - Validate.smaller(1.0, 0.0, "MSG"); - fail("Expecting IllegalArgumentException"); - } catch (final IllegalArgumentException ex) { - assertEquals("MSG", ex.getMessage()); - } - try { - Validate.smaller(Double.POSITIVE_INFINITY, 0.0, "MSG"); - fail("Expecting IllegalArgumentException"); - } catch (final IllegalArgumentException ex) { - assertEquals("MSG", ex.getMessage()); - } - try { - Validate.smaller(Double.NaN, 0.0, "MSG"); - fail("Expecting IllegalArgumentException"); - } catch (final IllegalArgumentException ex) { - assertEquals("MSG", ex.getMessage()); - } - try { - Validate.smaller(0.0, Double.NaN, "MSG"); - fail("Expecting IllegalArgumentException"); - } catch (final IllegalArgumentException ex) { - assertEquals("MSG", ex.getMessage()); - } - } - - //----------------------------------------------------------------------- - //----------------------------------------------------------------------- - - @Test - public void testSmallerOrEqualObject1() { - Validate.smallerOrEqualObject("a", "b"); - Validate.smallerOrEqualObject("b", "b"); - try { - Validate.smallerOrEqualObject("c", "b"); - fail("Expecting IllegalArgumentException"); - } catch (final IllegalArgumentException ex) { - assertEquals("The value c is not smaller than or equal to b", ex.getMessage()); - } - } - - @Test - public void testSmallerOrEqualObject2() { - Validate.smallerOrEqualObject("a", "b", "MSG"); - Validate.smallerOrEqualObject("b", "b", "MSG"); - try { - Validate.smallerOrEqualObject("c", "b", "MSG"); - fail("Expecting IllegalArgumentException"); - } catch (final IllegalArgumentException ex) { - assertEquals("MSG", ex.getMessage()); - } - } - - @Test - public void testSmallerOrEqualLong1() { - Validate.smallerOrEqual(-1, 0); - Validate.smallerOrEqual(0, 0); - try { - Validate.smallerOrEqual(1, 0); - fail("Expecting IllegalArgumentException"); - } catch (final IllegalArgumentException ex) { - assertEquals("The value 1 is not smaller than or equal to 0", ex.getMessage()); - } - } - - @Test - public void testSmallerOrEqualLong2() { - Validate.smallerOrEqual(-1, 0, "MSG"); - Validate.smallerOrEqual(0, 0, "MSG"); - try { - Validate.smallerOrEqual(1, 0, "MSG"); - fail("Expecting IllegalArgumentException"); - } catch (final IllegalArgumentException ex) { - assertEquals("MSG", ex.getMessage()); - } - } - - @Test - public void testSmallerOrEqualDouble1() { - Validate.smallerOrEqual(-1.0, 0.0); - Validate.smallerOrEqual(Double.NEGATIVE_INFINITY, 0.0); - Validate.smallerOrEqual(0.0, 0.0); - try { - Validate.smallerOrEqual(1.0, 0.0); - fail("Expecting IllegalArgumentException"); - } catch (final IllegalArgumentException ex) { - assertEquals("The value 1.0 is not smaller than or equal to 0.0", ex.getMessage()); - } - try { - Validate.smallerOrEqual(Double.POSITIVE_INFINITY, 0.0); - fail("Expecting IllegalArgumentException"); - } catch (final IllegalArgumentException ex) { - assertEquals("The value Infinity is not smaller than or equal to 0.0", ex.getMessage()); - } - try { - Validate.smallerOrEqual(Double.NaN, 0.0); - fail("Expecting IllegalArgumentException"); - } catch (final IllegalArgumentException ex) { - assertEquals("The value NaN is not smaller than or equal to 0.0", ex.getMessage()); - } - try { - Validate.smallerOrEqual(0.0, Double.NaN); - fail("Expecting IllegalArgumentException"); - } catch (final IllegalArgumentException ex) { - assertEquals("The value 0.0 is not smaller than or equal to NaN", ex.getMessage()); - } - } - - @Test - public void testSmallerOrEqualDouble2() { - Validate.smallerOrEqual(-1.0, 0.0, "MSG"); - Validate.smallerOrEqual(Double.NEGATIVE_INFINITY, 0.0, "MSG"); - Validate.smallerOrEqual(0.0, 0.0, "MSG"); - try { - Validate.smallerOrEqual(1.0, 0.0, "MSG"); - fail("Expecting IllegalArgumentException"); - } catch (final IllegalArgumentException ex) { - assertEquals("MSG", ex.getMessage()); - } - try { - Validate.smallerOrEqual(Double.POSITIVE_INFINITY, 0.0, "MSG"); - fail("Expecting IllegalArgumentException"); - } catch (final IllegalArgumentException ex) { - assertEquals("MSG", ex.getMessage()); - } - try { - Validate.smallerOrEqual(Double.NaN, 0.0, "MSG"); - fail("Expecting IllegalArgumentException"); - } catch (final IllegalArgumentException ex) { - assertEquals("MSG", ex.getMessage()); - } - try { - Validate.smallerOrEqual(0.0, Double.NaN, "MSG"); - fail("Expecting IllegalArgumentException"); - } catch (final IllegalArgumentException ex) { - assertEquals("MSG", ex.getMessage()); - } - } - - //----------------------------------------------------------------------- - //----------------------------------------------------------------------- - - @Test - public void testDifferentObject1() { - Validate.differentObject("b", "a"); - try { - Validate.differentObject("a", "a"); - fail("Expecting IllegalArgumentException"); - } catch (final IllegalArgumentException ex) { - assertEquals("The value a is invalid", ex.getMessage()); - } - } - - @Test - public void testDifferentObject2() { - Validate.differentObject("b", "a", "MSG"); - try { - Validate.differentObject("a", "a", "MSG"); - fail("Expecting IllegalArgumentException"); - } catch (final IllegalArgumentException ex) { - assertEquals("MSG", ex.getMessage()); - } - } - - @Test - public void testDifferentLong1() { - Validate.different(1, 0); - try { - Validate.different(0, 0); - fail("Expecting IllegalArgumentException"); - } catch (final IllegalArgumentException ex) { - assertEquals("The value 0 is invalid", ex.getMessage()); - } - } - - @Test - public void testDifferentLong2() { - Validate.different(1, 0, "MSG"); - try { - Validate.different(0, 0, "MSG"); - fail("Expecting IllegalArgumentException"); - } catch (final IllegalArgumentException ex) { - assertEquals("MSG", ex.getMessage()); - } - } - - @Test - public void testDifferentDouble1() { - Validate.different(1.0, 0.0); - Validate.different(Double.NaN, 0.0); - Validate.different(1.0, Double.NaN); - Validate.different(Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY); - try { - Validate.different(0, 0); - fail("Expecting IllegalArgumentException"); - } catch (final IllegalArgumentException ex) { - assertEquals("The value 0 is invalid", ex.getMessage()); - } - try { - Validate.different(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY); - fail("Expecting IllegalArgumentException"); - } catch (final IllegalArgumentException ex) { - assertEquals("The value Infinity is invalid", ex.getMessage()); - } - } - - @Test - public void testDifferentDouble2() { - Validate.different(1.0, 0.0, "MSG"); - Validate.different(Double.NaN, 0.0, "MSG"); - Validate.different(1.0, Double.NaN, "MSG"); - Validate.different(Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, "MSG"); - try { - Validate.different(0, 0, "MSG"); - fail("Expecting IllegalArgumentException"); - } catch (final IllegalArgumentException ex) { - assertEquals("MSG", ex.getMessage()); - } - try { - Validate.different(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY, "MSG"); - fail("Expecting IllegalArgumentException"); - } catch (final IllegalArgumentException ex) { - assertEquals("MSG", ex.getMessage()); - } - } - - //----------------------------------------------------------------------- - //----------------------------------------------------------------------- - @Test public void testInclusiveBetween() {