Java Assert assertInstanceOf(Object obj, Class expClass)

Here you can find the source of assertInstanceOf(Object obj, Class expClass)

Description

Checks if the passed object is of the class specified, null values are ignored

License

Open Source License

Declaration

public static void assertInstanceOf(Object obj, Class<?> expClass) 

Method Source Code

//package com.java2s;
/**/*  w w  w  .  ja v  a2 s  . c o  m*/
 * <copyright>
 *
 * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *   Martin Taal - Initial API and implementation
 *
 * </copyright>
 *
 * $Id: AssertUtil.java,v 1.7 2009/03/30 07:53:04 mtaal Exp $
 */

public class Main {
    /**
     * Checks if the passed object is of the class specified, null values are ignored
     */
    public static void assertInstanceOf(Object obj, Class<?> expClass) {
        if (obj == null)
            return;
        if (!(expClass.isAssignableFrom(obj.getClass()))) {
            throw new AssertionError("Expected class: "
                    + expClass.getName() + " but object has class: "
                    + obj.getClass().getName());
        }
    }
}

Related

  1. assertIndex(int index, String msg)
  2. assertInputNotEmpty(final String input, final String message)
  3. assertInstance(final Object object, final Class c)
  4. assertInstance(Object object, Class c)
  5. assertInstanceOf(Object obj, Class classType)
  6. assertInstanceOf(Object object, Class expectClass)
  7. assertIntegerGreaterThanZero(long number, String name)
  8. assertIntegerNotNegative(String message, int num)
  9. assertion(boolean isTrue, String reason)