S
- the "self" type of this assertion class. Please read "Emulating 'self types' using Java Generics to simplify fluent API implementation"
for more details.A
- the type of the "actual" value.public abstract class AbstractAssert<S extends AbstractAssert<S,A>,A> extends Object implements Assert<S,A>
Modifier and Type | Field and Description |
---|---|
protected A |
actual |
protected WritableAssertionInfo |
info |
protected S |
myself |
Modifier | Constructor and Description |
---|---|
protected |
AbstractAssert(A actual,
Class<?> selfType) |
Modifier and Type | Method and Description |
---|---|
S |
as(Description description)
Sets the description of the assertion that is going to be called after.
|
S |
as(String description,
Object... args)
Sets the description of the assertion that is going to be called after.
|
AbstractListAssert<?,?,Object> |
asList()
Verifies that the actual value is an instance of List,
and returns a list assertion, to allow chaining of list-specific
assertions from this call.
|
AbstractCharSequenceAssert<?,String> |
asString()
Verifies that the actual value is an instance of String,
and returns a String assertion, to allow chaining of String-specific
assertions from this call.
|
S |
describedAs(Description description)
Sets the description of the assertion that is going to be called after.
|
S |
describedAs(String description,
Object... args)
Sets the description of the assertion that is going to be called after.
|
String |
descriptionText()
The description of this assertion set with
describedAs(String, Object...) or
describedAs(Description) . |
S |
doesNotHave(Condition<? super A> condition)
Verifies that the actual value does not satisfy the given condition.
|
S |
doesNotHaveSameClassAs(Object other)
Verifies that the actual value does not have the same class as the given object.
|
boolean |
equals(Object obj)
Deprecated.
use
#isEqualTo() instead |
protected void |
failWithMessage(String errorMessage,
Object... arguments)
Utility method to ease writing custom assertions classes using
String.format(String, Object...) specifiers
in error message. |
protected WritableAssertionInfo |
getWritableAssertionInfo()
Exposes the
WritableAssertionInfo used in the current assertion for better extensibility. When writing
your own assertion class, you can use the returned WritableAssertionInfo to change the error message and
still keep the description set by the assertion user. |
S |
has(Condition<? super A> condition)
Verifies that the actual value satisfies the given condition.
|
int |
hashCode()
Always returns 1.
|
S |
hasSameClassAs(Object other)
Verifies that the actual value has the same class as the given object.
|
S |
hasToString(String expectedToString)
Verifies that actual
actual.toString() is equal to the given String . |
protected S |
inBinary()
Use binary object representation instead of standard representation in error messages.
|
protected S |
inHexadecimal()
Use hexadecimal object representation instead of standard representation in error messages.
|
S |
is(Condition<? super A> condition)
Verifies that the actual value satisfies the given condition.
|
S |
isEqualTo(Object expected)
Verifies that the actual value is equal to the given one.
|
S |
isExactlyInstanceOf(Class<?> type)
Verifies that the actual value is exactly an instance of the given type.
|
S |
isIn(Iterable<?> values)
Verifies that the actual value is present in the given values.
|
S |
isIn(Object... values)
Verifies that the actual value is present in the given array of values.
|
S |
isInstanceOf(Class<?> type)
Verifies that the actual value is an instance of the given type.
|
S |
isInstanceOfAny(Class<?>... types)
Verifies that the actual value is an instance of any of the given types.
|
S |
isNot(Condition<? super A> condition)
Verifies that the actual value does not satisfy the given condition.
|
S |
isNotEqualTo(Object other)
Verifies that the actual value is not equal to the given one.
|
S |
isNotExactlyInstanceOf(Class<?> type)
Verifies that the actual value is not exactly an instance of given type.
|
S |
isNotIn(Iterable<?> values)
Verifies that the actual value is not present in the given values.
|
S |
isNotIn(Object... values)
Verifies that the actual value is not present in the given array of values.
|
S |
isNotInstanceOf(Class<?> type)
Verifies that the actual value is not an instance of the given type.
|
S |
isNotInstanceOfAny(Class<?>... types)
Verifies that the actual value is not an instance of any of the given types.
|
S |
isNotNull()
Verifies that the actual value is not
null . |
S |
isNotOfAnyClassIn(Class<?>... types)
Verifies that the actual value type is not in given types.
|
S |
isNotSameAs(Object other)
Verifies that the actual value is not the same as the given one, ie using == comparison.
|
void |
isNull()
Verifies that the actual value is
null . |
S |
isOfAnyClassIn(Class<?>... types)
Verifies that the actual value type is in given types.
|
S |
isSameAs(Object expected)
Verifies that the actual value is the same as the given one, ie using == comparison.
|
S |
matches(Predicate<? super A> predicate)
Verifies that the actual object matches the given predicate.
|
S |
matches(Predicate<? super A> predicate,
String predicateDescription)
Verifies that the actual object matches the given predicate, the predicate description is used to get an
informative error message.
|
S |
overridingErrorMessage(String newErrorMessage,
Object... args)
Overrides AssertJ default error message by the given one.
|
protected void |
throwAssertionError(ErrorMessageFactory errorMessageFactory)
Utility method to throw an
AssertionError given a BasicErrorMessageFactory . |
S |
usingComparator(Comparator<? super A> customComparator)
Use given custom comparator instead of relying on actual type A equals method for incoming assertion checks.
|
S |
usingDefaultComparator()
Revert to standard comparison for incoming assertion checks.
|
S |
withFailMessage(String newErrorMessage,
Object... args)
Alternative method for
overridingErrorMessage(java.lang.String, java.lang.Object...) |
S |
withThreadDumpOnError()
In case of assertion error, the thread dump will be printed on
System.err . |
protected final WritableAssertionInfo info
protected final A actual
protected final S extends AbstractAssert<S,A> myself
protected WritableAssertionInfo getWritableAssertionInfo()
WritableAssertionInfo
used in the current assertion for better extensibility. When writing
your own assertion class, you can use the returned WritableAssertionInfo
to change the error message and
still keep the description set by the assertion user.WritableAssertionInfo
used in the current assertionprotected void failWithMessage(String errorMessage, Object... arguments)
String.format(String, Object...)
specifiers
in error message.
Moreover, this method honors any description set with as(String, Object...)
or overidden error message
defined by the user with overridingErrorMessage(String, Object...)
.
Example :
public TolkienCharacterAssert hasName(String name) {
// check that actual TolkienCharacter we want to make assertions on is not null.
isNotNull();
// check condition
if (!actual.getName().equals(name)) {
failWithMessage("Expected character's name to be <%s> but was <%s>", name, actual.getName());
}
// return the current assertion for method chaining
return this;
}
errorMessage
- the error message to formatarguments
- the arguments referenced by the format specifiers in the errorMessage string.protected void throwAssertionError(ErrorMessageFactory errorMessageFactory)
AssertionError
given a BasicErrorMessageFactory
.
Instead of writing ...
throw Failures.instance().failure(info, ShouldBePresent.shouldBePresent());
... you can simply write :
throwAssertionError(info, ShouldBePresent.shouldBePresent());
errorMessageFactory
- used to define the error message.public S as(String description, Object... args)
You must set it before calling the assertion otherwise it is ignored as the failing assertion breaks the chained call by throwing an AssertionError.
The description follows String.format(String, Object...)
syntax.
Example :
try {
// set a bad age to Mr Frodo which is really 33 years old.
frodo.setAge(50);
// specify a test description (call as() before the assertion !), it supports String format syntax.
assertThat(frodo.getAge()).as("check %s's age", frodo.getName()).isEqualTo(33);
} catch (AssertionError e) {
assertThat(e).hasMessage("[check Frodo's age] expected:<[33]> but was:<[50]>");
}
as
in interface Descriptable<S extends AbstractAssert<S,A>>
description
- the new description to set.args
- optional parameter if description is a format String.this
object.Descriptable.describedAs(String, Object...)
public S as(Description description)
You must set it before calling the assertion otherwise it is ignored as the failing assertion breaks the chained call by throwing an AssertionError.
This overloaded version of "describedAs" offers more flexibility than the one taking a String
by allowing
users to pass their own implementation of a description. For example, a description that creates its value lazily,
only when an assertion failure occurs.
as
in interface Descriptable<S extends AbstractAssert<S,A>>
description
- the new description to set.this
object.Descriptable.describedAs(Description)
protected S inHexadecimal()
assertThat("µµµ").contains("μμμ");
java.lang.AssertionError:
Expecting:
<"µµµ">
to contain:
<"μμμ">
With Hexadecimal message:
assertThat("µµµ").inHexadecimal().contains("μμμ");
java.lang.AssertionError:
Expecting:
<"['00B5', '00B5', '00B5']">
to contain:
<"['03BC', '03BC', '03BC']">
this
assertion object.protected S inBinary()
assertThat(1).inBinary().isEqualTo(2);
org.junit.ComparisonFailure:
Expected :0b00000000_00000000_00000000_00000010
Actual :0b00000000_00000000_00000000_00000001
this
assertion object.public S describedAs(String description, Object... args)
You must set it before calling the assertion otherwise it is ignored as the failing assertion breaks the chained call by throwing an AssertionError.
Alias for
since "as" is a keyword in Groovy.Descriptable.as(String, Object...)
describedAs
in interface Descriptable<S extends AbstractAssert<S,A>>
description
- the new description to set.this
object.public S describedAs(Description description)
You must set it before calling the assertion otherwise it is ignored as the failing assertion breaks the chained call by throwing an AssertionError.
This overloaded version of "describedAs" offers more flexibility than the one taking a String
by allowing
users to pass their own implementation of a description. For example, a description that creates its value lazily,
only when an assertion failure occurs.
describedAs
in interface Descriptable<S extends AbstractAssert<S,A>>
description
- the new description to set.this
object.public S isEqualTo(Object expected)
Example:
// assertions will pass
assertThat("abc").isEqualTo("abc");
assertThat(new HashMap<String, Integer>()).isEqualTo(new HashMap<String, Integer>());
// assertions will fail
assertThat("abc").isEqualTo("123");
assertThat(new ArrayList<String>()).isEqualTo(1);
public S isNotEqualTo(Object other)
Example:
// assertions will pass
assertThat("abc").isNotEqualTo("123");
assertThat(new ArrayList<String>()).isNotEqualTo(1);
// assertions will fail
assertThat("abc").isNotEqualTo("abc");
assertThat(new HashMap<String, Integer>()).isNotEqualTo(new HashMap<String, Integer>());
isNotEqualTo
in interface Assert<S extends AbstractAssert<S,A>,A>
other
- the given value to compare the actual value to.this
assertion object.public void isNull()
null
.
Example:
String value = null;
// assertion will pass
assertThat(value).isNull();
// assertions will fail
assertThat("abc").isNull();
assertThat(new HashMap<String, Integer>()).isNull();
public S isNotNull()
null
.
Example:
// assertion will pass
assertThat("abc").isNotNull();
assertThat(new HashMap<String, Integer>()).isNotNull();
// assertion will fail
String value = null;
assertThat(value).isNotNull();
public S isSameAs(Object expected)
Example:
// Name is a class with first and last fields, two Names are equals if both first and last are equals.
Name tyrion = new Name("Tyrion", "Lannister");
Name alias = tyrion;
Name clone = new Name("Tyrion", "Lannister");
// assertions succeed:
assertThat(tyrion).isSameAs(alias)
.isEqualTo(clone);
// assertion fails:
assertThat(tyrion).isSameAs(clone);
public S isNotSameAs(Object other)
Example:
// Name is a class with first and last fields, two Names are equals if both first and last are equals.
Name tyrion = new Name("Tyrion", "Lannister");
Name alias = tyrion;
Name clone = new Name("Tyrion", "Lannister");
// assertions succeed:
assertThat(clone).isNotSameAs(tyrion)
.isEqualTo(tyrion);
// assertion fails:
assertThat(alias).isNotSameAs(tyrion);
isNotSameAs
in interface Assert<S extends AbstractAssert<S,A>,A>
other
- the given value to compare the actual value to.this
assertion object.public S isIn(Object... values)
Example:
Ring[] elvesRings = new Ring[] { vilya, nenya, narya };
// assertion will pass:
assertThat(nenya).isIn(elvesRings);
// assertion will fail:
assertThat(oneRing).isIn(elvesRings);
public S isNotIn(Object... values)
Example:
Ring[] elvesRings = new Ring[] { vilya, nenya, narya };
// assertion will pass:
assertThat(oneRing).isNotIn(elvesRings);
// assertion will fail:
assertThat(nenya).isNotIn(elvesRings);
public S isIn(Iterable<?> values)
Example:
Iterable<Ring> elvesRings = newArrayList(vilya, nenya, narya);
// assertion will pass:
assertThat(nenya).isIn(elvesRings);
// assertion will fail:
assertThat(oneRing).isIn(elvesRings);
public S isNotIn(Iterable<?> values)
Example:
Iterable<Ring> elvesRings = newArrayList(vilya, nenya, narya);
// assertion will pass:
assertThat(oneRing).isNotIn(elvesRings);
// assertion will fail:
assertThat(nenya).isNotIn(elvesRings);
public S is(Condition<? super A> condition)
ExtensionPoints.has(Condition)
.is
in interface ExtensionPoints<S extends AbstractAssert<S,A>,A>
condition
- the given condition.this ExtensionPoints
object.ExtensionPoints.is(Condition)
public S isNot(Condition<? super A> condition)
ExtensionPoints.doesNotHave(Condition)
.isNot
in interface ExtensionPoints<S extends AbstractAssert<S,A>,A>
condition
- the given condition.this ExtensionPoints
object.ExtensionPoints.isNot(Condition)
public S has(Condition<? super A> condition)
ExtensionPoints.is(Condition)
.has
in interface ExtensionPoints<S extends AbstractAssert<S,A>,A>
condition
- the given condition.this ExtensionPoints
object.ExtensionPoints.is(Condition)
public S doesNotHave(Condition<? super A> condition)
ExtensionPoints.isNot(Condition)
.doesNotHave
in interface ExtensionPoints<S extends AbstractAssert<S,A>,A>
condition
- the given condition.this ExtensionPoints
object.ExtensionPoints.isNot(Condition)
public S isInstanceOf(Class<?> type)
Example:
// assertions will pass
assertThat("abc").isInstanceOf(String.class);
assertThat(new HashMap<String, Integer>()).isInstanceOf(HashMap.class);
assertThat(new HashMap<String, Integer>()).isInstanceOf(Map.class);
// assertions will fail
assertThat(1).isInstanceOf(String.class);
assertThat(new ArrayList<String>()).isInstanceOf(LinkedList.class);
isInstanceOf
in interface Assert<S extends AbstractAssert<S,A>,A>
type
- the type to check the actual value against.public S isInstanceOfAny(Class<?>... types)
Example:
// assertions will pass
assertThat("abc").isInstanceOfAny(String.class, Integer.class);
assertThat(new ArrayList<String>()).isInstanceOfAny(LinkedList.class, ArrayList.class);
assertThat(new HashMap<String, Integer>()).isInstanceOfAny(TreeMap.class, Map.class);
// assertions will fail
assertThat(1).isInstanceOfAny(Double.class, Float.class);
assertThat(new ArrayList<String>()).isInstanceOfAny(LinkedList.class, Vector.class);
isInstanceOfAny
in interface Assert<S extends AbstractAssert<S,A>,A>
types
- the types to check the actual value against.public S isNotInstanceOf(Class<?> type)
Example:
// assertions will pass
assertThat(1).isNotInstanceOf(Double.class);
assertThat(new ArrayList<String>()).isNotInstanceOf(LinkedList.class);
// assertions will fail
assertThat("abc").isNotInstanceOf(String.class);
assertThat(new HashMap<String, Integer>()).isNotInstanceOf(HashMap.class);
assertThat(new HashMap<String, Integer>()).isNotInstanceOf(Map.class);
isNotInstanceOf
in interface Assert<S extends AbstractAssert<S,A>,A>
type
- the type to check the actual value against.public S isNotInstanceOfAny(Class<?>... types)
Example:
// assertions will pass
assertThat(1).isNotInstanceOfAny(Double.class, Float.class);
assertThat(new ArrayList<String>()).isNotInstanceOfAny(LinkedList.class, Vector.class);
// assertions will fail
assertThat(1).isNotInstanceOfAny(Double.class, Integer.class);
assertThat(new ArrayList<String>()).isNotInstanceOfAny(LinkedList.class, ArrayList.class);
assertThat(new HashMap<String, Integer>()).isNotInstanceOfAny(TreeMap.class, Map.class);
isNotInstanceOfAny
in interface Assert<S extends AbstractAssert<S,A>,A>
types
- the types to check the actual value against.public S hasSameClassAs(Object other)
Example:
// assertions will pass
assertThat(1).hasSameClassAs(2);
assertThat("abc").hasSameClassAs("123");
assertThat(new ArrayList<String>()).hasSameClassAs(new ArrayList<Integer>());
// assertions will fail
assertThat(1).hasSameClassAs("abc");
assertThat(new ArrayList<String>()).hasSameClassAs(new LinkedList<String>());
hasSameClassAs
in interface Assert<S extends AbstractAssert<S,A>,A>
other
- the object to check type against.public S hasToString(String expectedToString)
actual.toString()
is equal to the given String
.
Example :
CartoonCaracter homer = new CartoonCaracter("Homer");
// Instead of writing ...
assertThat(homer.toString()).isEqualTo("Homer");
// ... you can simply write:
assertThat(homer).hasToString("Homer");
hasToString
in interface Assert<S extends AbstractAssert<S,A>,A>
expectedToString
- the expected String description of actual.public S doesNotHaveSameClassAs(Object other)
Example:
// assertions will pass
assertThat(1).doesNotHaveSameClassAs("abc");
assertThat(new ArrayList<String>()).doesNotHaveSameClassAs(new LinkedList<String>());
// assertions will fail
assertThat(1).doesNotHaveSameClassAs(2);
assertThat("abc").doesNotHaveSameClassAs("123");
assertThat(new ArrayList<String>()).doesNotHaveSameClassAs(new ArrayList<Integer>());
doesNotHaveSameClassAs
in interface Assert<S extends AbstractAssert<S,A>,A>
other
- the object to check type against.public S isExactlyInstanceOf(Class<?> type)
Example:
// assertions will pass
assertThat("abc").isExactlyInstanceOf(String.class);
assertThat(new ArrayList<String>()).isExactlyInstanceOf(ArrayList.class);
assertThat(new HashMap<String, Integer>()).isExactlyInstanceOf(HashMap.class);
// assertions will fail
assertThat(1).isExactlyInstanceOf(String.class);
assertThat(new ArrayList<String>()).isExactlyInstanceOf(List.class);
assertThat(new HashMap<String, Integer>()).isExactlyInstanceOf(Map.class);
isExactlyInstanceOf
in interface Assert<S extends AbstractAssert<S,A>,A>
type
- the type to check the actual value against.public S isNotExactlyInstanceOf(Class<?> type)
Example:
// assertions will pass
assertThat(1).isNotExactlyInstanceOf(String.class);
assertThat(new ArrayList<String>()).isNotExactlyInstanceOf(List.class);
assertThat(new HashMap<String, Integer>()).isNotExactlyInstanceOf(Map.class);
// assertions will fail
assertThat("abc").isNotExactlyInstanceOf(String.class);
assertThat(new ArrayList<String>()).isNotExactlyInstanceOf(ArrayList.class);
assertThat(new HashMap<String, Integer>()).isNotExactlyInstanceOf(HashMap.class);
isNotExactlyInstanceOf
in interface Assert<S extends AbstractAssert<S,A>,A>
type
- the type to check the actual value against.public S isOfAnyClassIn(Class<?>... types)
Example:
// assertions will pass
assertThat(new HashMap<String, Integer>()).isOfAnyClassIn(HashMap.class, TreeMap.class);
assertThat(new ArrayList<String>()).isOfAnyClassIn(ArrayList.class, LinkedList.class);
// assertions will fail
assertThat(new HashMap<String, Integer>()).isOfAnyClassIn(TreeMap.class, Map.class);
assertThat(new ArrayList<String>()).isOfAnyClassIn(LinkedList.class, List.class);
isOfAnyClassIn
in interface Assert<S extends AbstractAssert<S,A>,A>
types
- the types to check the actual value against.public S isNotOfAnyClassIn(Class<?>... types)
Example:
// assertions will pass
assertThat(new HashMap<String, Integer>()).isNotOfAnyClassIn(Map.class, TreeMap.class);
assertThat(new ArrayList<String>()).isNotOfAnyClassIn(LinkedList.class, List.class);
// assertions will fail
assertThat(new HashMap<String, Integer>()).isNotOfAnyClassIn(HashMap.class, TreeMap.class);
assertThat(new ArrayList<String>()).isNotOfAnyClassIn(ArrayList.class, LinkedList.class);
isNotOfAnyClassIn
in interface Assert<S extends AbstractAssert<S,A>,A>
types
- the types to check the actual value against.public AbstractListAssert<?,?,Object> asList()
Example :
Object sortedListAsObject = Arrays.asList(1, 2, 3);
// assertion will pass
assertThat(sortedListAsObject).asList().isSorted();
Object unsortedListAsObject = Arrays.asList(3, 1, 2);
// assertion will fail
assertThat(unsortedListAsObject).asList().isSorted();
public AbstractCharSequenceAssert<?,String> asString()
Example :
Object stringAsObject = "hello world";
// assertion will pass
assertThat(stringAsObject).asString().contains("hello");
// assertion will fail
assertThat(stringAsObject).asString().contains("holla");
public String descriptionText()
describedAs(String, Object...)
or
describedAs(Description)
.public S overridingErrorMessage(String newErrorMessage, Object... args)
The new error message is built using String.format(String, Object...)
if you provide args parameter (if you
don't, the error message is taken as it is).
Example :
assertThat(player.isRookie()).overridingErrorMessage("Expecting Player <%s> to be a rookie but was not.", player)
.isTrue();
newErrorMessage
- the error message that will replace the default one provided by Assertj.args
- the args used to fill error message as in String.format(String, Object...)
.Exception
- see String.format(String, Object...)
exception clause.public S withFailMessage(String newErrorMessage, Object... args)
overridingErrorMessage(java.lang.String, java.lang.Object...)
newErrorMessage
- the error message that will replace the default one provided by Assertj.args
- the args used to fill error message as in String.format(String, Object...)
.Exception
- see String.format(String, Object...)
exception clause.public S usingComparator(Comparator<? super A> customComparator)
Custom comparator is bound to assertion instance, meaning that if a new assertion is created, it will use default comparison strategy.
Examples :
// frodo and sam are instances of Character with Hobbit race (obviously :).
// raceComparator implements Comparator<Character>
assertThat(frodo).usingComparator(raceComparator).isEqualTo(sam);
usingComparator
in interface Assert<S extends AbstractAssert<S,A>,A>
customComparator
- the comparator to use for incoming assertion checks.this
assertion object.public S usingDefaultComparator()
This method should be used to disable a custom comparison strategy set by calling
Assert.usingComparator(Comparator)
.
usingDefaultComparator
in interface Assert<S extends AbstractAssert<S,A>,A>
this
assertion object.public S withThreadDumpOnError()
Assert
System.err
.
Example :
assertThat("Messi").withThreadDumpOnError().isEqualTo("Ronaldo");
will print the thread dump, something looking like:
"JDWP Command Reader"
java.lang.Thread.State: RUNNABLE
"JDWP Event Helper Thread"
java.lang.Thread.State: RUNNABLE
"JDWP Transport Listener: dt_socket"
java.lang.Thread.State: RUNNABLE
"Signal Dispatcher"
java.lang.Thread.State: RUNNABLE
"Finalizer"
java.lang.Thread.State: WAITING
at java.lang.Object.wait(Native Method)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:135)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:151)
at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:189)
"Reference Handler"
java.lang.Thread.State: WAITING
at java.lang.Object.wait(Native Method)
at java.lang.Object.wait(Object.java:503)
at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:133)
"main"
java.lang.Thread.State: RUNNABLE
at sun.management.ThreadImpl.dumpThreads0(Native Method)
at sun.management.ThreadImpl.dumpAllThreads(ThreadImpl.java:446)
at org.assertj.core.internal.Failures.threadDumpDescription(Failures.java:193)
at org.assertj.core.internal.Failures.printThreadDumpIfNeeded(Failures.java:141)
at org.assertj.core.internal.Failures.failure(Failures.java:91)
at org.assertj.core.internal.Objects.assertEqual(Objects.java:314)
at org.assertj.core.api.AbstractAssert.isEqualTo(AbstractAssert.java:198)
at org.assertj.examples.ThreadDumpOnErrorExample.main(ThreadDumpOnErrorExample.java:28)
withThreadDumpOnError
in interface Assert<S extends AbstractAssert<S,A>,A>
@Deprecated public boolean equals(Object obj)
#isEqualTo()
insteadequals
in interface Assert<S extends AbstractAssert<S,A>,A>
equals
in class Object
UnsupportedOperationException
- if this method is called.public S matches(Predicate<? super A> predicate)
Example :
assertThat(player).matches(p -> p.isRookie());
predicate
- the Predicate
to matchthis
assertion object.AssertionError
- if the actual does not match the given Predicate
.NullPointerException
- if given Predicate
is null.public S matches(Predicate<? super A> predicate, String predicateDescription)
Example :
assertThat(player).matches(p -> p.isRookie(), "is rookie");
The error message contains the predicate description, if the previous assertion fails, it will be:
Expecting:
<player>
to match 'is rookie' predicate.
predicate
- the Predicate
to matchpredicateDescription
- a description of the Predicate
used in the error messagethis
assertion object.AssertionError
- if the actual does not match the given Predicate
.NullPointerException
- if given Predicate
is null.NullPointerException
- if given predicateDescription is null.Copyright © 2014–2016 AssertJ. All rights reserved.