Java Assert assertNotBlank(final String arg, final String message)

Here you can find the source of assertNotBlank(final String arg, final String message)

Description

Throws an IllegalArgumentException with the given message if null or blank.

License

Open Source License

Parameter

Parameter Description
arg the string to test
message the message to send back if the string is null or empty

Declaration

public static final void assertNotBlank(final String arg, final String message) 

Method Source Code

//package com.java2s;
/*/*from  w  w w  .  j a v a 2  s .c  om*/
 * Copyright (c) 2006 Stephan D. Cote' - All rights reserved.
 * 
 * This program and the accompanying materials are made available under the 
 * terms of the MIT License which accompanies this distribution, and is 
 * available at http://creativecommons.org/licenses/MIT/
 *
 * Contributors:
 *   Stephan D. Cote 
 *      - Initial concept and implementation
 */

public class Main {
    /**
     * Throws an IllegalArgumentException with the given message if null or blank.
     *
     * @param arg the string to test
     * @param message the message to send back if the string is null or empty
     */
    public static final void assertNotBlank(final String arg, final String message) {
        if (arg == null) {
            throw new IllegalArgumentException("Null argument not allowed: " + message);
        }

        if (arg.trim().equals("")) {
            throw new IllegalArgumentException("Blank argument not allowed: " + message);
        }
    }
}

Related

  1. assertNonEmpty(String s, String name)
  2. assertNonFatal(boolean test, String msg)
  3. assertNonNegative(int field, String fieldName)
  4. assertNonZero(int i, String fieldName)
  5. assertNoSlash(final String ofString)
  6. assertNotBlank(final String value, final String exceptionMessage)
  7. assertNotBlank(final String... strings)
  8. assertNotBlankOrThrowException(final String... strings)
  9. assertNotEmpty(final String str)