Java Assert Not Null assertNotNull(String message, Object object)

Here you can find the source of assertNotNull(String message, Object object)

Description

Asserts that an object isn't null.

License

Apache License

Parameter

Parameter Description
message the identifying message for the AssertionError ( <code>null</code> okay)
object Object to check or <code>null</code>

Declaration

public static void assertNotNull(String message, Object object) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**/*from w w  w .ja  v a 2  s .c  o  m*/
     * Asserts that an object isn't null. If it is an {@link AssertionError} is
     * thrown with the given message.
     * 
     * @param message
     *            the identifying message for the {@link AssertionError} (
     *            <code>null</code> okay)
     * @param object
     *            Object to check or <code>null</code>
     */
    public static void assertNotNull(String message, Object object) {
        assertTrue(message, object != null);
    }

    /**
     * Asserts that a condition is true. If it isn't it throws an
     * {@link AssertionError} with the given message.
     * 
     * @param message
     *            the identifying message for the {@link AssertionError} (
     *            <code>null</code> okay)
     * @param condition
     *            condition to be checked
     */
    public static void assertTrue(String message, boolean condition) {
        if (!condition)
            fail(message);
    }

    /**
     * Fails a test with the given message.
     * 
     * @param message
     *            the identifying message for the {@link AssertionError} (
     *            <code>null</code> okay)
     * @see AssertionError
     */
    public static void fail(String message) {
        throw new IllegalStateException(message == null ? "" : message);
    }
}

Related

  1. assertNotNull(Object... objects)
  2. assertNotNull(Object... params)
  3. assertNotNull(Object... params)
  4. assertNotNull(String errorMessage, Object... args)
  5. assertNotNull(String fieldName, Object object)
  6. assertNotNull(String message, Object val)
  7. assertNotNull(String variableName, Object value)
  8. assertNotNull(StringBuilder buffer)
  9. assertNotNull(T exception, Object... objects)