/** * Verifies that the actual value does not have the same class as the given object. * * @param info contains information about the assertion. * @param actual the given object. * @param other the object to check type against. * @throws AssertionError if the actual has the same type has the given object. * @throws NullPointerException if the actual value is null. * @throws NullPointerException if the given object is null. */ public void assertDoesNotHaveSameClassAs(AssertionInfo info, Object actual, Object other) { assertNotNull(info, actual); if (other == null) throw new NullPointerException("The given object should not be null"); Class<?> actualClass = actual.getClass(); Class<?> otherClass = other.getClass(); if (!actualClass.equals(otherClass)) return; throw failures.failure(info, shouldNotHaveSameClass(actual, other)); }
/** * Verifies that the actual value is not exactly a instance of given type. * * @param info contains information about the assertion. * @param actual the given object. * @param type the type to check the actual value against. * @throws AssertionError if the actual is exactly a instance of given type. * @throws NullPointerException if the actual value is null. * @throws NullPointerException if the given object is null. */ public void assertIsNotExactlyInstanceOf(AssertionInfo info, Object actual, Class<?> type) { assertNotNull(info, actual); if (type == null) throw new NullPointerException("The given type should not be null"); Class<?> current = actual.getClass(); if (!type.equals(current)) return; throw failures.failure(info, shouldNotBeExactlyInstance(actual, type)); }
/** * Verifies that the given object is not an instance of any of the given types. * * @param info contains information about the assertion. * @param actual the given object. * @param types the types to check the given object against. * @throws NullPointerException if the given array is {@code null}. * @throws IllegalArgumentException if the given array is empty. * @throws NullPointerException if the given array has {@code null} elements. * @throws AssertionError if the given object is {@code null}. * @throws AssertionError if the given object is an instance of any of the given types. */ public void assertIsNotInstanceOfAny(AssertionInfo info, Object actual, Class<?>[] types) { checkIsNotNullAndIsNotEmpty(types); assertNotNull(info, actual); boolean found = false; for (Class<?> type : types) { if (type == null) { String format = "The given array of types:<%s> should not have null elements"; throw new NullPointerException(String.format(format, toStringOf(types))); } if (type.isInstance(actual)) { found = true; break; } } if (!found) return; throw failures.failure(info, shouldNotBeInstanceOfAny(actual, types)); }
/** * Verifies that the given object is not an instance of the given type. * * @param info contains information about the assertion. * @param actual the given object. * @param type the type to check the given object against. * @throws NullPointerException if the given type is {@code null}. * @throws AssertionError if the given object is {@code null}. * @throws AssertionError if the given object is an instance of the given type. */ public void assertIsNotInstanceOf(AssertionInfo info, Object actual, Class<?> type) { if (type == null) throw new NullPointerException("The given type should not be null"); assertNotNull(info, actual); if (!type.isInstance(actual)) return; throw failures.failure(info, shouldNotBeInstance(actual, type)); }