Repository: commons-lang Updated Branches: refs/heads/master 64d820bff -> 09686fad4
Revert parts of LANG-1134 to polish the API after 3.5 Project: http://git-wip-us.apache.org/repos/asf/commons-lang/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-lang/commit/09686fad Tree: http://git-wip-us.apache.org/repos/asf/commons-lang/tree/09686fad Diff: http://git-wip-us.apache.org/repos/asf/commons-lang/diff/09686fad Branch: refs/heads/master Commit: 09686fad46d49016057bae8f02dc79f409b7bd10 Parents: 64d820b Author: Benedikt Ritter <brit...@apache.org> Authored: Mon Sep 19 11:46:19 2016 +0200 Committer: Benedikt Ritter <brit...@apache.org> Committed: Mon Sep 19 11:46:19 2016 +0200 ---------------------------------------------------------------------- src/changes/changes.xml | 2 +- .../java/org/apache/commons/lang3/Validate.java | 668 ------------------- .../org/apache/commons/lang3/ValidateTest.java | 612 ----------------- 3 files changed, 1 insertion(+), 1281 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/commons-lang/blob/09686fad/src/changes/changes.xml ---------------------------------------------------------------------- diff --git a/src/changes/changes.xml b/src/changes/changes.xml index d3a52fe..bc720f7 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -89,7 +89,7 @@ The <action> type attribute can be add,update,fix,remove. <action issue="LANG-1218" type="update" dev="ggregory" due-to="Ruslan Cheremin">EqualsBuilder.append(Object,Object) is too big to be inlined, which prevents whole builder to be scalarized</action> <action issue="LANG-1205" type="fix" dev="chas" due-to="pbrose">NumberUtils.createNumber() behaves inconsistently with NumberUtils.isNumber()</action> <action issue="LANG-1115" type="add" dev="chas" due-to="Jim Lloyd, Joe Ferner">Add support for varargs in ConstructorUtils, MemberUtils, and MethodUtils</action> - <action issue="LANG-1134" type="add" dev="chas" due-to="Alan Smithee">New methods for lang3.Validate</action> + <action issue="LANG-1134" type="add" dev="chas" due-to="Alan Smithee">Add methods to check numbers against NaN and inifinite to Validate</action> <action issue="LANG-1222" type="fix" dev="ggregory" due-to="Adam J.">Fix for incorrect comment on StringUtils.containsIgnoreCase method</action> <action issue="LANG-1221" type="fix" dev="ggregory" due-to="Pierre Templier">Fix typo on appendIfMissing javadoc</action> <action issue="LANG-1220" type="add" dev="kinow" due-to="Casey Scarborough">Add tests for missed branches in DateUtils</action> http://git-wip-us.apache.org/repos/asf/commons-lang/blob/09686fad/src/main/java/org/apache/commons/lang3/Validate.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/lang3/Validate.java b/src/main/java/org/apache/commons/lang3/Validate.java index b70ddd5..da20da4 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 class Validate { } } - // greater - //--------------------------------------------------------------------------------- - - /** - * <p>Validates that the specified argument is strictly greater than a given - * reference; otherwise throwing an exception.</p> - * - * <pre>Validate.greaterObject(myObject, refObject);</pre> - * - * <p>The message of the exception is "The value {@code value} is not - * greater than {@code min}".</p> - * - * @param <T> 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 <T> void greaterObject(final Comparable<T> value, final T min) { - greaterObject(value, min, DEFAULT_GREATER_EX_MESSAGE, value, min); - } - - /** - * <p>Validates that the specified argument is strictly greater than a given - * reference; otherwise throwing an exception with the specified message.</p> - * - * <pre>Validate.greaterObject(myObject, refObject, "The value must be greater than the reference");</pre> - * - * @param <T> 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 <T> void greaterObject(final Comparable<T> value, final T min, final String message, final Object... values) { - if (value.compareTo(min) <= 0) { - throw new IllegalArgumentException(String.format(message, values)); - } - } - - /** - * <p>Validates that the specified argument is strictly greater than a given - * reference; otherwise throwing an exception.</p> - * - * <pre>Validate.greater(myLong, 0);</pre> - * - * <p>The message of the exception is "The value {@code value} is not - * greater than {@code min}".</p> - * - * @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); - } - - /** - * <p>Validates that the specified argument is strictly greater than a given - * reference; otherwise throwing an exception with the specified message.</p> - * - * <pre>Validate.greater(myLong, 0);</pre> - * - * @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)); - } - } - - /** - * <p>Validates that the specified argument is strictly greater than a given - * reference; otherwise throwing an exception.</p> - * - * <p>If {@code min} or {@code value} is {@code NaN}, the test will fail and - * the exception will be thrown.</p> - * - * <pre>Validate.greater(myDouble, 0.0);</pre> - * - * <p>The message of the exception is "The value {@code value} is not - * greater than {@code min}".</p> - * - * @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); - } - - /** - * <p>Validates that the specified argument is strictly greater than a given - * reference; otherwise throwing an exception with the specified message.</p> - * - * <p>If {@code min} or {@code value} is {@code NaN}, the test will fail and - * the exception will be thrown.</p> - * - * <pre>Validate.greater(myDouble, 0.0);</pre> - * - * @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 - //--------------------------------------------------------------------------------- - - /** - * <p>Validates that the specified argument is greater than, or equal to, a - * given reference; otherwise throwing an exception.</p> - * - * <pre>Validate.greaterOrEqualObject(myObject, refObject);</pre> - * - * <p>The message of the exception is "The value {@code value} is not - * greater than or equal to {@code min}".</p> - * - * @param <T> 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 <T> void greaterOrEqualObject(final Comparable<T> value, final T min) { - greaterOrEqualObject(value, min, DEFAULT_GREATER_OR_EQUAL_EX_MESSAGE, value, min); - } - - /** - * <p>Validates that the specified argument is greater than, or equal to, a - * given reference; otherwise throwing an exception.</p> - * - * <pre>Validate.greaterOrEqualObject(myObject, refObject, "The value must be greater than the reference");</pre> - * - * @param <T> 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 <T> void greaterOrEqualObject(final Comparable<T> value, final T min, final String message, final Object... values) { - if (value.compareTo(min) < 0) { - throw new IllegalArgumentException(String.format(message, values)); - } - } - - /** - * <p>Validates that the specified argument is greater than, or equal to, a - * given reference; otherwise throwing an exception.</p> - * - * <pre>Validate.greaterOrEqual(myLong, 0);</pre> - * - * <p>The message of the exception is "The value {@code value} is not - * greater than or equal to {@code min}".</p> - * - * @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); - } - - /** - * <p>Validates that the specified argument is greater than, or equal to, a - * given reference; otherwise throwing an exception with the specified message.</p> - * - * <pre>Validate.greaterOrEqual(myLong, 0);</pre> - * - * @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)); - } - } - - /** - * <p>Validates that the specified argument is greater than, or equal to, a - * given reference; otherwise throwing an exception.</p> - * - * <p>If {@code min} or {@code value} is {@code NaN}, the test will fail and - * the exception will be thrown.</p> - * - * <pre>Validate.greaterOrEqual(myDouble, 0.0);</pre> - * - * <p>The message of the exception is "The value {@code value} is not - * greater than or equal to {@code min}".</p> - * - * @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); - } - - /** - * <p>Validates that the specified argument is greater than, or equal to, a - * given reference; otherwise throwing an exception with the specified message.</p> - * - * <p>If {@code min} or {@code value} is {@code NaN}, the test will fail and - * the exception will be thrown.</p> - * - * <pre>Validate.greaterOrEqual(myDouble, 0.0);</pre> - * - * @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 - //--------------------------------------------------------------------------------- - - /** - * <p>Validates that the specified argument is strictly smaller than a given - * reference; otherwise throwing an exception.</p> - * - * <pre>Validate.smallerObject(myObject, refObject);</pre> - * - * <p>The message of the exception is "The value {@code value} is not - * smaller than {@code max}".</p> - * - * @param <T> 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 <T> void smallerObject(final Comparable<T> value, final T max) { - smallerObject(value, max, DEFAULT_SMALLER_EX_MESSAGE, value, max); - } - - /** - * <p>Validates that the specified argument is strictly smaller than a given - * reference; otherwise throwing an exception with the specified message.</p> - * - * <pre>Validate.smallerObject(myObject, refObject, "The value must be greater than the reference");</pre> - * - * @param <T> 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 <T> void smallerObject(final Comparable<T> value, final T max, final String message, final Object... values) { - if (value.compareTo(max) >= 0) { - throw new IllegalArgumentException(String.format(message, values)); - } - } - - /** - * <p>Validates that the specified argument is strictly smaller than a given - * reference; otherwise throwing an exception.</p> - * - * <pre>Validate.smaller(myLong, 0);</pre> - * - * <p>The message of the exception is "The value {@code value} is not - * smaller than {@code max}".</p> - * - * @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); - } - - /** - * <p>Validates that the specified argument is strictly smaller than a given - * reference; otherwise throwing an exception with the specified message.</p> - * - * <pre>Validate.smaller(myLong, 0);</pre> - * - * @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)); - } - } - - /** - * <p>Validates that the specified argument is strictly smaller than a given - * reference; otherwise throwing an exception.</p> - * - * <p>If {@code min} or {@code value} is {@code NaN}, the test will fail and - * the exception will be thrown.</p> - * - * <pre>Validate.smaller(myDouble, 0.0);</pre> - * - * <p>The message of the exception is "The value {@code value} is not - * smaller than {@code max}".</p> - * - * @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); - } - - /** - * <p>Validates that the specified argument is strictly smaller than a given - * reference; otherwise throwing an exception with the specified message.</p> - * - * <p>If {@code min} or {@code value} is {@code NaN}, the test will fail and - * the exception will be thrown.</p> - * - * <pre>Validate.smaller(myDouble, 0.0);</pre> - * - * @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 - //--------------------------------------------------------------------------------- - - /** - * <p>Validates that the specified argument is smaller than, or equal to, a - * given reference; otherwise throwing an exception.</p> - * - * <pre>Validate.smallerOrEqualObject(myObject, refObject);</pre> - * - * <p>The message of the exception is "The value {@code value} is not - * smaller than or equal to {@code max}".</p> - * - * @param <T> 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 <T> void smallerOrEqualObject(final Comparable<T> value, final T max) { - smallerOrEqualObject(value, max, DEFAULT_SMALLER_OR_EQUAL_EX_MESSAGE, value, max); - } - - /** - * <p>Validates that the specified argument is smaller than, or equal to, a - * given reference; otherwise throwing an exception with the specified message.</p> - * - * <pre>Validate.smallerOrEqualObject(myObject, refObject, "The value must be greater than the reference");</pre> - * - * @param <T> 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 <T> void smallerOrEqualObject(final Comparable<T> value, final T max, final String message, final Object... values) { - if (value.compareTo(max) > 0) { - throw new IllegalArgumentException(String.format(message, values)); - } - } - - /** - * <p>Validates that the specified argument is smaller than, or equal to, a - * given reference; otherwise throwing an exception.</p> - * - * <pre>Validate.smallerOrEqual(myLong, 0);</pre> - * - * <p>The message of the exception is "The value {@code value} is not - * smaller than or equal to {@code max}".</p> - * - * @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); - } - - /** - * <p>Validates that the specified argument is smaller than, or equal to, a - * given reference; otherwise throwing an exception with the specified message.</p> - * - * <pre>Validate.smallerOrEqual(myLong, 0);</pre> - * - * @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)); - } - } - - /** - * <p>Validates that the specified argument is smaller than, or equal to, a - * given reference; otherwise throwing an exception.</p> - * - * <p>If {@code min} or {@code value} is {@code NaN}, the test will fail and - * the exception will be thrown.</p> - * - * <pre>Validate.smallerOrEqual(myDouble, 0.0);</pre> - * - * <p>The message of the exception is "The value {@code value} is not - * smaller than or equal to {@code max}".</p> - * - * @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); - } - - /** - * <p>Validates that the specified argument is smaller than, or equal to, a - * given reference; otherwise throwing an exception with the specified message.</p> - * - * <p>If {@code min} or {@code value} is {@code NaN}, the test will fail and - * the exception will be thrown.</p> - * - * <pre>Validate.smallerOrEqual(myDouble, 0.0);</pre> - * - * @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 - //--------------------------------------------------------------------------------- - - /** - * <p>Validates that the specified argument is different from a given value - * (reference); otherwise throwing an exception.</p> - * - * <p>Two objects are considered different if - * {@code value.equals(reference) == false}</p> - * - * <pre>Validate.differentObject(myObject, refObject);</pre> - * - * <p>The message of the exception is "The value {@code value} is - * invalid".</p> - * - * @param <T> 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 <T> void differentObject(final T value, final T reference) { - differentObject(value, reference, DEFAULT_DIFFERENT_EX_MESSAGE, value); - } - - /** - * <p>Validates that the specified argument is different from a given value - * (reference); otherwise throwing an exception with the specified message.</p> - * - * <p>Two objects are considered different if - * {@code value.equals(reference) == false}</p> - * - * <pre>Validate.differentObject(myObject, refObject, "The value is invalid");</pre> - * - * @param <T> 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 <T> 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)); - } - } - - /** - * <p>Validates that the specified argument is not equal to a given value - * (reference); otherwise throwing an exception.</p> - * - * <pre>Validate.different(myLong, 0);</pre> - * - * <p>The message of the exception is "The value {@code value} is - * invalid".</p> - * - * @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); - } - - /** - * <p>Validates that the specified argument is not equal to a given value - * (reference); otherwise throwing an exception with the specified message.</p> - * - * <pre>Validate.different(myLong, 0, "The value is invalid");</pre> - * - * @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)); - } - } - - /** - * <p>Validates that the specified argument is not equal to a given value - * (reference); otherwise throwing an exception.</p> - * - * <p>If {@code value} or {@code reference} is {@code NaN}, no exception will be thrown.</p> - * - * <pre>Validate.different(myDouble, 0.0);</pre> - * - * <p>The message of the exception is "The value {@code value} is - * invalid".</p> - * - * @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); - } - - /** - * <p>Validates that the specified argument is not equal to a given value - * (reference); otherwise throwing an exception with the specified message.</p> - * - * <p>If {@code value} or {@code reference} is {@code NaN}, no exception will be thrown.</p> - * - * <pre>Validate.different(myDouble, 0.0, "The value is invalid");</pre> - * - * @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 //--------------------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/commons-lang/blob/09686fad/src/test/java/org/apache/commons/lang3/ValidateTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/lang3/ValidateTest.java b/src/test/java/org/apache/commons/lang3/ValidateTest.java index bb294bb..cd84ec3 100644 --- a/src/test/java/org/apache/commons/lang3/ValidateTest.java +++ b/src/test/java/org/apache/commons/lang3/ValidateTest.java @@ -913,618 +913,6 @@ public class ValidateTest { //----------------------------------------------------------------------- @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() { Validate.inclusiveBetween("a", "c", "b");