Java Assert Null assertObjectNullOrIsInstance(Object obj, Class expectedType, String name)

Here you can find the source of assertObjectNullOrIsInstance(Object obj, Class expectedType, String name)

Description

Check if the given object is an instance of the expected class.

License

Open Source License

Parameter

Parameter Description
obj the given object to check.
expectedType the expected class.
name the name to identify the object.

Exception

Parameter Description
IllegalArgumentException if the given object is null or is not an instance of the expected class.

Declaration

static void assertObjectNullOrIsInstance(Object obj,
        Class expectedType, String name) 

Method Source Code

//package com.java2s;

public class Main {
    /**//from w  ww  .j  a  v a  2 s  . co m
     * Check if the given object is an instance of the expected class.
     *
     * @param obj          the given object to check.
     * @param expectedType the expected class.
     * @param name         the name to identify the object.
     *
     * @throws IllegalArgumentException if the given object is null or is not an instance of the expected class.
     */
    static void assertObjectNullOrIsInstance(Object obj,
            Class expectedType, String name) {
        if (obj != null && !expectedType.isInstance(obj)) {
            throw new IllegalArgumentException(name + " of type ["
                    + obj.getClass().getName()
                    + "] should be an instance of "
                    + expectedType.getName());
        }
    }
}

Related

  1. assertNull(Object object, String message)
  2. assertNull(String message, Object object)
  3. assertNull(String message, Object object)
  4. assertNull(String message, Object val)
  5. assertNull(String string, Object obj)