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
Subject
to create withabout(Subject.Factory)
. - For the types of
Subject
built 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) final <S extends Subject, A>
SimpleSubjectBuilder<S, A> about
(Subject.Factory<S, A> factory) Given a factory for someSubject
class, returns a builder whosethat(actual)
method creates instances of that class.final void
fail()
Reports a failure.static StandardSubjectBuilder
forCustomFailureStrategy
(FailureStrategy failureStrategy) Returns a new instance that invokes the givenFailureStrategy
when a check fails.final PrimitiveIntArraySubject
final <ComparableT extends Comparable<?>>
ComparableSubject<ComparableT> final GuavaOptionalSubject
final MultimapSubject
final MultisetSubject
final TableSubject
final BooleanSubject
final ClassSubject
final DoubleSubject
final FloatSubject
final IntegerSubject
final IterableSubject
final LongSubject
final Subject
final StringSubject
final ThrowableSubject
final BigDecimalSubject
that
(@Nullable BigDecimal actual) final PathSubject
final MapSubject
final OptionalSubject
final OptionalDoubleSubject
that
(@Nullable OptionalDouble actual) final OptionalIntSubject
that
(@Nullable OptionalInt actual) final OptionalLongSubject
that
(@Nullable OptionalLong actual) final IntStreamSubject
final LongStreamSubject
that
(@Nullable LongStream actual) final StreamSubject
final <T extends @Nullable Object>
ObjectArraySubject<T> final StandardSubjectBuilder
withMessage
(@Nullable String messageToPrepend) Returns a new instance that will output the given message before the main failure message.final StandardSubjectBuilder
withMessage
(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 givenFailureStrategy
when 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
OptionalSubject
previously part oftruth-java8-extension
)
-
that
- Since:
- 1.4.0 (with access to
OptionalIntSubject
previously part oftruth-java8-extension
)
-
that
- Since:
- 1.4.0 (with access to
OptionalLongSubject
previously part oftruth-java8-extension
)
-
that
- Since:
- 1.4.0 (with access to
OptionalDoubleSubject
previously part oftruth-java8-extension
)
-
that
- Since:
- 1.3.0 (with access to
StreamSubject
previously part oftruth-java8-extension
)
-
that
- Since:
- 1.4.0 (with access to
IntStreamSubject
previously part oftruth-java8-extension
)
-
that
- Since:
- 1.4.0 (with access to
LongStreamSubject
previously part oftruth-java8-extension
)
-
that
- Since:
- 1.4.0 (with access to
PathSubject
previously 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%s
specifier.- Throws:
IllegalArgumentException
- if the number of placeholders in the format string does not equal the number of given arguments
-
about
Given a factory for someSubject
class, 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) -
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)
).
-