public class Subject<S extends Subject<S,T>,T> extends Object
Modifier and Type | Field and Description |
---|---|
protected FailureStrategy |
failureStrategy |
Constructor and Description |
---|
Subject(FailureStrategy failureStrategy,
T subject) |
Modifier and Type | Method and Description |
---|---|
protected TestVerb |
check()
A convenience for implementers of
Subject subclasses to use other truth
Subject wrappers within their own propositional logic. |
boolean |
equals(Object o)
Deprecated.
Object.equals(Object) is not supported on Truth subjects.
If you meant to test object equality, use isEqualTo(Object) instead. |
protected void |
fail(String verb)
Assembles a failure message and passes such to the FailureStrategy
|
protected void |
fail(String verb,
Object... messageParts)
Assembles a failure message and passes such to the FailureStrategy
|
protected void |
fail(String verb,
Object part)
Assembles a failure message and passes such to the FailureStrategy.
|
protected void |
failWithBadResults(String verb,
Object expected,
String failVerb,
Object actual)
Assembles a failure message and passes it to the FailureStrategy
|
protected void |
failWithCustomSubject(String verb,
Object expected,
Object actual)
Assembles a failure message with an alternative representation of the wrapped subject
and passes it to the FailureStrategy
|
protected void |
failWithoutSubject(String verb)
Assembles a failure message without a given subject and passes it to the FailureStrategy
|
protected void |
failWithRawMessage(String message,
Object... parameters)
Passes through a failure message verbatim.
|
protected String |
getDisplaySubject() |
protected T |
getSubject() |
int |
hashCode()
Deprecated.
Object.hashCode() is not supported on Truth subjects. |
protected String |
internalCustomName() |
void |
isAnyOf(Object first,
Object second,
Object... rest)
Fails unless the subject is equal to any of the given elements.
|
void |
isEqualTo(Object other)
Fails if the subject is not equal to the given object.
|
void |
isIn(Iterable<?> iterable)
Fails unless the subject is equal to any element in the given iterable.
|
void |
isInstanceOf(Class<?> clazz)
Fails if the subject is not an instance of the given class.
|
void |
isNoneOf(Object first,
Object second,
Object... rest)
Fails if the subject is equal to any of the given elements.
|
void |
isNotEqualTo(Object other)
Fails if the subject is equal to the given object.
|
void |
isNotIn(Iterable<?> iterable)
Fails if the subject is equal to any element in the given iterable.
|
void |
isNotInstanceOf(Class<?> clazz)
Fails if the subject is an instance of the given class.
|
void |
isNotNull()
Fails if the subject is null.
|
void |
isNotSameAs(Object other)
Fails if the subject is the same instance as the given object.
|
void |
isNull()
Fails if the subject is not null.
|
void |
isSameAs(Object other)
Fails if the subject is not the same instance as the given object.
|
S |
named(String name)
Renames the subject so that this name appears in the error messages in place of string
representations of the subject.
|
protected final FailureStrategy failureStrategy
public Subject(FailureStrategy failureStrategy, @Nullable T subject)
protected String internalCustomName()
public S named(String name)
public void isNull()
public void isNotNull()
public void isEqualTo(@Nullable Object other)
public void isNotEqualTo(@Nullable Object other)
public void isSameAs(@Nullable Object other)
public void isNotSameAs(@Nullable Object other)
public void isInstanceOf(Class<?> clazz)
public void isNotInstanceOf(Class<?> clazz)
public void isIn(Iterable<?> iterable)
public void isAnyOf(@Nullable Object first, @Nullable Object second, @Nullable Object... rest)
public void isNotIn(Iterable<?> iterable)
public void isNoneOf(@Nullable Object first, @Nullable Object second, @Nullable Object... rest)
protected T getSubject()
protected String getDisplaySubject()
protected TestVerb check()
Subject
subclasses to use other truth
Subject
wrappers within their own propositional logic.protected void fail(String verb)
verb
- the proposition being assertedprotected void fail(String verb, Object part)
part
have the same toString()'s.verb
- the proposition being assertedpart
- the value against which the subject is comparedprotected void fail(String verb, Object... messageParts)
verb
- the proposition being assertedmessageParts
- the expectations against which the subject is comparedprotected void failWithBadResults(String verb, Object expected, String failVerb, Object actual)
verb
- the proposition being assertedexpected
- the expectations against which the subject is comparedfailVerb
- the failure of the proposition being assertedactual
- the actual value the subject was compared againstprotected void failWithCustomSubject(String verb, Object expected, Object actual)
verb
- the proposition being assertedexpected
- the expected value of the propositionactual
- the custom representation of the subject to be reported in the failure.protected void failWithoutSubject(String verb)
verb
- the proposition being assertedprotected void failWithRawMessage(String message, Object... parameters)
Subject
subclasses which
need to provide alternate language for more fit-to-purpose error messages.message
- the message template to be passed to the failure. Note, this method only
guarantees to process %s
tokens. It is not guaranteed to be compatible
with String.format()
. Any other formatting desired (such as floats or
scientific notation) should be performed before the method call and the formatted
value passed in as a string.parameters
- the object parameters which will be applied to the message template.@Deprecated public boolean equals(@Nullable Object o)
Object.equals(Object)
is not supported on Truth subjects.
If you meant to test object equality, use isEqualTo(Object)
instead.equals
in class Object
UnsupportedOperationException
- always@Deprecated public int hashCode()
Object.hashCode()
is not supported on Truth subjects.hashCode
in class Object
UnsupportedOperationException
- alwaysCopyright © 2015. All rights reserved.