Java Assert assertStringNotEmpty(String str, String name)

Here you can find the source of assertStringNotEmpty(String str, String name)

Description

Check if the string is empty.

License

Open Source License

Parameter

Parameter Description
str the string to check.
name the string's name.

Exception

Parameter Description
IllegalArgumentException if the object is empty.

Declaration

static void assertStringNotEmpty(String str, String name) 

Method Source Code

//package com.java2s;

public class Main {
    /**/*from   w w  w  .j  a v  a2 s  .c om*/
     * Check if the string is empty.
     * @param str
     *            the string to check.
     * @param name
     *            the string's name.
     * @throws IllegalArgumentException
     *             if the object is empty.
     */
    static void assertStringNotEmpty(String str, String name) {
        assertObjectNotNull(str, name);
        if (str.trim().length() == 0) {
            throw new IllegalArgumentException("the string " + name
                    + " should not be empty.");
        }
    }

    /**
     * Check if the object is null.
     * @param obj
     *            the object to check.
     * @param name
     *            the object's name
     * @throws IllegalArgumentException
     *             if the object is null.
     */
    static void assertObjectNotNull(Object obj, String name) {
        if (obj == null) {
            throw new IllegalArgumentException("the object " + name
                    + " should not be null.");
        }
    }
}

Related

  1. assertSplit(final String text, final int length)
  2. assertSquare(double[]... d)
  3. assertState(boolean expression)
  4. assertStringMatch(String first, String second)
  5. assertStringNotEmpty(String str, String name)
  6. assertStringNotEmpty(String string, String fieldName)
  7. assertTesting()
  8. assertThrows(Class exception, Runnable action)
  9. assertTwoParameters(Class clz, String method, double... args)