Java Assert assertNotBlank(final String value, final String exceptionMessage)

Here you can find the source of assertNotBlank(final String value, final String exceptionMessage)

Description

Assert that the given value is not blank.

License

Open Source License

Parameter

Parameter Description
value the value to assert
exceptionMessage the exception message

Exception

Parameter Description
IllegalArgumentException if the value is null or empty

Return

the value to assert

Declaration

public static String assertNotBlank(final String value, final String exceptionMessage) 

Method Source Code

//package com.java2s;

public class Main {
    /**//from  w ww.j  a  va2  s. co m
     * Assert that the given value is not blank. If the value is blank,
     * an {@code IllegalArgumentException} will be thrown.
     * 
     * @param value the value to assert
     * @param exceptionMessage the exception message
     * @throws IllegalArgumentException if the value is null or empty
     * @return the value to assert
     */
    public static String assertNotBlank(final String value, final String exceptionMessage) {
        if (notBlank(value)) {
            return value;
        }
        throw new IllegalArgumentException(exceptionMessage);
    }

    /**
     * Check whether the string is not blank.
     * 
     * @param string the string to check
     * @return true if the string is not blank
     */
    public static boolean notBlank(final String string) {
        return string != null && !string.trim().isEmpty();
    }
}

Related

  1. assertNonFatal(boolean test, String msg)
  2. assertNonNegative(int field, String fieldName)
  3. assertNonZero(int i, String fieldName)
  4. assertNoSlash(final String ofString)
  5. assertNotBlank(final String arg, final String message)
  6. assertNotBlank(final String... strings)
  7. assertNotBlankOrThrowException(final String... strings)
  8. assertNotEmpty(final String str)
  9. assertNotEmpty(String string, String exceptionMessageTitle)