From 0595a9828a4b0d1aa41d96b5606fbc91626bf324 Mon Sep 17 00:00:00 2001 From: Lady-Stardust <> Date: Sun, 10 May 2015 03:31:53 +0200 Subject: [PATCH 1/4] Added new methods, see LANG-1134 --- .../org/apache/commons/lang3/Validate.java | 761 +++++++++++++++++- .../apache/commons/lang3/ValidateTest.java | 699 ++++++++++++++++ 2 files changed, 1459 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/apache/commons/lang3/Validate.java b/src/main/java/org/apache/commons/lang3/Validate.java index f8308954914..e3a32dec856 100644 --- a/src/main/java/org/apache/commons/lang3/Validate.java +++ b/src/main/java/org/apache/commons/lang3/Validate.java @@ -45,6 +45,20 @@ */ public class Validate { + private static final String DEFAULT_NOT_NAN_EX_MESSAGE = + "The validated value is not a number"; + private static final String DEFAULT_FINITE_EX_MESSAGE = + "The value is invalid: %f"; + private static final String DEFAULT_GREATER_EX_MESSAGE = + "The value %s is not greater than %s"; + private static final String DEFAULT_GREATER_OR_EQUAL_EX_MESSAGE = + "The value %s is not greater than or equal to %s"; + private static final String DEFAULT_SMALLER_EX_MESSAGE = + "The value %s is not smaller than %s"; + private static final String DEFAULT_SMALLER_OR_EQUAL_EX_MESSAGE = + "The value %s is not smaller than or equal to %s"; + private static final String DEFAULT_DIFFERENT_EX_MESSAGE = + "The value %s is invalid"; private static final String DEFAULT_EXCLUSIVE_BETWEEN_EX_MESSAGE = "The value %s is not in the specified exclusive range of %s to %s"; private static final String DEFAULT_INCLUSIVE_BETWEEN_EX_MESSAGE = @@ -874,7 +888,752 @@ public static void matchesPattern(final CharSequence input, final String pattern throw new IllegalArgumentException(String.format(message, values)); } } - + + // notNaN + //--------------------------------------------------------------------------------- + + /** + *
Validates that the specified argument is not {@code NaN}; otherwise + * throwing an exception.
+ * + *Validate.notNaN(myDouble);+ * + *
The message of the exception is "The validated value is not a + * number".
+ * + * @param value the value to validate + * @throws IllegalArgumentException if the value is not a number + * @see #notNaN(double, java.lang.String, java.lang.Object...) + * + * @since 3.4 + */ + public static void notNaN(final double value) { + notNaN(value, DEFAULT_NOT_NAN_EX_MESSAGE); + } + + /** + *Validates that the specified argument is not {@code NaN}; otherwise + * throwing an exception with the specified message.
+ * + *Validate.notNaN(myDouble, "The value must be a number");+ * + * @param value the value to validate + * @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 the value is not a number + * @see #notNaN(double) + * + * @since 3.4 + */ + public static void notNaN(final double value, final String message, final Object... values) { + if (value != value) { + throw new IllegalArgumentException(String.format(message, values)); + } + } + + // finite + //--------------------------------------------------------------------------------- + + /** + *
Validates that the specified argument is not infinite or {@code NaN}; + * otherwise throwing an exception.
+ * + *Validate.finite(myDouble);+ * + *
The message of the exception is "The value is invalid: %f".
+ * + * @param value the value to validate + * @throws IllegalArgumentException if the value is infinite or {@code NaN} + * @see #finite(double, java.lang.String, java.lang.Object...) + * + * @since 3.4 + */ + public static void finite(final double value) { + finite(value, DEFAULT_FINITE_EX_MESSAGE, value); + } + + /** + *Validates that the specified argument is not infinite or {@code NaN}; + * otherwise throwing an exception with the specified message.
+ * + *Validate.finite(myDouble, "The argument must contain a numeric value");+ * + * @param value the value to validate + * @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 the value is infinite or {@code NaN} + * @see #finite(double) + * + * @since 3.4 + */ + public static void finite(final double value, final String message, final Object... values) { + if (value != value || Double.isInfinite(value)) { + throw new IllegalArgumentException(String.format(message, values)); + } + } + + // greater + //--------------------------------------------------------------------------------- + + /** + *
Validates that the specified argument is strictly greater than a given + * reference; otherwise throwing an exception.
+ * + *Validate.greaterObj(myObject, refObject);+ * + *
The message of the exception is "The value {@code value} is not + * greater than {@code min}".
+ * + * @paramValidates that the specified argument is strictly greater than a given + * reference; otherwise throwing an exception with the specified message.
+ * + *Validate.greaterObj(myObject, refObject, "The value must be greater than the reference");+ * + * @param
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 min the reference value + * @param value the value to validate + * @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.4 + */ + public static void greater(final long min, final long value) { + greater(min, value, 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 min the reference value + * @param value the value to validate + * @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.4 + */ + public static void greater(final long min, final long value, 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 min the reference value + * @param value the value to validate + * @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.4 + */ + public static void greater(final double min, final double value) { + greater(min, value, 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 min the reference value + * @param value the value to validate + * @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.4 + */ + public static void greater(final double min, final double value, 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.greaterOrEqualObj(myObject, refObject);+ * + *
The message of the exception is "The value {@code value} is not + * greater than or equal to {@code min}".
+ * + * @paramValidates that the specified argument is greater than, or equal to, a + * given reference; otherwise throwing an exception.
+ * + *Validate.greaterOrEqualObj(myObject, refObject, "The value must be greater than the reference");+ * + * @param
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 min the reference value + * @param value the value to validate + * @throws IllegalArgumentException if {@code value} is smaller than {@code min} + * @see #greaterOrEqual(long, long, java.lang.String, java.lang.Object...) + * + * @since 3.4 + */ + public static void greaterOrEqual(final long min, final long value) { + greaterOrEqual(min, value, 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 min the reference value + * @param value the value to validate + * @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.4 + */ + public static void greaterOrEqual(final long min, final long value, 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 min the reference value + * @param value the value to validate + * @throws IllegalArgumentException if {@code value} is smaller than {@code min} + * @see #greaterOrEqual(double, double, java.lang.String, java.lang.Object...) + * + * @since 3.4 + */ + public static void greaterOrEqual(final double min, final double value) { + greaterOrEqual(min, value, 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 min the reference value + * @param value the value to validate + * @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.4 + */ + public static void greaterOrEqual(final double min, final double value, 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.smallerObj(myObject, refObject);+ * + *
The message of the exception is "The value {@code value} is not + * smaller than {@code max}".
+ * + * @paramValidates that the specified argument is strictly smaller than a given + * reference; otherwise throwing an exception with the specified message.
+ * + *Validate.smallerObj(myObject, refObject, "The value must be greater than the reference");+ * + * @param
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 max the reference value + * @param value the value to validate + * @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.4 + */ + public static void smaller(final long max, final long value) { + smaller(max, value, 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 max the reference value + * @param value the value to validate + * @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.4 + */ + public static void smaller(final long max, final long value, 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 max the reference value + * @param value the value to validate + * @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.4 + */ + public static void smaller(final double max, final double value) { + smaller(max, value, 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 max the reference value + * @param value the value to validate + * @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.4 + */ + public static void smaller(final double max, final double value, 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.smallerOrEqualObj(myObject, refObject);+ * + *
The message of the exception is "The value {@code value} is not + * smaller than or equal to {@code max}".
+ * + * @paramValidates that the specified argument is smaller than, or equal to, a + * given reference; otherwise throwing an exception with the specified message.
+ * + *Validate.smallerOrEqualObj(myObject, refObject, "The value must be greater than the reference");+ * + * @param
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 max the reference value + * @param value the value to validate + * @throws IllegalArgumentException if {@code value} is greater than {@code max} + * @see #smallerOrEqual(long, long, java.lang.String, java.lang.Object...) + * + * @since 3.4 + */ + public static void smallerOrEqual(final long max, final long value) { + smallerOrEqual(max, value, 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 max the reference value + * @param value the value to validate + * @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.4 + */ + public static void smallerOrEqual(final long max, final long value, 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 max the reference value + * @param value the value to validate + * @throws IllegalArgumentException if {@code value} is greater than {@code max} + * @see #smallerOrEqual(double, double, java.lang.String, java.lang.Object...) + * + * @since 3.4 + */ + public static void smallerOrEqual(final double max, final double value) { + smallerOrEqual(max, value, 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 max the reference value + * @param value the value to validate + * @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.4 + */ + public static void smallerOrEqual(final double max, final double value, final String message, final Object... values) { + if (!(value <= max)) { + throw new IllegalArgumentException(String.format(message, values)); + } + } + + // different + //--------------------------------------------------------------------------------- + + /** + *
Validates that the specified argument is not equal to a given value + * (reference); otherwise throwing an exception.
+ * + *Validate.differentObj(myObject, refObject);+ * + *
The message of the exception is "The value {@code value} is + * invalid".
+ * + * @paramValidates that the specified argument is not equal to a given value + * (reference); otherwise throwing an exception with the specified message.
+ * + *Validate.differentObj(myObject, refObject, "The value is invalid");+ * + * @param
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 reference the reference value + * @param value the value to validate + * @throws IllegalArgumentException if {@code value} is equal to {@code reference} + * + * @since 3.4 + */ + public static void different(final long reference, final long value) { + differentObj(reference, value, 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 reference the reference value + * @param value the value to validate + * @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.4 + */ + public static void different(final long reference, final long value, 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 reference the reference value + * @param value the value to validate + * @throws IllegalArgumentException if {@code value} is equal to {@code reference} + * + * @since 3.4 + */ + public static void different(final double reference, final double value) { + differentObj(reference, value, 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 reference the reference value + * @param value the value to validate + * @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.4 + */ + public static void different(final double reference, final double value, 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 954179c7ed2..0d6cc19c1ec 100644 --- a/src/test/java/org/apache/commons/lang3/ValidateTest.java +++ b/src/test/java/org/apache/commons/lang3/ValidateTest.java @@ -830,6 +830,699 @@ public void testMatchesPattern_withMessage() assertEquals("Does not match", e.getMessage()); } } + + //----------------------------------------------------------------------- + //----------------------------------------------------------------------- + + @Test + public void testNotNaN1() { + Validate.notNaN(0.0); + Validate.notNaN(Double.POSITIVE_INFINITY); + Validate.notNaN(Double.NEGATIVE_INFINITY); + try { + Validate.notNaN(Double.NaN); + fail("Expecting IllegalArgumentException"); + } catch (final IllegalArgumentException ex) { + assertEquals("The validated value is not a number", ex.getMessage()); + } + } + + @Test + public void testNotNaN2() { + Validate.notNaN(0.0, "MSG"); + Validate.notNaN(Double.POSITIVE_INFINITY, "MSG"); + Validate.notNaN(Double.NEGATIVE_INFINITY, "MSG"); + try { + Validate.notNaN(Double.NaN, "MSG"); + fail("Expecting IllegalArgumentException"); + } catch (final IllegalArgumentException ex) { + assertEquals("MSG", ex.getMessage()); + } + } + + //----------------------------------------------------------------------- + //----------------------------------------------------------------------- + + @Test + public void testFinite1() { + Validate.finite(0.0); + try { + Validate.finite(Double.POSITIVE_INFINITY); + fail("Expecting IllegalArgumentException"); + } catch (final IllegalArgumentException ex) { + assertEquals("The value is invalid: Infinity", ex.getMessage()); + } + try { + Validate.finite(Double.NEGATIVE_INFINITY); + fail("Expecting IllegalArgumentException"); + } catch (final IllegalArgumentException ex) { + assertEquals("The value is invalid: -Infinity", ex.getMessage()); + } + try { + Validate.finite(Double.NaN); + fail("Expecting IllegalArgumentException"); + } catch (final IllegalArgumentException ex) { + assertEquals("The value is invalid: NaN", ex.getMessage()); + } + } + + @Test + public void testFinite2() { + Validate.finite(0.0, "MSG"); + try { + Validate.finite(Double.POSITIVE_INFINITY, "MSG"); + fail("Expecting IllegalArgumentException"); + } catch (final IllegalArgumentException ex) { + assertEquals("MSG", ex.getMessage()); + } + try { + Validate.finite(Double.NEGATIVE_INFINITY, "MSG"); + fail("Expecting IllegalArgumentException"); + } catch (final IllegalArgumentException ex) { + assertEquals("MSG", ex.getMessage()); + } + try { + Validate.finite(Double.NaN, "MSG"); + fail("Expecting IllegalArgumentException"); + } catch (final IllegalArgumentException ex) { + assertEquals("MSG", ex.getMessage()); + } + } + + //----------------------------------------------------------------------- + //----------------------------------------------------------------------- + + @Test + public void testGreaterObject1() { + Validate.greaterObj("b", "c"); + try { + Validate.greaterObj("b", "b"); + fail("Expecting IllegalArgumentException"); + } catch (final IllegalArgumentException ex) { + assertEquals("The value b is not greater than b", ex.getMessage()); + } + try { + Validate.greaterObj("b", "a"); + fail("Expecting IllegalArgumentException"); + } catch (final IllegalArgumentException ex) { + assertEquals("The value a is not greater than b", ex.getMessage()); + } + } + + @Test + public void testGreaterObject2() { + Validate.greaterObj("b", "c", "MSG"); + try { + Validate.greaterObj("b", "b", "MSG"); + fail("Expecting IllegalArgumentException"); + } catch (final IllegalArgumentException ex) { + assertEquals("MSG", ex.getMessage()); + } + try { + Validate.greaterObj("b", "a", "MSG"); + fail("Expecting IllegalArgumentException"); + } catch (final IllegalArgumentException ex) { + assertEquals("MSG", ex.getMessage()); + } + } + + @Test + public void testGreaterLong1() { + Validate.greater(0, 1); + 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(0, -1); + fail("Expecting IllegalArgumentException"); + } catch (final IllegalArgumentException ex) { + assertEquals("The value -1 is not greater than 0", ex.getMessage()); + } + } + + @Test + public void testGreaterLong2() { + Validate.greater(0, 1, "MSG"); + try { + Validate.greater(0, 0, "MSG"); + fail("Expecting IllegalArgumentException"); + } catch (final IllegalArgumentException ex) { + assertEquals("MSG", ex.getMessage()); + } + try { + Validate.greater(0, -1, "MSG"); + fail("Expecting IllegalArgumentException"); + } catch (final IllegalArgumentException ex) { + assertEquals("MSG", ex.getMessage()); + } + } + + @Test + public void testGreaterDouble1() { + Validate.greater(0.0, 1.0); + Validate.greater(0.0, Double.POSITIVE_INFINITY); + 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(0.0, -1.0); + fail("Expecting IllegalArgumentException"); + } catch (final IllegalArgumentException ex) { + assertEquals("The value -1.0 is not greater than 0.0", ex.getMessage()); + } + try { + Validate.greater(0.0, Double.NEGATIVE_INFINITY); + fail("Expecting IllegalArgumentException"); + } catch (final IllegalArgumentException ex) { + assertEquals("The value -Infinity 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 NaN 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 0.0 is not greater than NaN", ex.getMessage()); + } + } + + @Test + public void testGreaterDouble2() { + Validate.greater(0.0, 1.0, "MSG"); + Validate.greater(0.0, Double.POSITIVE_INFINITY, "MSG"); + try { + Validate.greater(0.0, 0.0, "MSG"); + fail("Expecting IllegalArgumentException"); + } catch (final IllegalArgumentException ex) { + assertEquals("MSG", ex.getMessage()); + } + try { + Validate.greater(0.0, -1.0, "MSG"); + fail("Expecting IllegalArgumentException"); + } catch (final IllegalArgumentException ex) { + assertEquals("MSG", ex.getMessage()); + } + try { + Validate.greater(0.0, Double.NEGATIVE_INFINITY, "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()); + } + try { + Validate.greater(Double.NaN, 0.0, "MSG"); + fail("Expecting IllegalArgumentException"); + } catch (final IllegalArgumentException ex) { + assertEquals("MSG", ex.getMessage()); + } + } + + //----------------------------------------------------------------------- + //----------------------------------------------------------------------- + + @Test + public void testGreaterOrEqualObject1() { + Validate.greaterOrEqualObj("b", "c"); + Validate.greaterOrEqualObj("b", "b"); + try { + Validate.greaterOrEqualObj("b", "a"); + 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.greaterOrEqualObj("b", "c", "MSG"); + Validate.greaterOrEqualObj("b", "b", "MSG"); + try { + Validate.greaterOrEqualObj("b", "a", "MSG"); + fail("Expecting IllegalArgumentException"); + } catch (final IllegalArgumentException ex) { + assertEquals("MSG", ex.getMessage()); + } + } + + @Test + public void testGreaterOrEqualLong1() { + Validate.greaterOrEqual(0, 1); + Validate.greaterOrEqual(0, 0); + try { + Validate.greaterOrEqual(0, -1); + 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(0, 1, "MSG"); + Validate.greaterOrEqual(0, 0, "MSG"); + try { + Validate.greaterOrEqual(0, -1, "MSG"); + fail("Expecting IllegalArgumentException"); + } catch (final IllegalArgumentException ex) { + assertEquals("MSG", ex.getMessage()); + } + } + + @Test + public void testGreaterOrEqualDouble1() { + Validate.greaterOrEqual(0.0, 1.0); + Validate.greaterOrEqual(0.0, Double.POSITIVE_INFINITY); + Validate.greaterOrEqual(0.0, 0.0); + try { + Validate.greaterOrEqual(0.0, -1.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(0.0, Double.NEGATIVE_INFINITY); + 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(0.0, Double.NaN); + 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(Double.NaN, 0.0); + 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(0.0, 1.0, "MSG"); + Validate.greaterOrEqual(0.0, Double.POSITIVE_INFINITY, "MSG"); + Validate.greaterOrEqual(0.0, 0.0, "MSG"); + + try { + Validate.greaterOrEqual(0.0, -1.0, "MSG"); + fail("Expecting IllegalArgumentException"); + } catch (final IllegalArgumentException ex) { + assertEquals("MSG", ex.getMessage()); + } + try { + Validate.greaterOrEqual(0.0, Double.NEGATIVE_INFINITY, "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, 0.0, "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.smallerObj("b", "a"); + try { + Validate.smallerObj("b", "b"); + fail("Expecting IllegalArgumentException"); + } catch (final IllegalArgumentException ex) { + assertEquals("The value b is not smaller than b", ex.getMessage()); + } + try { + Validate.smallerObj("b", "c"); + fail("Expecting IllegalArgumentException"); + } catch (final IllegalArgumentException ex) { + assertEquals("The value c is not smaller than b", ex.getMessage()); + } + } + + @Test + public void testSmallerObject2() { + Validate.smallerObj("b", "a", "MSG"); + try { + Validate.smallerObj("b", "b", "MSG"); + fail("Expecting IllegalArgumentException"); + } catch (final IllegalArgumentException ex) { + assertEquals("MSG", ex.getMessage()); + } + try { + Validate.smallerObj("b", "c", "MSG"); + fail("Expecting IllegalArgumentException"); + } catch (final IllegalArgumentException ex) { + assertEquals("MSG", ex.getMessage()); + } + } + + @Test + public void testSmallerLong1() { + Validate.smaller(0, -1); + 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(0, 1); + fail("Expecting IllegalArgumentException"); + } catch (final IllegalArgumentException ex) { + assertEquals("The value 1 is not smaller than 0", ex.getMessage()); + } + } + + @Test + public void testSmallerLong2() { + Validate.smaller(0, -1, "MSG"); + try { + Validate.smaller(0, 0, "MSG"); + fail("Expecting IllegalArgumentException"); + } catch (final IllegalArgumentException ex) { + assertEquals("MSG", ex.getMessage()); + } + try { + Validate.smaller(0, 1, "MSG"); + fail("Expecting IllegalArgumentException"); + } catch (final IllegalArgumentException ex) { + assertEquals("MSG", ex.getMessage()); + } + } + + @Test + public void testSmallerDouble1() { + Validate.smaller(0.0, -1.0); + Validate.smaller(0.0, Double.NEGATIVE_INFINITY); + 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(0.0, 1.0); + fail("Expecting IllegalArgumentException"); + } catch (final IllegalArgumentException ex) { + assertEquals("The value 1.0 is not smaller than 0.0", ex.getMessage()); + } + try { + Validate.smaller(0.0, Double.POSITIVE_INFINITY); + fail("Expecting IllegalArgumentException"); + } catch (final IllegalArgumentException ex) { + assertEquals("The value Infinity 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 NaN 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 0.0 is not smaller than NaN", ex.getMessage()); + } + } + + @Test + public void testSmallerDouble2() { + Validate.smaller(0.0, -1.0, "MSG"); + Validate.smaller(0.0, Double.NEGATIVE_INFINITY, "MSG"); + try { + Validate.smaller(0.0, 0.0, "MSG"); + fail("Expecting IllegalArgumentException"); + } catch (final IllegalArgumentException ex) { + assertEquals("MSG", ex.getMessage()); + } + try { + Validate.smaller(0.0, 1.0, "MSG"); + fail("Expecting IllegalArgumentException"); + } catch (final IllegalArgumentException ex) { + assertEquals("MSG", ex.getMessage()); + } + try { + Validate.smaller(0.0, Double.POSITIVE_INFINITY, "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()); + } + try { + Validate.smaller(Double.NaN, 0.0, "MSG"); + fail("Expecting IllegalArgumentException"); + } catch (final IllegalArgumentException ex) { + assertEquals("MSG", ex.getMessage()); + } + } + + //----------------------------------------------------------------------- + //----------------------------------------------------------------------- + + @Test + public void testSmallerOrEqualObject1() { + Validate.smallerOrEqualObj("b", "a"); + Validate.smallerOrEqualObj("b", "b"); + try { + Validate.smallerOrEqualObj("b", "c"); + 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.smallerOrEqualObj("b", "a", "MSG"); + Validate.smallerOrEqualObj("b", "b", "MSG"); + try { + Validate.smallerOrEqualObj("b", "c", "MSG"); + fail("Expecting IllegalArgumentException"); + } catch (final IllegalArgumentException ex) { + assertEquals("MSG", ex.getMessage()); + } + } + + @Test + public void testSmallerOrEqualLong1() { + Validate.smallerOrEqual(0, -1); + Validate.smallerOrEqual(0, 0); + try { + Validate.smallerOrEqual(0, 1); + 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(0, -1, "MSG"); + Validate.smallerOrEqual(0, 0, "MSG"); + try { + Validate.smallerOrEqual(0, 1, "MSG"); + fail("Expecting IllegalArgumentException"); + } catch (final IllegalArgumentException ex) { + assertEquals("MSG", ex.getMessage()); + } + } + + @Test + public void testSmallerOrEqualDouble1() { + Validate.smallerOrEqual(0.0, -1.0); + Validate.smallerOrEqual(0.0, Double.NEGATIVE_INFINITY); + Validate.smallerOrEqual(0.0, 0.0); + try { + Validate.smallerOrEqual(0.0, 1.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(0.0, Double.POSITIVE_INFINITY); + 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(0.0, Double.NaN); + 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(Double.NaN, 0.0); + 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(0.0, -1.0, "MSG"); + Validate.smallerOrEqual(0.0, Double.NEGATIVE_INFINITY, "MSG"); + Validate.smallerOrEqual(0.0, 0.0, "MSG"); + try { + Validate.smallerOrEqual(0.0, 1.0, "MSG"); + fail("Expecting IllegalArgumentException"); + } catch (final IllegalArgumentException ex) { + assertEquals("MSG", ex.getMessage()); + } + try { + Validate.smallerOrEqual(0.0, Double.POSITIVE_INFINITY, "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()); + } + try { + Validate.smallerOrEqual(Double.NaN, 0.0, "MSG"); + fail("Expecting IllegalArgumentException"); + } catch (final IllegalArgumentException ex) { + assertEquals("MSG", ex.getMessage()); + } + } + + //----------------------------------------------------------------------- + //----------------------------------------------------------------------- + + @Test + public void testDifferentObject1() { + Validate.differentObj("a", "b"); + try { + Validate.differentObj("a", "a"); + fail("Expecting IllegalArgumentException"); + } catch (final IllegalArgumentException ex) { + assertEquals("The value a is invalid", ex.getMessage()); + } + } + + @Test + public void testDifferentObject2() { + Validate.differentObj("a", "b", "MSG"); + try { + Validate.differentObj("a", "a", "MSG"); + fail("Expecting IllegalArgumentException"); + } catch (final IllegalArgumentException ex) { + assertEquals("MSG", ex.getMessage()); + } + } + + @Test + public void testDifferentLong1() { + Validate.different(0, 1); + 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(0, 1, "MSG"); + try { + Validate.different(0, 0, "MSG"); + fail("Expecting IllegalArgumentException"); + } catch (final IllegalArgumentException ex) { + assertEquals("MSG", ex.getMessage()); + } + } + + @Test + public void testDifferentDouble1() { + Validate.different(0.0, 1.0); + Validate.different(0.0, Double.NaN); + Validate.different(Double.NaN, 1.0); + Validate.different(Double.POSITIVE_INFINITY, Double.NEGATIVE_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(0.0, 1.0, "MSG"); + Validate.different(0.0, Double.NaN, "MSG"); + Validate.different(Double.NaN, 1.0, "MSG"); + Validate.different(Double.POSITIVE_INFINITY, Double.NEGATIVE_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() @@ -1015,6 +1708,9 @@ public void testExclusiveBetweenDouble_withMessage() } } + //----------------------------------------------------------------------- + //----------------------------------------------------------------------- + @Test public void testIsInstanceOf() { Validate.isInstanceOf(String.class, "hi"); @@ -1067,6 +1763,9 @@ public void testIsInstanceOf_withMessageArgs() { } } + //----------------------------------------------------------------------- + //----------------------------------------------------------------------- + @Test public void testIsAssignable() { Validate.isAssignableFrom(CharSequence.class, String.class); From da892402f40cfa30f8b6ff9659020ba16a9027af Mon Sep 17 00:00:00 2001 From: Stardust
Validate.greaterObj(myObject, refObject, "The value must be greater than the reference");* * @param
The message of the exception is "The value {@code value} is not * greater than {@code min}".
* - * @param min the reference value * @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.4 */ - public static void greater(final long min, final long value) { - greater(min, value, DEFAULT_GREATER_EX_MESSAGE, value, min); + public static void greater(final long value, final long min) { + greater(value, min, DEFAULT_GREATER_EX_MESSAGE, value, min); } /** @@ -1044,8 +1044,8 @@ public static void greater(final long min, final long value) { * *Validate.greater(myLong, 0);* - * @param min the reference value * @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} @@ -1053,7 +1053,7 @@ public static void greater(final long min, final long value) { * * @since 3.4 */ - public static void greater(final long min, final long value, final String message, final Object... values) { + 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)); } @@ -1071,15 +1071,15 @@ public static void greater(final long min, final long value, final String messag *
The message of the exception is "The value {@code value} is not * greater than {@code min}".
* - * @param min the reference value * @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.4 */ - public static void greater(final double min, final double value) { - greater(min, value, DEFAULT_GREATER_EX_MESSAGE, value, min); + public static void greater(final double value, final double min) { + greater(value, min, DEFAULT_GREATER_EX_MESSAGE, value, min); } /** @@ -1091,8 +1091,8 @@ public static void greater(final double min, final double value) { * *Validate.greater(myDouble, 0.0);* - * @param min the reference value * @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} @@ -1100,7 +1100,7 @@ public static void greater(final double min, final double value) { * * @since 3.4 */ - public static void greater(final double min, final double value, final String message, final Object... values) { + 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)); } @@ -1119,15 +1119,15 @@ public static void greater(final double min, final double value, final String me * greater than or equal to {@code min}". * * @param
Validate.greaterOrEqualObj(myObject, refObject, "The value must be greater than the reference");* * @param
The message of the exception is "The value {@code value} is not * greater than or equal to {@code min}".
* - * @param min the reference value * @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.4 */ - public static void greaterOrEqual(final long min, final long value) { - greaterOrEqual(min, value, DEFAULT_GREATER_OR_EQUAL_EX_MESSAGE, value, min); + public static void greaterOrEqual(final long value, final long min) { + greaterOrEqual(value, min, DEFAULT_GREATER_OR_EQUAL_EX_MESSAGE, value, min); } /** @@ -1178,8 +1178,8 @@ public static void greaterOrEqual(final long min, final long value) { * *Validate.greaterOrEqual(myLong, 0);* - * @param min the reference value * @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} @@ -1187,7 +1187,7 @@ public static void greaterOrEqual(final long min, final long value) { * * @since 3.4 */ - public static void greaterOrEqual(final long min, final long value, final String message, final Object... values) { + 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)); } @@ -1205,15 +1205,15 @@ public static void greaterOrEqual(final long min, final long value, final String *
The message of the exception is "The value {@code value} is not * greater than or equal to {@code min}".
* - * @param min the reference value * @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.4 */ - public static void greaterOrEqual(final double min, final double value) { - greaterOrEqual(min, value, DEFAULT_GREATER_OR_EQUAL_EX_MESSAGE, value, min); + public static void greaterOrEqual(final double value, final double min) { + greaterOrEqual(value, min, DEFAULT_GREATER_OR_EQUAL_EX_MESSAGE, value, min); } /** @@ -1225,8 +1225,8 @@ public static void greaterOrEqual(final double min, final double value) { * *Validate.greaterOrEqual(myDouble, 0.0);* - * @param min the reference value * @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} @@ -1234,7 +1234,7 @@ public static void greaterOrEqual(final double min, final double value) { * * @since 3.4 */ - public static void greaterOrEqual(final double min, final double value, final String message, final Object... values) { + 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)); } @@ -1253,15 +1253,15 @@ public static void greaterOrEqual(final double min, final double value, final St * smaller than {@code max}". * * @param
Validate.smallerObj(myObject, refObject, "The value must be greater than the reference");* * @param
The message of the exception is "The value {@code value} is not * smaller than {@code max}".
* - * @param max the reference value * @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.4 */ - public static void smaller(final long max, final long value) { - smaller(max, value, DEFAULT_SMALLER_EX_MESSAGE, value, max); + public static void smaller(final long value, final long max) { + smaller(value, max, DEFAULT_SMALLER_EX_MESSAGE, value, max); } /** @@ -1312,8 +1312,8 @@ public static void smaller(final long max, final long value) { * *Validate.smaller(myLong, 0);* - * @param max the reference value * @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} @@ -1321,7 +1321,7 @@ public static void smaller(final long max, final long value) { * * @since 3.4 */ - public static void smaller(final long max, final long value, final String message, final Object... values) { + 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)); } @@ -1339,15 +1339,15 @@ public static void smaller(final long max, final long value, final String messag *
The message of the exception is "The value {@code value} is not * smaller than {@code max}".
* - * @param max the reference value * @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.4 */ - public static void smaller(final double max, final double value) { - smaller(max, value, DEFAULT_SMALLER_EX_MESSAGE, value, max); + public static void smaller(final double value, final double max) { + smaller(value, max, DEFAULT_SMALLER_EX_MESSAGE, value, max); } /** @@ -1359,8 +1359,8 @@ public static void smaller(final double max, final double value) { * *Validate.smaller(myDouble, 0.0);* - * @param max the reference value * @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} @@ -1368,7 +1368,7 @@ public static void smaller(final double max, final double value) { * * @since 3.4 */ - public static void smaller(final double max, final double value, final String message, final Object... values) { + 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)); } @@ -1387,15 +1387,15 @@ public static void smaller(final double max, final double value, final String me * smaller than or equal to {@code max}". * * @param
Validate.smallerOrEqualObj(myObject, refObject, "The value must be greater than the reference");* * @param
The message of the exception is "The value {@code value} is not * smaller than or equal to {@code max}".
* - * @param max the reference value * @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.4 */ - public static void smallerOrEqual(final long max, final long value) { - smallerOrEqual(max, value, DEFAULT_SMALLER_OR_EQUAL_EX_MESSAGE, value, max); + public static void smallerOrEqual(final long value, final long max) { + smallerOrEqual(value, max, DEFAULT_SMALLER_OR_EQUAL_EX_MESSAGE, value, max); } /** @@ -1446,8 +1446,8 @@ public static void smallerOrEqual(final long max, final long value) { * *Validate.smallerOrEqual(myLong, 0);* - * @param max the reference value * @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} @@ -1455,7 +1455,7 @@ public static void smallerOrEqual(final long max, final long value) { * * @since 3.4 */ - public static void smallerOrEqual(final long max, final long value, final String message, final Object... values) { + 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)); } @@ -1473,15 +1473,15 @@ public static void smallerOrEqual(final long max, final long value, final String *
The message of the exception is "The value {@code value} is not * smaller than or equal to {@code max}".
* - * @param max the reference value * @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.4 */ - public static void smallerOrEqual(final double max, final double value) { - smallerOrEqual(max, value, DEFAULT_SMALLER_OR_EQUAL_EX_MESSAGE, value, max); + public static void smallerOrEqual(final double value, final double max) { + smallerOrEqual(value, max, DEFAULT_SMALLER_OR_EQUAL_EX_MESSAGE, value, max); } /** @@ -1493,8 +1493,8 @@ public static void smallerOrEqual(final double max, final double value) { * *Validate.smallerOrEqual(myDouble, 0.0);* - * @param max the reference value * @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} @@ -1502,7 +1502,7 @@ public static void smallerOrEqual(final double max, final double value) { * * @since 3.4 */ - public static void smallerOrEqual(final double max, final double value, final String message, final Object... values) { + 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)); } @@ -1512,41 +1512,47 @@ public static void smallerOrEqual(final double max, final double value, final St //--------------------------------------------------------------------------------- /** - *
Validates that the specified argument is not equal to a given value + *
Validates that the specified argument is different from a given value * (reference); otherwise throwing an exception.
* + *Two objects are considered different if + * {@code value.compareTo(reference) != 0}
+ * *Validate.differentObj(myObject, refObject);* *
The message of the exception is "The value {@code value} is * invalid".
* * @paramValidates that the specified argument is not equal to a given 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.compareTo(reference) != 0}
+ * *Validate.differentObj(myObject, refObject, "The value is invalid");* * @param
The message of the exception is "The value {@code value} is * invalid".
* - * @param reference the reference value * @param value the value to validate + * @param reference the reference value * @throws IllegalArgumentException if {@code value} is equal to {@code reference} * * @since 3.4 */ - public static void different(final long reference, final long value) { - different(reference, value, DEFAULT_DIFFERENT_EX_MESSAGE, value); + public static void different(final long value, final long reference) { + different(value, reference, DEFAULT_DIFFERENT_EX_MESSAGE, value); } /** @@ -1577,15 +1583,15 @@ public static void different(final long reference, final long value) { * *Validate.different(myLong, 0, "The value is invalid");* - * @param reference the reference value * @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.4 */ - public static void different(final long reference, final long value, final String message, final Object... values) { + 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)); } @@ -1602,14 +1608,14 @@ public static void different(final long reference, final long value, final Strin *
The message of the exception is "The value {@code value} is * invalid".
* - * @param reference the reference value * @param value the value to validate + * @param reference the reference value * @throws IllegalArgumentException if {@code value} is equal to {@code reference} * * @since 3.4 */ - public static void different(final double reference, final double value) { - different(reference, value, DEFAULT_DIFFERENT_EX_MESSAGE, value); + public static void different(final double value, final double reference) { + different(value, reference, DEFAULT_DIFFERENT_EX_MESSAGE, value); } /** @@ -1620,15 +1626,15 @@ public static void different(final double reference, final double value) { * *Validate.different(myDouble, 0.0, "The value is invalid");* - * @param reference the reference value * @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.4 */ - public static void different(final double reference, final double value, final String message, final Object... values) { + 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)); } diff --git a/src/test/java/org/apache/commons/lang3/ValidateTest.java b/src/test/java/org/apache/commons/lang3/ValidateTest.java index 0d6cc19c1ec..8c242cab45b 100644 --- a/src/test/java/org/apache/commons/lang3/ValidateTest.java +++ b/src/test/java/org/apache/commons/lang3/ValidateTest.java @@ -914,7 +914,7 @@ public void testFinite2() { @Test public void testGreaterObject1() { - Validate.greaterObj("b", "c"); + Validate.greaterObj("c", "b"); try { Validate.greaterObj("b", "b"); fail("Expecting IllegalArgumentException"); @@ -922,7 +922,7 @@ public void testGreaterObject1() { assertEquals("The value b is not greater than b", ex.getMessage()); } try { - Validate.greaterObj("b", "a"); + Validate.greaterObj("a", "b"); fail("Expecting IllegalArgumentException"); } catch (final IllegalArgumentException ex) { assertEquals("The value a is not greater than b", ex.getMessage()); @@ -931,7 +931,7 @@ public void testGreaterObject1() { @Test public void testGreaterObject2() { - Validate.greaterObj("b", "c", "MSG"); + Validate.greaterObj("c", "b", "MSG"); try { Validate.greaterObj("b", "b", "MSG"); fail("Expecting IllegalArgumentException"); @@ -939,7 +939,7 @@ public void testGreaterObject2() { assertEquals("MSG", ex.getMessage()); } try { - Validate.greaterObj("b", "a", "MSG"); + Validate.greaterObj("a", "b", "MSG"); fail("Expecting IllegalArgumentException"); } catch (final IllegalArgumentException ex) { assertEquals("MSG", ex.getMessage()); @@ -948,7 +948,7 @@ public void testGreaterObject2() { @Test public void testGreaterLong1() { - Validate.greater(0, 1); + Validate.greater(1, 0); try { Validate.greater(0, 0); fail("Expecting IllegalArgumentException"); @@ -956,7 +956,7 @@ public void testGreaterLong1() { assertEquals("The value 0 is not greater than 0", ex.getMessage()); } try { - Validate.greater(0, -1); + Validate.greater(-1, 0); fail("Expecting IllegalArgumentException"); } catch (final IllegalArgumentException ex) { assertEquals("The value -1 is not greater than 0", ex.getMessage()); @@ -965,7 +965,7 @@ public void testGreaterLong1() { @Test public void testGreaterLong2() { - Validate.greater(0, 1, "MSG"); + Validate.greater(1, 0, "MSG"); try { Validate.greater(0, 0, "MSG"); fail("Expecting IllegalArgumentException"); @@ -973,7 +973,7 @@ public void testGreaterLong2() { assertEquals("MSG", ex.getMessage()); } try { - Validate.greater(0, -1, "MSG"); + Validate.greater(-1, 0, "MSG"); fail("Expecting IllegalArgumentException"); } catch (final IllegalArgumentException ex) { assertEquals("MSG", ex.getMessage()); @@ -982,8 +982,8 @@ public void testGreaterLong2() { @Test public void testGreaterDouble1() { - Validate.greater(0.0, 1.0); - Validate.greater(0.0, Double.POSITIVE_INFINITY); + Validate.greater(1.0, 0.0); + Validate.greater(Double.POSITIVE_INFINITY, 0.0); try { Validate.greater(0.0, 0.0); fail("Expecting IllegalArgumentException"); @@ -991,25 +991,25 @@ public void testGreaterDouble1() { assertEquals("The value 0.0 is not greater than 0.0", ex.getMessage()); } try { - Validate.greater(0.0, -1.0); + 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(0.0, Double.NEGATIVE_INFINITY); + 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(0.0, Double.NaN); + 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(Double.NaN, 0.0); + 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()); @@ -1018,8 +1018,8 @@ public void testGreaterDouble1() { @Test public void testGreaterDouble2() { - Validate.greater(0.0, 1.0, "MSG"); - Validate.greater(0.0, Double.POSITIVE_INFINITY, "MSG"); + 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"); @@ -1027,25 +1027,25 @@ public void testGreaterDouble2() { assertEquals("MSG", ex.getMessage()); } try { - Validate.greater(0.0, -1.0, "MSG"); + Validate.greater(-1.0, 0.0, "MSG"); fail("Expecting IllegalArgumentException"); } catch (final IllegalArgumentException ex) { assertEquals("MSG", ex.getMessage()); } try { - Validate.greater(0.0, Double.NEGATIVE_INFINITY, "MSG"); + Validate.greater(Double.NEGATIVE_INFINITY, 0.0, "MSG"); fail("Expecting IllegalArgumentException"); } catch (final IllegalArgumentException ex) { assertEquals("MSG", ex.getMessage()); } try { - Validate.greater(0.0, Double.NaN, "MSG"); + Validate.greater(Double.NaN, 0.0, "MSG"); fail("Expecting IllegalArgumentException"); } catch (final IllegalArgumentException ex) { assertEquals("MSG", ex.getMessage()); } try { - Validate.greater(Double.NaN, 0.0, "MSG"); + Validate.greater(0.0, Double.NaN, "MSG"); fail("Expecting IllegalArgumentException"); } catch (final IllegalArgumentException ex) { assertEquals("MSG", ex.getMessage()); @@ -1057,10 +1057,10 @@ public void testGreaterDouble2() { @Test public void testGreaterOrEqualObject1() { - Validate.greaterOrEqualObj("b", "c"); + Validate.greaterOrEqualObj("c", "b"); Validate.greaterOrEqualObj("b", "b"); try { - Validate.greaterOrEqualObj("b", "a"); + Validate.greaterOrEqualObj("a", "b"); fail("Expecting IllegalArgumentException"); } catch (final IllegalArgumentException ex) { assertEquals("The value a is not greater than or equal to b", ex.getMessage()); @@ -1069,10 +1069,10 @@ public void testGreaterOrEqualObject1() { @Test public void testGreaterOrEqualObject2() { - Validate.greaterOrEqualObj("b", "c", "MSG"); + Validate.greaterOrEqualObj("c", "b", "MSG"); Validate.greaterOrEqualObj("b", "b", "MSG"); try { - Validate.greaterOrEqualObj("b", "a", "MSG"); + Validate.greaterOrEqualObj("a", "b", "MSG"); fail("Expecting IllegalArgumentException"); } catch (final IllegalArgumentException ex) { assertEquals("MSG", ex.getMessage()); @@ -1081,10 +1081,10 @@ public void testGreaterOrEqualObject2() { @Test public void testGreaterOrEqualLong1() { - Validate.greaterOrEqual(0, 1); + Validate.greaterOrEqual(1, 0); Validate.greaterOrEqual(0, 0); try { - Validate.greaterOrEqual(0, -1); + 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()); @@ -1093,10 +1093,10 @@ public void testGreaterOrEqualLong1() { @Test public void testGreaterOrEqualLong2() { - Validate.greaterOrEqual(0, 1, "MSG"); + Validate.greaterOrEqual(1, 0, "MSG"); Validate.greaterOrEqual(0, 0, "MSG"); try { - Validate.greaterOrEqual(0, -1, "MSG"); + Validate.greaterOrEqual(-1, 0, "MSG"); fail("Expecting IllegalArgumentException"); } catch (final IllegalArgumentException ex) { assertEquals("MSG", ex.getMessage()); @@ -1105,29 +1105,29 @@ public void testGreaterOrEqualLong2() { @Test public void testGreaterOrEqualDouble1() { - Validate.greaterOrEqual(0.0, 1.0); - Validate.greaterOrEqual(0.0, Double.POSITIVE_INFINITY); + Validate.greaterOrEqual(1.0, 0.0); + Validate.greaterOrEqual(Double.POSITIVE_INFINITY, 0.0); Validate.greaterOrEqual(0.0, 0.0); try { - Validate.greaterOrEqual(0.0, -1.0); + 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(0.0, Double.NEGATIVE_INFINITY); + 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(0.0, Double.NaN); + 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(Double.NaN, 0.0); + 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()); @@ -1142,30 +1142,30 @@ public void testGreaterOrEqualDouble1() { @Test public void testGreaterOrEqualDouble2() { - Validate.greaterOrEqual(0.0, 1.0, "MSG"); - Validate.greaterOrEqual(0.0, Double.POSITIVE_INFINITY, "MSG"); + 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(0.0, -1.0, "MSG"); + Validate.greaterOrEqual(-1.0, 0.0, "MSG"); fail("Expecting IllegalArgumentException"); } catch (final IllegalArgumentException ex) { assertEquals("MSG", ex.getMessage()); } try { - Validate.greaterOrEqual(0.0, Double.NEGATIVE_INFINITY, "MSG"); + Validate.greaterOrEqual(Double.NEGATIVE_INFINITY, 0.0, "MSG"); fail("Expecting IllegalArgumentException"); } catch (final IllegalArgumentException ex) { assertEquals("MSG", ex.getMessage()); } try { - Validate.greaterOrEqual(0.0, Double.NaN, "MSG"); + Validate.greaterOrEqual(Double.NaN, 0.0, "MSG"); fail("Expecting IllegalArgumentException"); } catch (final IllegalArgumentException ex) { assertEquals("MSG", ex.getMessage()); } try { - Validate.greaterOrEqual(Double.NaN, 0.0, "MSG"); + Validate.greaterOrEqual(0.0, Double.NaN, "MSG"); fail("Expecting IllegalArgumentException"); } catch (final IllegalArgumentException ex) { assertEquals("MSG", ex.getMessage()); @@ -1183,7 +1183,7 @@ public void testGreaterOrEqualDouble2() { @Test public void testSmallerObject1() { - Validate.smallerObj("b", "a"); + Validate.smallerObj("a", "b"); try { Validate.smallerObj("b", "b"); fail("Expecting IllegalArgumentException"); @@ -1191,7 +1191,7 @@ public void testSmallerObject1() { assertEquals("The value b is not smaller than b", ex.getMessage()); } try { - Validate.smallerObj("b", "c"); + Validate.smallerObj("c", "b"); fail("Expecting IllegalArgumentException"); } catch (final IllegalArgumentException ex) { assertEquals("The value c is not smaller than b", ex.getMessage()); @@ -1200,7 +1200,7 @@ public void testSmallerObject1() { @Test public void testSmallerObject2() { - Validate.smallerObj("b", "a", "MSG"); + Validate.smallerObj("a", "b", "MSG"); try { Validate.smallerObj("b", "b", "MSG"); fail("Expecting IllegalArgumentException"); @@ -1208,7 +1208,7 @@ public void testSmallerObject2() { assertEquals("MSG", ex.getMessage()); } try { - Validate.smallerObj("b", "c", "MSG"); + Validate.smallerObj("c", "b", "MSG"); fail("Expecting IllegalArgumentException"); } catch (final IllegalArgumentException ex) { assertEquals("MSG", ex.getMessage()); @@ -1217,7 +1217,7 @@ public void testSmallerObject2() { @Test public void testSmallerLong1() { - Validate.smaller(0, -1); + Validate.smaller(-1, 0); try { Validate.smaller(0, 0); fail("Expecting IllegalArgumentException"); @@ -1225,7 +1225,7 @@ public void testSmallerLong1() { assertEquals("The value 0 is not smaller than 0", ex.getMessage()); } try { - Validate.smaller(0, 1); + Validate.smaller(1, 0); fail("Expecting IllegalArgumentException"); } catch (final IllegalArgumentException ex) { assertEquals("The value 1 is not smaller than 0", ex.getMessage()); @@ -1234,7 +1234,7 @@ public void testSmallerLong1() { @Test public void testSmallerLong2() { - Validate.smaller(0, -1, "MSG"); + Validate.smaller(-1, 0, "MSG"); try { Validate.smaller(0, 0, "MSG"); fail("Expecting IllegalArgumentException"); @@ -1242,7 +1242,7 @@ public void testSmallerLong2() { assertEquals("MSG", ex.getMessage()); } try { - Validate.smaller(0, 1, "MSG"); + Validate.smaller(1, 0, "MSG"); fail("Expecting IllegalArgumentException"); } catch (final IllegalArgumentException ex) { assertEquals("MSG", ex.getMessage()); @@ -1251,8 +1251,8 @@ public void testSmallerLong2() { @Test public void testSmallerDouble1() { - Validate.smaller(0.0, -1.0); - Validate.smaller(0.0, Double.NEGATIVE_INFINITY); + Validate.smaller(-1.0, 0.0); + Validate.smaller(Double.NEGATIVE_INFINITY, 0.0); try { Validate.smaller(0.0, 0.0); fail("Expecting IllegalArgumentException"); @@ -1260,25 +1260,25 @@ public void testSmallerDouble1() { assertEquals("The value 0.0 is not smaller than 0.0", ex.getMessage()); } try { - Validate.smaller(0.0, 1.0); + 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(0.0, Double.POSITIVE_INFINITY); + 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(0.0, Double.NaN); + 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(Double.NaN, 0.0); + 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()); @@ -1287,8 +1287,8 @@ public void testSmallerDouble1() { @Test public void testSmallerDouble2() { - Validate.smaller(0.0, -1.0, "MSG"); - Validate.smaller(0.0, Double.NEGATIVE_INFINITY, "MSG"); + 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"); @@ -1296,25 +1296,25 @@ public void testSmallerDouble2() { assertEquals("MSG", ex.getMessage()); } try { - Validate.smaller(0.0, 1.0, "MSG"); + Validate.smaller(1.0, 0.0, "MSG"); fail("Expecting IllegalArgumentException"); } catch (final IllegalArgumentException ex) { assertEquals("MSG", ex.getMessage()); } try { - Validate.smaller(0.0, Double.POSITIVE_INFINITY, "MSG"); + Validate.smaller(Double.POSITIVE_INFINITY, 0.0, "MSG"); fail("Expecting IllegalArgumentException"); } catch (final IllegalArgumentException ex) { assertEquals("MSG", ex.getMessage()); } try { - Validate.smaller(0.0, Double.NaN, "MSG"); + Validate.smaller(Double.NaN, 0.0, "MSG"); fail("Expecting IllegalArgumentException"); } catch (final IllegalArgumentException ex) { assertEquals("MSG", ex.getMessage()); } try { - Validate.smaller(Double.NaN, 0.0, "MSG"); + Validate.smaller(0.0, Double.NaN, "MSG"); fail("Expecting IllegalArgumentException"); } catch (final IllegalArgumentException ex) { assertEquals("MSG", ex.getMessage()); @@ -1326,10 +1326,10 @@ public void testSmallerDouble2() { @Test public void testSmallerOrEqualObject1() { - Validate.smallerOrEqualObj("b", "a"); + Validate.smallerOrEqualObj("a", "b"); Validate.smallerOrEqualObj("b", "b"); try { - Validate.smallerOrEqualObj("b", "c"); + Validate.smallerOrEqualObj("c", "b"); fail("Expecting IllegalArgumentException"); } catch (final IllegalArgumentException ex) { assertEquals("The value c is not smaller than or equal to b", ex.getMessage()); @@ -1338,10 +1338,10 @@ public void testSmallerOrEqualObject1() { @Test public void testSmallerOrEqualObject2() { - Validate.smallerOrEqualObj("b", "a", "MSG"); + Validate.smallerOrEqualObj("a", "b", "MSG"); Validate.smallerOrEqualObj("b", "b", "MSG"); try { - Validate.smallerOrEqualObj("b", "c", "MSG"); + Validate.smallerOrEqualObj("c", "b", "MSG"); fail("Expecting IllegalArgumentException"); } catch (final IllegalArgumentException ex) { assertEquals("MSG", ex.getMessage()); @@ -1350,10 +1350,10 @@ public void testSmallerOrEqualObject2() { @Test public void testSmallerOrEqualLong1() { - Validate.smallerOrEqual(0, -1); + Validate.smallerOrEqual(-1, 0); Validate.smallerOrEqual(0, 0); try { - Validate.smallerOrEqual(0, 1); + 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()); @@ -1362,10 +1362,10 @@ public void testSmallerOrEqualLong1() { @Test public void testSmallerOrEqualLong2() { - Validate.smallerOrEqual(0, -1, "MSG"); + Validate.smallerOrEqual(-1, 0, "MSG"); Validate.smallerOrEqual(0, 0, "MSG"); try { - Validate.smallerOrEqual(0, 1, "MSG"); + Validate.smallerOrEqual(1, 0, "MSG"); fail("Expecting IllegalArgumentException"); } catch (final IllegalArgumentException ex) { assertEquals("MSG", ex.getMessage()); @@ -1374,29 +1374,29 @@ public void testSmallerOrEqualLong2() { @Test public void testSmallerOrEqualDouble1() { - Validate.smallerOrEqual(0.0, -1.0); - Validate.smallerOrEqual(0.0, Double.NEGATIVE_INFINITY); + Validate.smallerOrEqual(-1.0, 0.0); + Validate.smallerOrEqual(Double.NEGATIVE_INFINITY, 0.0); Validate.smallerOrEqual(0.0, 0.0); try { - Validate.smallerOrEqual(0.0, 1.0); + 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(0.0, Double.POSITIVE_INFINITY); + 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(0.0, Double.NaN); + 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(Double.NaN, 0.0); + 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()); @@ -1405,29 +1405,29 @@ public void testSmallerOrEqualDouble1() { @Test public void testSmallerOrEqualDouble2() { - Validate.smallerOrEqual(0.0, -1.0, "MSG"); - Validate.smallerOrEqual(0.0, Double.NEGATIVE_INFINITY, "MSG"); + 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(0.0, 1.0, "MSG"); + Validate.smallerOrEqual(1.0, 0.0, "MSG"); fail("Expecting IllegalArgumentException"); } catch (final IllegalArgumentException ex) { assertEquals("MSG", ex.getMessage()); } try { - Validate.smallerOrEqual(0.0, Double.POSITIVE_INFINITY, "MSG"); + Validate.smallerOrEqual(Double.POSITIVE_INFINITY, 0.0, "MSG"); fail("Expecting IllegalArgumentException"); } catch (final IllegalArgumentException ex) { assertEquals("MSG", ex.getMessage()); } try { - Validate.smallerOrEqual(0.0, Double.NaN, "MSG"); + Validate.smallerOrEqual(Double.NaN, 0.0, "MSG"); fail("Expecting IllegalArgumentException"); } catch (final IllegalArgumentException ex) { assertEquals("MSG", ex.getMessage()); } try { - Validate.smallerOrEqual(Double.NaN, 0.0, "MSG"); + Validate.smallerOrEqual(0.0, Double.NaN, "MSG"); fail("Expecting IllegalArgumentException"); } catch (final IllegalArgumentException ex) { assertEquals("MSG", ex.getMessage()); @@ -1439,7 +1439,7 @@ public void testSmallerOrEqualDouble2() { @Test public void testDifferentObject1() { - Validate.differentObj("a", "b"); + Validate.differentObj("b", "a"); try { Validate.differentObj("a", "a"); fail("Expecting IllegalArgumentException"); @@ -1450,7 +1450,7 @@ public void testDifferentObject1() { @Test public void testDifferentObject2() { - Validate.differentObj("a", "b", "MSG"); + Validate.differentObj("b", "a", "MSG"); try { Validate.differentObj("a", "a", "MSG"); fail("Expecting IllegalArgumentException"); @@ -1461,7 +1461,7 @@ public void testDifferentObject2() { @Test public void testDifferentLong1() { - Validate.different(0, 1); + Validate.different(1, 0); try { Validate.different(0, 0); fail("Expecting IllegalArgumentException"); @@ -1472,7 +1472,7 @@ public void testDifferentLong1() { @Test public void testDifferentLong2() { - Validate.different(0, 1, "MSG"); + Validate.different(1, 0, "MSG"); try { Validate.different(0, 0, "MSG"); fail("Expecting IllegalArgumentException"); @@ -1483,10 +1483,10 @@ public void testDifferentLong2() { @Test public void testDifferentDouble1() { - Validate.different(0.0, 1.0); - Validate.different(0.0, Double.NaN); - Validate.different(Double.NaN, 1.0); - Validate.different(Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY); + 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"); @@ -1503,10 +1503,10 @@ public void testDifferentDouble1() { @Test public void testDifferentDouble2() { - Validate.different(0.0, 1.0, "MSG"); - Validate.different(0.0, Double.NaN, "MSG"); - Validate.different(Double.NaN, 1.0, "MSG"); - Validate.different(Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, "MSG"); + 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"); @@ -1707,9 +1707,6 @@ public void testExclusiveBetweenDouble_withMessage() assertEquals("Error", e.getMessage()); } } - - //----------------------------------------------------------------------- - //----------------------------------------------------------------------- @Test public void testIsInstanceOf() { @@ -1763,9 +1760,6 @@ public void testIsInstanceOf_withMessageArgs() { } } - //----------------------------------------------------------------------- - //----------------------------------------------------------------------- - @Test public void testIsAssignable() { Validate.isAssignableFrom(CharSequence.class, String.class);