public class Subject<S extends Subject<S,T>,T> extends Object
Modifier and Type | Class and Description |
---|---|
static interface |
Subject.HasField |
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.
This method is not a proposition, but the default Object equality method.
Testing code should use
isEqualTo(Object) to check for object equalty
or isSameAs(Object) to check reference equality. |
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() |
Subject.HasField |
hasField(String fieldName) |
int |
hashCode()
Deprecated.
Equals/Hashcode is not supported on Subjects. Their only use is as a holder of
propositions. Use of equals() is deprecated and forwards to isEqualTo() and
hashCode() is disallowed.
|
protected String |
internalCustomName() |
void |
is(Object other)
Deprecated.
Use
isEqualTo(Object) to check object equality or
isSameAs(Object) to check reference equality. |
void |
isA(Class<?> clazz)
Deprecated.
Use
isInstanceOf(java.lang.Class<?>) instead. |
void |
isEqualTo(Object other)
Fails if the subject is not equal to the given object.
|
void |
isInstanceOf(Class<?> clazz)
Fails if the subject is not an instance of the given class.
|
void |
isNotA(Class<?> clazz)
Deprecated.
Use
isNotInstanceOf(Class) instead. |
void |
isNotEqualTo(Object other)
Fails if the subject is equal to the given object.
|
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 |
labeled(String label)
Deprecated.
Use
named(String) instead. |
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, T subject)
protected String internalCustomName()
public S named(String name)
@Deprecated public S labeled(String label)
named(String)
instead.@Deprecated public void is(Object other)
isEqualTo(Object)
to check object equality or
isSameAs(Object)
to check reference equality.public void isNull()
public void isNotNull()
public void isEqualTo(Object other)
public void isNotEqualTo(Object other)
public void isSameAs(Object other)
public void isNotSameAs(Object other)
@Deprecated public void isA(Class<?> clazz)
isInstanceOf(java.lang.Class<?>)
instead.@Deprecated public void isNotA(Class<?> clazz)
isNotInstanceOf(Class)
instead.public void isInstanceOf(Class<?> clazz)
public void isNotInstanceOf(Class<?> clazz)
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.@GwtIncompatible(value="java.lang.reflect.Field") public Subject.HasField hasField(String fieldName)
@Deprecated public boolean equals(Object o)
isEqualTo(Object)
to check for object equalty
or isSameAs(Object)
to check reference equality.@Deprecated public int hashCode()
Copyright © 2014. All rights reserved.