Class Subject<S extends Subject<S,​T>,​T>

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static interface  Subject.HasField  
    • Constructor Summary

      Constructors 
      Constructor Description
      Subject​(FailureStrategy failureStrategy, T subject)  
    • Method Summary

      All Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      protected TestVerb check()
      A convenience for implementers of Subject subclasses to use other truth Subject wrappers within their own propositional logic.
      boolean equals​(java.lang.Object o)
      Deprecated.
      This method is not a proposition, but the default Object equality method.
      protected void fail​(java.lang.String verb)
      Assembles a failure message and passes such to the FailureStrategy
      protected void fail​(java.lang.String verb, java.lang.Object part)
      Assembles a failure message and passes such to the FailureStrategy.
      protected void fail​(java.lang.String verb, java.lang.Object... messageParts)
      Assembles a failure message and passes such to the FailureStrategy
      protected void failWithBadResults​(java.lang.String verb, java.lang.Object expected, java.lang.String failVerb, java.lang.Object actual)
      Assembles a failure message and passes it to the FailureStrategy
      protected void failWithCustomSubject​(java.lang.String verb, java.lang.Object expected, java.lang.Object actual)
      Assembles a failure message with an alternative representation of the wrapped subject and passes it to the FailureStrategy
      protected void failWithoutSubject​(java.lang.String verb)
      Assembles a failure message without a given subject and passes it to the FailureStrategy
      protected void failWithRawMessage​(java.lang.String message, java.lang.Object... parameters)
      Passes through a failure message verbatim.
      protected java.lang.String getDisplaySubject()  
      protected T getSubject()  
      Subject.HasField hasField​(java.lang.String fieldName)  
      int hashCode()
      Deprecated.
      Equals/Hashcode is not supported on Subjects.
      protected java.lang.String internalCustomName()  
      void is​(java.lang.Object other)
      Deprecated.
      Use isEqualTo(Object) to check object equality or isSameAs(Object) to check reference equality.
      void isA​(java.lang.Class<?> clazz)
      Deprecated.
      void isEqualTo​(java.lang.Object other)
      Fails if the subject is not equal to the given object.
      void isInstanceOf​(java.lang.Class<?> clazz)
      Fails if the subject is not an instance of the given class.
      void isNotA​(java.lang.Class<?> clazz)
      Deprecated.
      void isNotEqualTo​(java.lang.Object other)
      Fails if the subject is equal to the given object.
      void isNotInstanceOf​(java.lang.Class<?> clazz)
      Fails if the subject is an instance of the given class.
      void isNotNull()
      Fails if the subject is null.
      void isNotSameAs​(java.lang.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​(java.lang.Object other)
      Fails if the subject is not the same instance as the given object.
      S labeled​(java.lang.String label)
      Deprecated.
      Use named(String) instead.
      S named​(java.lang.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

      • subject

        private final T subject
      • customName

        private java.lang.String customName
    • Method Detail

      • internalCustomName

        protected java.lang.String internalCustomName()
      • named

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

        @Deprecated
        public S labeled​(java.lang.String label)
        Deprecated.
        Use named(String) instead.
      • is

        @Deprecated
        public void is​(java.lang.Object other)
        Deprecated.
        Use isEqualTo(Object) to check object equality or isSameAs(Object) to check reference equality.
      • isNull

        public void isNull()
        Fails if the subject is not null.
      • isNotNull

        public void isNotNull()
        Fails if the subject is null.
      • isEqualTo

        public void isEqualTo​(java.lang.Object other)
        Fails if the subject is not equal to the given object.
      • isNotEqualTo

        public void isNotEqualTo​(java.lang.Object other)
        Fails if the subject is equal to the given object.
      • isSameAs

        public void isSameAs​(java.lang.Object other)
        Fails if the subject is not the same instance as the given object.
      • isNotSameAs

        public void isNotSameAs​(java.lang.Object other)
        Fails if the subject is the same instance as the given object.
      • isA

        @Deprecated
        public void isA​(java.lang.Class<?> clazz)
        Deprecated.
        Fails if the subject is not an instance of the given class.
      • isNotA

        @Deprecated
        public void isNotA​(java.lang.Class<?> clazz)
        Deprecated.
        Fails if the subject is an instance of the given class.
      • isInstanceOf

        public void isInstanceOf​(java.lang.Class<?> clazz)
        Fails if the subject is not an instance of the given class.
      • isNotInstanceOf

        public void isNotInstanceOf​(java.lang.Class<?> clazz)
        Fails if the subject is an instance of the given class.
      • getSubject

        protected T getSubject()
      • getDisplaySubject

        protected java.lang.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​(java.lang.String verb)
        Assembles a failure message and passes such to the FailureStrategy
        Parameters:
        verb - the proposition being asserted
      • fail

        protected void fail​(java.lang.String verb,
                            java.lang.Object part)
        Assembles a failure message and passes such to the FailureStrategy. Also performs disambiguation if the subject and part have the same toString()'s.
        Parameters:
        verb - the proposition being asserted
        part - the value against which the subject is compared
      • fail

        protected void fail​(java.lang.String verb,
                            java.lang.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​(java.lang.String verb,
                                          java.lang.Object expected,
                                          java.lang.String failVerb,
                                          java.lang.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​(java.lang.String verb,
                                             java.lang.Object expected,
                                             java.lang.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​(java.lang.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​(java.lang.String message,
                                          java.lang.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("java.lang.reflect.Field")
        public Subject.HasField hasField​(java.lang.String fieldName)
      • equals

        @Deprecated
        public boolean equals​(java.lang.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 java.lang.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 java.lang.Object