com.google.common.truth
Class Subject<S extends Subject<S,T>,T>

java.lang.Object
  extended by com.google.common.truth.Subject<S,T>
Direct Known Subclasses:
AbstractArraySubject, BooleanSubject, ClassSubject, DefaultSubject, IntegerSubject, IterableSubject, MapSubject, OptionalSubject, StringSubject, Subject

public class Subject<S extends Subject<S,T>,T>
extends Object

Propositions for arbitrarily typed subjects and for properties of Object

Author:
David Saff, Christian Gruber ([email protected])

Nested Class Summary
static interface Subject.HasField
           
 
Field Summary
protected  FailureStrategy failureStrategy
           
 
Constructor Summary
Subject(FailureStrategy failureStrategy, T subject)
           
 
Method Summary
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 "is" or "isEqualTo" propositions for equality tests.
protected  void fail(String verb, Object... messageParts)
          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)
           
 void isA(Class<?> clazz)
           
 void isEqualTo(Object other)
           
 void isNotA(Class<?> clazz)
           
 void isNotEqualTo(Object other)
           
 void isNotNull()
           
 void isNull()
           
 S labeled(String label)
          Soft-deprecated in favor of named(String).
 S named(String name)
          Renames the subject so that this name appears in the error messages in place of string representations of the subject.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

failureStrategy

protected final FailureStrategy failureStrategy
Constructor Detail

Subject

public Subject(FailureStrategy failureStrategy,
               T subject)
Method Detail

internalCustomName

protected String internalCustomName()

named

public S named(String name)
Renames the subject so that this name appears in the error messages in place of string representations of the subject.


labeled

public S labeled(String label)
Soft-deprecated in favor of named(String).


is

public void is(Object other)

isNull

public void isNull()

isNotNull

public void isNotNull()

isEqualTo

public void isEqualTo(Object other)

isNotEqualTo

public void isNotEqualTo(Object other)

isA

public void isA(Class<?> clazz)

isNotA

public void isNotA(Class<?> clazz)

getSubject

protected T getSubject()

getDisplaySubject

protected String getDisplaySubject()

check

protected TestVerb check()
A convenience for implementers of Subject subclasses to use other truth Subject wrappers within their own propositional logic.


fail

protected void fail(String verb,
                    Object... messageParts)
Assembles a failure message and passes such to the FailureStrategy

Parameters:
verb - the proposition being asserted
messageParts - the expectations against which the subject is compared

failWithBadResults

protected void failWithBadResults(String verb,
                                  Object expected,
                                  String failVerb,
                                  Object actual)
Assembles a failure message and passes it to the FailureStrategy

Parameters:
verb - the proposition being asserted
messageParts - the expectations against which the subject is compared

failWithCustomSubject

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

Parameters:
verb - the proposition being asserted
expected - the expected value of the proposition
actual - the custom representation of the subject to be reported in the failure.

failWithoutSubject

protected void failWithoutSubject(String verb)
Assembles a failure message without a given subject and passes it to the FailureStrategy

Parameters:
verb - the proposition being asserted

failWithRawMessage

protected void failWithRawMessage(String message,
                                  Object... parameters)
Passes through a failure message verbatim. Used for Subject subclasses which need to provide alternate language for more fit-to-purpose error messages.

Parameters:
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.
paramters - the object parameters which will be applied to the message template.

hasField

@GwtIncompatible(value="java.lang.reflect.Field")
public Subject.HasField hasField(String fieldName)

equals

@Deprecated
public boolean equals(Object o)
Deprecated. This method is not a proposition, but the default Object equality method. Testing code should use "is" or "isEqualTo" propositions for equality tests.

Overrides:
equals in class Object

hashCode

@Deprecated
public 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.

Overrides:
hashCode in class Object


Copyright © 2014. All rights reserved.