Class StandardSubjectBuilder
java.lang.Object
com.google.common.truth.StandardSubjectBuilder
- Direct Known Subclasses:
Expect
In a fluent assertion chain, an object with which you can do any of the following:
- Set an optional message with
withMessage(java.lang.String). - Specify the type of
Subjectto create withabout(Subject.Factory). - For the types of
Subjectbuilt into Truth, directly specify the value under test withthat(Object).
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.
-
Method Summary
Modifier and TypeMethodDescriptionfinal <CustomSubjectBuilderT extends CustomSubjectBuilder>
CustomSubjectBuilderTabout(CustomSubjectBuilder.Factory<CustomSubjectBuilderT> factory) A generic, advanced method of extension of Truth to new types, which is documented onCustomSubjectBuilder.final <S extends Subject, A>
SimpleSubjectBuilder<S, A> about(Subject.Factory<S, A> factory) Given a factory for someSubjectclass, returns a builder whosethat(actual)method creates instances of that class.final voidfail()Reports a failure.static StandardSubjectBuilderforCustomFailureStrategy(FailureStrategy strategy) Returns a new instance that invokes the givenFailureStrategywhen a check fails.final PrimitiveIntArraySubjectfinal <ComparableT extends Comparable<?>>
ComparableSubject<ComparableT> final GuavaOptionalSubjectfinal MultimapSubjectfinal MultisetSubjectfinal TableSubjectfinal BooleanSubjectfinal ClassSubjectfinal DoubleSubjectfinal FloatSubjectfinal IntegerSubjectfinal IterableSubjectfinal LongSubjectfinal Subjectfinal StringSubjectfinal ThrowableSubjectfinal BigDecimalSubjectthat(@Nullable BigDecimal actual) final PathSubjectfinal MapSubjectfinal OptionalSubjectfinal OptionalDoubleSubjectthat(@Nullable OptionalDouble actual) final OptionalIntSubjectthat(@Nullable OptionalInt actual) final OptionalLongSubjectthat(@Nullable OptionalLong actual) final IntStreamSubjectfinal LongStreamSubjectthat(@Nullable LongStream actual) final StreamSubjectfinal <T extends @Nullable Object>
ObjectArraySubject<T> final StandardSubjectBuilderwithMessage(@Nullable String message) Returns a new instance that will output the given message before the main failure message.final StandardSubjectBuilderwithMessage(String format, @Nullable Object... args) Returns a new instance that will output the given message before the main failure message.
-
Method Details
-
forCustomFailureStrategy
Returns a new instance that invokes the givenFailureStrategywhen a check fails. Most users should not need this. If you think you do, see the documentation onFailureStrategy. -
that
public final <ComparableT extends Comparable<?>> ComparableSubject<ComparableT> that(@Nullable ComparableT actual) -
that
-
that
-
that
-
that
-
that
-
that
-
that
-
that
-
that
-
that
-
that
-
that
-
that
-
that
-
that
-
that
-
that
-
that
-
that
-
that
-
that
-
that
-
that
-
that
-
that
-
that
- Since:
- 1.3.0 (with access to
OptionalSubjectpreviously part oftruth-java8-extension)
-
that
- Since:
- 1.4.0 (with access to
OptionalIntSubjectpreviously part oftruth-java8-extension)
-
that
- Since:
- 1.4.0 (with access to
OptionalLongSubjectpreviously part oftruth-java8-extension)
-
that
- Since:
- 1.4.0 (with access to
OptionalDoubleSubjectpreviously part oftruth-java8-extension)
-
that
- Since:
- 1.3.0 (with access to
StreamSubjectpreviously part oftruth-java8-extension)
-
that
- Since:
- 1.4.0 (with access to
IntStreamSubjectpreviously part oftruth-java8-extension)
-
that
- Since:
- 1.4.0 (with access to
LongStreamSubjectpreviously part oftruth-java8-extension)
-
that
- Since:
- 1.4.0 (with access to
PathSubjectpreviously part oftruth-java8-extension)
-
withMessage
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
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%sspecifier.- Throws:
IllegalArgumentException- if the number of placeholders in the format string does not equal the number of given arguments
-
about
Given a factory for someSubjectclass, returns a builder whosethat(actual)method creates instances of that class. Created subjects use the previously set failure strategy and any previously set failure message. -
about
public final <CustomSubjectBuilderT extends CustomSubjectBuilder> CustomSubjectBuilderT about(CustomSubjectBuilder.Factory<CustomSubjectBuilderT> factory) A generic, advanced method of extension of Truth to new types, which is documented onCustomSubjectBuilder. Extension creators should preferSubject.Factoryif possible. -
fail
public final void fail()Reports a failure.To set a message, first call
withMessage(java.lang.String)(or, more commonly, use the shortcutTruth.assertWithMessage(java.lang.String)).
-