Class StandardSubjectBuilder

  • Direct Known Subclasses:
    Expect

    public class StandardSubjectBuilder
    extends java.lang.Object
    In a fluent assertion chain, an object with which you can do any of the following:

    For more information about the methods in this class, see this FAQ entry.

    For people extending Truth

    You won't extend this type. When you write a custom subject, see our doc on extensions.

    • Field Detail

      • metadataDoNotReferenceDirectly

        private final FailureMetadata metadataDoNotReferenceDirectly
    • Constructor Detail

      • StandardSubjectBuilder

        StandardSubjectBuilder​(FailureMetadata metadata)
    • Method Detail

      • forCustomFailureStrategy

        public static StandardSubjectBuilder forCustomFailureStrategy​(FailureStrategy failureStrategy)
        Returns a new instance that invokes the given FailureStrategy when a check fails. Most users should not need this. If you think you do, see the documentation on FailureStrategy.
      • that

        public final <ComparableT extends java.lang.Comparable<?>> ComparableSubject<ComparableT> that​(ComparableT actual)
      • that

        public final Subject that​(java.lang.Object actual)
      • that

        public final ClassSubject that​(java.lang.Class<?> actual)
      • that

        public final LongSubject that​(java.lang.Long actual)
      • that

        public final DoubleSubject that​(java.lang.Double actual)
      • that

        public final FloatSubject that​(java.lang.Float actual)
      • that

        public final IntegerSubject that​(java.lang.Integer actual)
      • that

        public final BooleanSubject that​(java.lang.Boolean actual)
      • that

        public final StringSubject that​(java.lang.String actual)
      • that

        public final IterableSubject that​(java.lang.Iterable<?> actual)
      • that

        public final MapSubject that​(java.util.Map<?,​?> actual)
      • that

        public final MultimapSubject that​(com.google.common.collect.Multimap<?,​?> actual)
      • that

        public final MultisetSubject that​(com.google.common.collect.Multiset<?> actual)
      • that

        public final TableSubject that​(com.google.common.collect.Table<?,​?,​?> actual)
      • withMessage

        public final StandardSubjectBuilder withMessage​(java.lang.String messageToPrepend)
        Returns a new instance that will output the given message before the main failure message. If this method is called multiple times, the messages will appear in the order that they were specified.
      • withMessage

        public final StandardSubjectBuilder withMessage​(java.lang.String format,
                                                        java.lang.Object... args)
        Returns a new instance that will output the given message before the main failure message. If this method is called multiple times, the messages will appear in the order that they were specified.

        Note: the arguments will be substituted into the format template using Strings.lenientFormat. Note this only supports the %s specifier.

        Throws:
        java.lang.IllegalArgumentException - if the number of placeholders in the format string does not equal the number of given arguments
      • about

        public final <S extends Subject,​A> SimpleSubjectBuilder<S,​A> about​(Subject.Factory<S,​A> factory)
        Given a factory for some Subject class, returns a builder whose that(actual) method creates instances of that class. Created subjects use the previously set failure strategy and any previously set failure message.
      • checkStatePreconditions

        void checkStatePreconditions()
        Extension point invoked before every assertion. This allows Expect to check that it's been set up properly as a TestRule.