/** * <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); }
@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()); } }
/** * <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.</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.</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); }