parent
2e3fa5c253
commit
77d187eefc
|
@ -22,6 +22,7 @@
|
|||
<body>
|
||||
|
||||
<release version="3.5" date="tba" description="tba">
|
||||
<action issue="LANG-1134" type="add" dev="chas" due-to="Alan Smithee">New methods for lang3.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>
|
||||
|
|
|
@ -45,6 +45,20 @@ import java.util.regex.Pattern;
|
|||
*/
|
||||
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 =
|
||||
|
@ -875,6 +889,757 @@ public class Validate {
|
|||
}
|
||||
}
|
||||
|
||||
// notNaN
|
||||
//---------------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* <p>Validates that the specified argument is not {@code NaN}; otherwise
|
||||
* throwing an exception.</p>
|
||||
*
|
||||
* <pre>Validate.notNaN(myDouble);</pre>
|
||||
*
|
||||
* <p>The message of the exception is "The validated value is not a
|
||||
* number".</p>
|
||||
*
|
||||
* @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.5
|
||||
*/
|
||||
public static void notNaN(final double value) {
|
||||
notNaN(value, DEFAULT_NOT_NAN_EX_MESSAGE);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Validates that the specified argument is not {@code NaN}; otherwise
|
||||
* throwing an exception with the specified message.</p>
|
||||
*
|
||||
* <pre>Validate.notNaN(myDouble, "The value must be a number");</pre>
|
||||
*
|
||||
* @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.5
|
||||
*/
|
||||
public static void notNaN(final double value, final String message, final Object... values) {
|
||||
if (Double.isNaN(value)) {
|
||||
throw new IllegalArgumentException(String.format(message, values));
|
||||
}
|
||||
}
|
||||
|
||||
// finite
|
||||
//---------------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* <p>Validates that the specified argument is not infinite or {@code NaN};
|
||||
* otherwise throwing an exception.</p>
|
||||
*
|
||||
* <pre>Validate.finite(myDouble);</pre>
|
||||
*
|
||||
* <p>The message of the exception is "The value is invalid: %f".</p>
|
||||
*
|
||||
* @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.5
|
||||
*/
|
||||
public static void finite(final double value) {
|
||||
finite(value, DEFAULT_FINITE_EX_MESSAGE, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Validates that the specified argument is not infinite or {@code NaN};
|
||||
* otherwise throwing an exception with the specified message.</p>
|
||||
*
|
||||
* <pre>Validate.finite(myDouble, "The argument must contain a numeric value");</pre>
|
||||
*
|
||||
* @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.5
|
||||
*/
|
||||
public static void finite(final double value, final String message, final Object... values) {
|
||||
if (Double.isNaN(value) || Double.isInfinite(value)) {
|
||||
throw new IllegalArgumentException(String.format(message, values));
|
||||
}
|
||||
}
|
||||
|
||||
// greater
|
||||
//---------------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* <p>Validates that the specified argument is strictly greater than a given
|
||||
* reference; otherwise throwing an exception.</p>
|
||||
*
|
||||
* <pre>Validate.greaterObj(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 #greaterObj(java.lang.Object, java.lang.Comparable, java.lang.String, java.lang.Object...)
|
||||
*
|
||||
* @since 3.5
|
||||
*/
|
||||
public static <T> void greaterObj(final Comparable<T> value, final T min) {
|
||||
greaterObj(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.greaterObj(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 #greaterObj(java.lang.Object, java.lang.Comparable)
|
||||
*
|
||||
* @since 3.5
|
||||
*/
|
||||
public static <T> void greaterObj(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.greaterOrEqualObj(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 #greaterOrEqualObj(java.lang.Object, java.lang.Comparable, java.lang.String, java.lang.Object...)
|
||||
*
|
||||
* @since 3.5
|
||||
*/
|
||||
public static <T> void greaterOrEqualObj(final Comparable<T> value, final T min) {
|
||||
greaterOrEqualObj(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.greaterOrEqualObj(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 #greaterOrEqualObj(java.lang.Object, java.lang.Comparable)
|
||||
*
|
||||
* @since 3.5
|
||||
*/
|
||||
public static <T> void greaterOrEqualObj(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.smallerObj(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 #smallerObj(java.lang.Object, java.lang.Comparable, java.lang.String, java.lang.Object...)
|
||||
*
|
||||
* @since 3.5
|
||||
*/
|
||||
public static <T> void smallerObj(final Comparable<T> value, final T max) {
|
||||
smallerObj(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.smallerObj(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 #smallerObj(java.lang.Object, java.lang.Comparable)
|
||||
*
|
||||
* @since 3.5
|
||||
*/
|
||||
public static <T> void smallerObj(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.smallerOrEqualObj(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 #smallerOrEqualObj(java.lang.Object, java.lang.Comparable, java.lang.String, java.lang.Object...)
|
||||
*
|
||||
* @since 3.5
|
||||
*/
|
||||
public static <T> void smallerOrEqualObj(final Comparable<T> value, final T max) {
|
||||
smallerOrEqualObj(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.smallerOrEqualObj(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 #smallerOrEqualObj(java.lang.Object, java.lang.Comparable)
|
||||
*
|
||||
* @since 3.5
|
||||
*/
|
||||
public static <T> void smallerOrEqualObj(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.compareTo(reference) != 0}</p>
|
||||
*
|
||||
* <pre>Validate.differentObj(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 differentObj(final Comparable<T> value, final T reference) {
|
||||
differentObj(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.compareTo(reference) != 0}</p>
|
||||
*
|
||||
* <pre>Validate.differentObj(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 differentObj(final Comparable<T> value, final T reference, final String message, final Object... values) {
|
||||
if (value.compareTo(reference) == 0) {
|
||||
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
|
||||
//---------------------------------------------------------------------------------
|
||||
|
||||
|
|
|
@ -831,6 +831,699 @@ public class ValidateTest {
|
|||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
@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("c", "b");
|
||||
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("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.greaterObj("c", "b", "MSG");
|
||||
try {
|
||||
Validate.greaterObj("b", "b", "MSG");
|
||||
fail("Expecting IllegalArgumentException");
|
||||
} catch (final IllegalArgumentException ex) {
|
||||
assertEquals("MSG", ex.getMessage());
|
||||
}
|
||||
try {
|
||||
Validate.greaterObj("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.greaterOrEqualObj("c", "b");
|
||||
Validate.greaterOrEqualObj("b", "b");
|
||||
try {
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGreaterOrEqualObject2() {
|
||||
Validate.greaterOrEqualObj("c", "b", "MSG");
|
||||
Validate.greaterOrEqualObj("b", "b", "MSG");
|
||||
try {
|
||||
Validate.greaterOrEqualObj("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.smallerObj("a", "b");
|
||||
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("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.smallerObj("a", "b", "MSG");
|
||||
try {
|
||||
Validate.smallerObj("b", "b", "MSG");
|
||||
fail("Expecting IllegalArgumentException");
|
||||
} catch (final IllegalArgumentException ex) {
|
||||
assertEquals("MSG", ex.getMessage());
|
||||
}
|
||||
try {
|
||||
Validate.smallerObj("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.smallerOrEqualObj("a", "b");
|
||||
Validate.smallerOrEqualObj("b", "b");
|
||||
try {
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSmallerOrEqualObject2() {
|
||||
Validate.smallerOrEqualObj("a", "b", "MSG");
|
||||
Validate.smallerOrEqualObj("b", "b", "MSG");
|
||||
try {
|
||||
Validate.smallerOrEqualObj("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.differentObj("b", "a");
|
||||
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("b", "a", "MSG");
|
||||
try {
|
||||
Validate.differentObj("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()
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue