Package org.fest.assertions.internal
Class Objects
java.lang.Object
org.fest.assertions.internal.Objects
Reusable assertions for
Object
s.- Author:
- Yvonne Wang, Alex Ruiz, Nicolas François, Mikhail Mazursky
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
assertDoesNotHaveSameClassAs
(AssertionInfo info, Object actual, Object other) Verifies that the actual value does not have the same class as the given object.void
assertEqual
(AssertionInfo info, Object actual, Object expected) Asserts that two objects are equal.void
assertHasSameClassAs
(AssertionInfo info, Object actual, Object other) Verifies that the actual value has the same class as the given object.void
assertIsExactlyInstanceOf
(AssertionInfo info, Object actual, Class<?> type) Verifies that the actual value is exactly a instance of given type.<A> void
assertIsIn
(AssertionInfo info, A actual, Iterable<? extends A> values) Asserts that the given object is present in the given collection.void
assertIsIn
(AssertionInfo info, Object actual, Object[] values) Asserts that the given object is present in the given array.void
assertIsInstanceOf
(AssertionInfo info, Object actual, Class<?> type) Verifies that the given object is an instance of the given type.void
assertIsInstanceOfAny
(AssertionInfo info, Object actual, Class<?>[] types) Verifies that the given object is an instance of any of the given types.<A> void
assertIsLenientEqualsToByAcceptingFields
(AssertionInfo info, A actual, A other, String... fields) Assert that the given object is lenient equals to other object by comparing given fields value only.<A> void
assertIsLenientEqualsToByIgnoringFields
(AssertionInfo info, A actual, A other, String... fields) Assert that the given object is lenient equals to the other by comparing all fields (including inherited fields) unless given ignored ones.<A> void
assertIsLenientEqualsToByIgnoringNullFields
(AssertionInfo info, A actual, A other) Assert that the given object is lenient equals by ignoring null fields value on other object (including inherited fields).void
assertIsNotExactlyInstanceOf
(AssertionInfo info, Object actual, Class<?> type) Verifies that the actual value is not exactly a instance of given type.<A> void
assertIsNotIn
(AssertionInfo info, A actual, Iterable<? extends A> values) Asserts that the given object is not present in the given collection.void
assertIsNotIn
(AssertionInfo info, Object actual, Object[] values) Asserts that the given object is not present in the given array.void
assertIsNotInstanceOf
(AssertionInfo info, Object actual, Class<?> type) Verifies that the given object is not an instance of the given type.void
assertIsNotInstanceOfAny
(AssertionInfo info, Object actual, Class<?>[] types) Verifies that the given object is not an instance of any of the given types.void
assertIsNotOfAnyClassIn
(AssertionInfo info, Object actual, Class<?>[] types) Verifies that the actual value type is not in given types.void
assertIsOfAnyClassIn
(AssertionInfo info, Object actual, Class<?>[] types) Verifies that the actual value type is in given types.void
assertNotEqual
(AssertionInfo info, Object actual, Object other) Asserts that two objects are not equal.void
assertNotNull
(AssertionInfo info, Object actual) Asserts that the given object is notnull
.void
assertNotSame
(AssertionInfo info, Object actual, Object other) Asserts that two objects do not refer to the same object.void
assertNull
(AssertionInfo info, Object actual) Asserts that the given object isnull
.void
assertSame
(AssertionInfo info, Object actual, Object expected) Asserts that two objects refer to the same object.Comparator
<?> static Objects
instance()
Returns the singleton instance of this class based onStandardComparisonStrategy
.
-
Constructor Details
-
Objects
-
-
Method Details
-
instance
Returns the singleton instance of this class based onStandardComparisonStrategy
.- Returns:
- the singleton instance of this class based on
StandardComparisonStrategy
.
-
getComparator
-
assertIsInstanceOf
Verifies that the given object is an instance of the given type.- Parameters:
info
- contains information about the assertion.actual
- the given object.type
- the type to check the given object against.- Throws:
NullPointerException
- if the given type isnull
.AssertionError
- if the given object isnull
.AssertionError
- if the given object is not an instance of the given type.
-
assertIsInstanceOfAny
Verifies that the given object is an instance of any of the given types.- Parameters:
info
- contains information about the assertion.actual
- the given object.types
- the types to check the given object against.- Throws:
NullPointerException
- if the given array isnull
.IllegalArgumentException
- if the given array is empty.NullPointerException
- if the given array hasnull
elements.AssertionError
- if the given object isnull
.AssertionError
- if the given object is not an instance of any of the given types.
-
assertIsNotInstanceOf
Verifies that the given object is not an instance of the given type.- Parameters:
info
- contains information about the assertion.actual
- the given object.type
- the type to check the given object against.- Throws:
NullPointerException
- if the given type isnull
.AssertionError
- if the given object isnull
.AssertionError
- if the given object is an instance of the given type.
-
assertIsNotInstanceOfAny
Verifies that the given object is not an instance of any of the given types.- Parameters:
info
- contains information about the assertion.actual
- the given object.types
- the types to check the given object against.- Throws:
NullPointerException
- if the given array isnull
.IllegalArgumentException
- if the given array is empty.NullPointerException
- if the given array hasnull
elements.AssertionError
- if the given object isnull
.AssertionError
- if the given object is an instance of any of the given types.
-
assertHasSameClassAs
Verifies that the actual value has the same class as the given object.- Parameters:
info
- contains information about the assertion.actual
- the given object.- Throws:
AssertionError
- if the actual has not the same type has the given object.NullPointerException
- if the actual value is null.NullPointerException
- if the given object is null.
-
assertDoesNotHaveSameClassAs
Verifies that the actual value does not have the same class as the given object.- Parameters:
info
- contains information about the assertion.actual
- the given object.other
- the object to check type against.- Throws:
AssertionError
- if the actual has the same type has the given object.NullPointerException
- if the actual value is null.NullPointerException
- if the given object is null.
-
assertIsExactlyInstanceOf
Verifies that the actual value is exactly a instance of given type.- Parameters:
info
- contains information about the assertion.actual
- the given object.type
- the type to check the actual value against.- Throws:
AssertionError
- if the actual is not exactly a instance of given type.NullPointerException
- if the actual value is null.NullPointerException
- if the given object is null.
-
assertIsNotExactlyInstanceOf
Verifies that the actual value is not exactly a instance of given type.- Parameters:
info
- contains information about the assertion.actual
- the given object.type
- the type to check the actual value against.- Throws:
AssertionError
- if the actual is exactly a instance of given type.NullPointerException
- if the actual value is null.NullPointerException
- if the given object is null.
-
assertIsOfAnyClassIn
Verifies that the actual value type is in given types.- Parameters:
info
- contains information about the assertion.actual
- the given object.types
- the types to check the actual value against.- Throws:
AssertionError
- if the actual value type is in given type.NullPointerException
- if the actual value is null.NullPointerException
- if the given types is null.
-
assertIsNotOfAnyClassIn
Verifies that the actual value type is not in given types.- Parameters:
info
- contains information about the assertion.actual
- the given object.types
- the types to check the actual value against.- Throws:
AssertionError
- if the actual value type is in given type.NullPointerException
- if the actual value is null.NullPointerException
- if the given types is null.
-
assertEqual
Asserts that two objects are equal.- Parameters:
info
- contains information about the assertion.actual
- the "actual" object.expected
- the "expected" object.- Throws:
AssertionError
- ifactual
is not equal toexpected
. This method will throw aorg.junit.ComparisonFailure
instead if JUnit is in the classpath and the given objects are not equal.
-
assertNotEqual
Asserts that two objects are not equal.- Parameters:
info
- contains information about the assertion.actual
- the given object.other
- the object to compareactual
to.- Throws:
AssertionError
- ifactual
is equal toother
.
-
assertNull
Asserts that the given object isnull
.- Parameters:
info
- contains information about the assertion.actual
- the given object.- Throws:
AssertionError
- if the given object is notnull
.
-
assertNotNull
Asserts that the given object is notnull
.- Parameters:
info
- contains information about the assertion.actual
- the given object.- Throws:
AssertionError
- if the given object isnull
.
-
assertSame
Asserts that two objects refer to the same object.- Parameters:
info
- contains information about the assertion.actual
- the given object.expected
- the expected object.- Throws:
AssertionError
- if the given objects do not refer to the same object.
-
assertNotSame
Asserts that two objects do not refer to the same object.- Parameters:
info
- contains information about the assertion.actual
- the given object.other
- the object to compareactual
to.- Throws:
AssertionError
- if the given objects refer to the same object.
-
assertIsIn
Asserts that the given object is present in the given array.- Parameters:
info
- contains information about the assertion.actual
- the given object.values
- the given array.- Throws:
NullPointerException
- if the given array isnull
.IllegalArgumentException
- if the given array is empty.AssertionError
- if the given object is not present in the given array.
-
assertIsNotIn
Asserts that the given object is not present in the given array.- Parameters:
info
- contains information about the assertion.actual
- the given object.values
- the given array.- Throws:
NullPointerException
- if the given array isnull
.IllegalArgumentException
- if the given array is empty.AssertionError
- if the given object is present in the given array.
-
assertIsIn
Asserts that the given object is present in the given collection.- Parameters:
info
- contains information about the assertion.actual
- the given object.values
- the given iterable.- Throws:
NullPointerException
- if the given collection isnull
.IllegalArgumentException
- if the given collection is empty.AssertionError
- if the given object is not present in the given collection.
-
assertIsNotIn
Asserts that the given object is not present in the given collection.- Parameters:
info
- contains information about the assertion.actual
- the given object.values
- the given collection.- Throws:
NullPointerException
- if the given iterable isnull
.IllegalArgumentException
- if the given collection is empty.AssertionError
- if the given object is present in the given collection.
-
assertIsLenientEqualsToByIgnoringNullFields
Assert that the given object is lenient equals by ignoring null fields value on other object (including inherited fields).- Parameters:
info
- contains information about the assertion.actual
- the given object.other
- the object to compareactual
to.- Throws:
NullPointerException
- if the actual type isnull
.NullPointerException
- if the other type isnull
.AssertionError
- if the actual and the given object are not lenient equals.AssertionError
- if the other object is not an instance of the actual type.
-
assertIsLenientEqualsToByAcceptingFields
public <A> void assertIsLenientEqualsToByAcceptingFields(AssertionInfo info, A actual, A other, String... fields) Assert that the given object is lenient equals to other object by comparing given fields value only.- Parameters:
info
- contains information about the assertion.actual
- the given object.other
- the object to compareactual
to.fields
- accepted fields- Throws:
NullPointerException
- if the other type isnull
.AssertionError
- if actual isnull
.AssertionError
- if the actual and the given object are not lenient equals.AssertionError
- if the other object is not an instance of the actual type.org.fest.util.IntrospectionError
- if a field does not exist in actual.
-
assertIsLenientEqualsToByIgnoringFields
public <A> void assertIsLenientEqualsToByIgnoringFields(AssertionInfo info, A actual, A other, String... fields) Assert that the given object is lenient equals to the other by comparing all fields (including inherited fields) unless given ignored ones.- Parameters:
info
- contains information about the assertion.actual
- the given object.other
- the object to compareactual
to.fields
- the fields to ignore in comparison- Throws:
NullPointerException
- if the other type isnull
.AssertionError
- if actual isnull
.AssertionError
- if the actual and the given object are not lenient equals.AssertionError
- if the other object is not an instance of the actual type.
-