001 /*
002 * Created on Dec 26, 2010
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
005 * the License. You may obtain a copy of the License at
006 *
007 * http://www.apache.org/licenses/LICENSE-2.0
008 *
009 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
010 * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
011 * specific language governing permissions and limitations under the License.
012 *
013 * Copyright @2010-2011 the original author or authors.
014 */
015 package org.fest.assertions.api;
016
017 /**
018 * Assertion methods for {@code Object}s.
019 * <p>
020 * To create a new instance of this class, invoke <code>{@link Assertions#assertThat(Object)}</code>.
021 * </p>
022 *
023 * @author Yvonne Wang
024 * @author Alex Ruiz
025 */
026 public class ObjectAssert extends AbstractAssert<ObjectAssert, Object> {
027
028 protected ObjectAssert(Object actual) {
029 super(actual, ObjectAssert.class);
030 }
031
032 /**
033 * Verifies that the actual {@code Object} is an instance of the given type.
034 * @param type the type to check the actual {@code Object} against.
035 * @return this assertion object.
036 * @throws NullPointerException if the given type is {@code null}.
037 * @throws AssertionError if the actual {@code Object} is {@code null}.
038 * @throws AssertionError if the actual {@code Object} is not an instance of the given type.
039 */
040 public ObjectAssert isInstanceOf(Class<?> type) {
041 objects.assertIsInstanceOf(info, actual, type);
042 return this;
043 }
044
045 /**
046 * Verifies that the actual {@code Object} is an instance of any of the given types.
047 * @param types the types to check the actual {@code Object} against.
048 * @return this assertion object.
049 * @throws AssertionError if the actual {@code Object} is {@code null}.
050 * @throws AssertionError if the actual {@code Object} is not an instance of any of the given types.
051 * @throws NullPointerException if the given array of types is {@code null}.
052 * @throws NullPointerException if the given array of types contains {@code null}s.
053 */
054 public ObjectAssert isInstanceOfAny(Class<?>...types) {
055 objects.assertIsInstanceOfAny(info, actual, types);
056 return this;
057 }
058 }