public class Objects extends Object
Object
s.Modifier and Type | Class and Description |
---|---|
static class |
Objects.ByFieldsComparison |
Constructor and Description |
---|
Objects(ComparisonStrategy comparisonStrategy) |
Modifier and Type | Method and Description |
---|---|
boolean |
areEqualToComparingOnlyGivenFields(Object actual,
Object other,
Map<String,Comparator<?>> comparatorByPropertyOrField,
TypeComparators comparatorByType,
String... fields) |
boolean |
areEqualToIgnoringGivenFields(Object actual,
Object other,
Map<String,Comparator<?>> comparatorByPropertyOrField,
TypeComparators comparatorByType,
String... fields) |
void |
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.
|
<A> void |
assertHasAllNullFieldsOrPropertiesExcept(AssertionInfo info,
A actual,
String... propertiesOrFieldsToIgnore)
Asserts that the given object has null fields except the given ones.
|
<A> void |
assertHasFieldOrProperty(AssertionInfo info,
A actual,
String name) |
<A> void |
assertHasFieldOrPropertyWithValue(AssertionInfo info,
A actual,
String name,
Object expectedValue) |
<A> void |
assertHasNoNullFieldsOrPropertiesExcept(AssertionInfo info,
A actual,
String... propertiesOrFieldsToIgnore)
Assert that the given object has no null fields except the given ones.
|
void |
assertHasSameClassAs(AssertionInfo info,
Object actual,
Object other)
Verifies that the actual value has the same class as the given object.
|
<A> void |
assertHasSameHashCodeAs(AssertionInfo info,
A actual,
Object other)
Asserts that the actual object has the same hashCode as the given object.
|
void |
assertHasToString(AssertionInfo info,
Object actual,
String expectedToString) |
<A> void |
assertIsEqualToComparingFieldByFieldRecursively(AssertionInfo info,
Object actual,
Object other,
Map<String,Comparator<?>> comparatorByPropertyOrField,
TypeComparators comparatorByType)
Assert that the given object is "deeply" equals to other by comparing all fields recursively.
|
<A> void |
assertIsEqualToComparingOnlyGivenFields(AssertionInfo info,
A actual,
A other,
Map<String,Comparator<?>> comparatorByPropertyOrField,
TypeComparators comparatorByType,
String... fields)
Assert that the given object is lenient equals to other object by comparing given fields value only.
|
<A> void |
assertIsEqualToIgnoringGivenFields(AssertionInfo info,
A actual,
A other,
Map<String,Comparator<?>> comparatorByPropertyOrField,
TypeComparators comparatorByType,
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 |
assertIsEqualToIgnoringNullFields(AssertionInfo info,
A actual,
A other,
Map<String,Comparator<?>> comparatorByPropertyOrField,
TypeComparators comparatorByType)
Assert that the given object is lenient equals by ignoring null fields value on other object (including inherited
fields).
|
void |
assertIsExactlyInstanceOf(AssertionInfo info,
Object actual,
Class<?> type)
Verifies that the actual value is exactly an instance of given type.
|
void |
assertIsIn(AssertionInfo info,
Object actual,
Iterable<?> 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.
|
void |
assertIsNotExactlyInstanceOf(AssertionInfo info,
Object actual,
Class<?> type)
Verifies that the actual value is not exactly an instance of given type.
|
void |
assertIsNotIn(AssertionInfo info,
Object actual,
Iterable<?> 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 not
null . |
void |
assertNotNull(AssertionInfo info,
Object actual,
String label)
Asserts that the given object is not
null . |
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 is
null . |
void |
assertSame(AssertionInfo info,
Object actual,
Object expected)
Asserts that two objects refer to the same object.
|
Comparator<?> |
getComparator() |
ComparisonStrategy |
getComparisonStrategy() |
static Set<Field> |
getDeclaredFieldsIncludingInherited(Class<?> clazz)
Returns the declared fields of given class and its superclasses stopping at superclass in
java.lang
package whose fields are not included. |
Failures |
getFailures() |
static Objects |
instance()
Returns the singleton instance of this class based on
StandardComparisonStrategy . |
public Objects(ComparisonStrategy comparisonStrategy)
public static Objects instance()
StandardComparisonStrategy
.StandardComparisonStrategy
.public Comparator<?> getComparator()
public ComparisonStrategy getComparisonStrategy()
public Failures getFailures()
public void assertIsInstanceOf(AssertionInfo info, Object actual, Class<?> type)
info
- contains information about the assertion.actual
- the given object.type
- the type to check the given object against.NullPointerException
- if the given type is null
.AssertionError
- if the given object is null
.AssertionError
- if the given object is not an instance of the given type.public void assertIsInstanceOfAny(AssertionInfo info, Object actual, Class<?>[] types)
info
- contains information about the assertion.actual
- the given object.types
- the types to check the given object against.NullPointerException
- if the given array is null
.IllegalArgumentException
- if the given array is empty.NullPointerException
- if the given array has null
elements.AssertionError
- if the given object is null
.AssertionError
- if the given object is not an instance of any of the given types.public void assertIsNotInstanceOf(AssertionInfo info, Object actual, Class<?> type)
info
- contains information about the assertion.actual
- the given object.type
- the type to check the given object against.NullPointerException
- if the given type is null
.AssertionError
- if the given object is null
.AssertionError
- if the given object is an instance of the given type.public void assertIsNotInstanceOfAny(AssertionInfo info, Object actual, Class<?>[] types)
info
- contains information about the assertion.actual
- the given object.types
- the types to check the given object against.NullPointerException
- if the given array is null
.IllegalArgumentException
- if the given array is empty.NullPointerException
- if the given array has null
elements.AssertionError
- if the given object is null
.AssertionError
- if the given object is an instance of any of the given types.public void assertHasSameClassAs(AssertionInfo info, Object actual, Object other)
info
- contains information about the assertion.actual
- the given object.other
- the object to check type against.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.public void assertDoesNotHaveSameClassAs(AssertionInfo info, Object actual, Object other)
info
- contains information about the assertion.actual
- the given object.other
- the object to check type against.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.public void assertIsExactlyInstanceOf(AssertionInfo info, Object actual, Class<?> type)
info
- contains information about the assertion.actual
- the given object.type
- the type to check the actual value against.AssertionError
- if the actual is not exactly an instance of given type.NullPointerException
- if the actual value is null.NullPointerException
- if the given object is null.public void assertIsNotExactlyInstanceOf(AssertionInfo info, Object actual, Class<?> type)
info
- contains information about the assertion.actual
- the given object.type
- the type to check the actual value against.AssertionError
- if the actual is exactly an instance of given type.NullPointerException
- if the actual value is null.NullPointerException
- if the given object is null.public void assertIsOfAnyClassIn(AssertionInfo info, Object actual, Class<?>[] types)
info
- contains information about the assertion.actual
- the given object.types
- the types to check the actual value against.AssertionError
- if the actual value type is in given type.NullPointerException
- if the actual value is null.NullPointerException
- if the given types is null.public void assertIsNotOfAnyClassIn(AssertionInfo info, Object actual, Class<?>[] types)
info
- contains information about the assertion.actual
- the given object.types
- the types to check the actual value against.AssertionError
- if the actual value type is in given type.NullPointerException
- if the actual value is null.NullPointerException
- if the given types is null.public void assertEqual(AssertionInfo info, Object actual, Object expected)
info
- contains information about the assertion.actual
- the "actual" object.expected
- the "expected" object.AssertionError
- if actual
is not equal to expected
. This method will throw a
org.junit.ComparisonFailure
instead if JUnit is in the classpath and the given objects are not
equal.public void assertNotEqual(AssertionInfo info, Object actual, Object other)
info
- contains information about the assertion.actual
- the given object.other
- the object to compare actual
to.AssertionError
- if actual
is equal to other
.public void assertNull(AssertionInfo info, Object actual)
null
.info
- contains information about the assertion.actual
- the given object.AssertionError
- if the given object is not null
.public void assertNotNull(AssertionInfo info, Object actual)
null
.info
- contains information about the assertion.actual
- the given object.AssertionError
- if the given object is null
.public void assertNotNull(AssertionInfo info, Object actual, String label)
null
.info
- contains information about the assertion.actual
- the given object.label
- the label to represent actual in the error messageAssertionError
- if the given object is null
.public void assertSame(AssertionInfo info, Object actual, Object expected)
info
- contains information about the assertion.actual
- the given object.expected
- the expected object.AssertionError
- if the given objects do not refer to the same object.public void assertNotSame(AssertionInfo info, Object actual, Object other)
info
- contains information about the assertion.actual
- the given object.other
- the object to compare actual
to.AssertionError
- if the given objects refer to the same object.public void assertHasToString(AssertionInfo info, Object actual, String expectedToString)
public void assertIsIn(AssertionInfo info, Object actual, Object[] values)
info
- contains information about the assertion.actual
- the given object.values
- the given array.NullPointerException
- if the given array is null
.IllegalArgumentException
- if the given array is empty.AssertionError
- if the given object is not present in the given array.public void assertIsNotIn(AssertionInfo info, Object actual, Object[] values)
info
- contains information about the assertion.actual
- the given object.values
- the given array.NullPointerException
- if the given array is null
.IllegalArgumentException
- if the given array is empty.AssertionError
- if the given object is present in the given array.public void assertIsIn(AssertionInfo info, Object actual, Iterable<?> values)
info
- contains information about the assertion.actual
- the given object.values
- the given iterable.NullPointerException
- if the given collection is null
.IllegalArgumentException
- if the given collection is empty.AssertionError
- if the given object is not present in the given collection.public void assertIsNotIn(AssertionInfo info, Object actual, Iterable<?> values)
info
- contains information about the assertion.actual
- the given object.values
- the given collection.NullPointerException
- if the given iterable is null
.IllegalArgumentException
- if the given collection is empty.AssertionError
- if the given object is present in the given collection.public <A> void assertIsEqualToIgnoringNullFields(AssertionInfo info, A actual, A other, Map<String,Comparator<?>> comparatorByPropertyOrField, TypeComparators comparatorByType)
A
- the actual typeinfo
- contains information about the assertion.actual
- the given object.other
- the object to compare actual
to.comparatorByPropertyOrField
- comparators use for specific fieldscomparatorByType
- comparators use for specific typesNullPointerException
- if the actual type is null
.NullPointerException
- if the other type is null
.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.public <A> void assertIsEqualToComparingOnlyGivenFields(AssertionInfo info, A actual, A other, Map<String,Comparator<?>> comparatorByPropertyOrField, TypeComparators comparatorByType, String... fields)
A
- the actual typeinfo
- contains information about the assertion.actual
- the given object.other
- the object to compare actual
to.comparatorByPropertyOrField
- comparators use for specific fieldscomparatorByType
- comparators use for specific typesfields
- accepted fieldsNullPointerException
- if the other type is null
.AssertionError
- if actual is null
.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.IntrospectionError
- if a field does not exist in actual.public <A> void assertIsEqualToIgnoringGivenFields(AssertionInfo info, A actual, A other, Map<String,Comparator<?>> comparatorByPropertyOrField, TypeComparators comparatorByType, String... fields)
A
- the actual typeinfo
- contains information about the assertion.actual
- the given object.other
- the object to compare actual
to.comparatorByPropertyOrField
- comparators use for specific fieldscomparatorByType
- comparators use for specific typesfields
- the fields to ignore in comparisonNullPointerException
- if the other type is null
.AssertionError
- if actual is null
.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.public <A> void assertHasNoNullFieldsOrPropertiesExcept(AssertionInfo info, A actual, String... propertiesOrFieldsToIgnore)
A
- the actual type.info
- contains information about the assertion.actual
- the given object.propertiesOrFieldsToIgnore
- the fields to ignore in comparison.AssertionError
- if actual is null
.AssertionError
- if some of the fields of the actual object are null.public <A> void assertHasAllNullFieldsOrPropertiesExcept(AssertionInfo info, A actual, String... propertiesOrFieldsToIgnore)
A
- the actual type.info
- contains information about the assertion.actual
- the given object.propertiesOrFieldsToIgnore
- the fields to ignore in comparison.AssertionError
- is actual is null
.AssertionError
- if some of the fields of the actual object are not null.public <A> void assertIsEqualToComparingFieldByFieldRecursively(AssertionInfo info, Object actual, Object other, Map<String,Comparator<?>> comparatorByPropertyOrField, TypeComparators comparatorByType)
A
- the actual typeinfo
- contains information about the assertion.actual
- the given object.comparatorByPropertyOrField
- comparators use for specific fieldscomparatorByType
- comparators use for specific typesother
- the object to compare actual
to.AssertionError
- if actual is null
.AssertionError
- if the actual and the given object are not "deeply" equal.public static Set<Field> getDeclaredFieldsIncludingInherited(Class<?> clazz)
java.lang
package whose fields are not included.clazz
- the class we want the declared fields.public boolean areEqualToIgnoringGivenFields(Object actual, Object other, Map<String,Comparator<?>> comparatorByPropertyOrField, TypeComparators comparatorByType, String... fields)
public boolean areEqualToComparingOnlyGivenFields(Object actual, Object other, Map<String,Comparator<?>> comparatorByPropertyOrField, TypeComparators comparatorByType, String... fields)
public <A> void assertHasFieldOrProperty(AssertionInfo info, A actual, String name)
public <A> void assertHasFieldOrPropertyWithValue(AssertionInfo info, A actual, String name, Object expectedValue)
public <A> void assertHasSameHashCodeAs(AssertionInfo info, A actual, Object other)
A
- the actual typeinfo
- contains information about the assertion.actual
- the given object.other
- the object to check hashCode against.AssertionError
- if the actual object is null.AssertionError
- if the given object is null.AssertionError
- if the actual object has not the same hashCode as the given object.Copyright © 2014–2019 AssertJ. All rights reserved.