Package com.google.common.truth
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.
-
Field Summary
Fields -
Constructor Summary
Constructors -
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.(package private) void
Extension point invoked before every assertion.final void
fail()
Reports a failure.static StandardSubjectBuilder
forCustomFailureStrategy
(FailureStrategy failureStrategy) Returns a new instance that invokes the givenFailureStrategy
when a check fails.private FailureMetadata
metadata()
that
(boolean[] actual) that
(byte[] actual) that
(char[] actual) that
(double[] actual) that
(float[] actual) final PrimitiveIntArraySubject
that
(int[] actual) that
(long[] actual) that
(short[] actual) final GuavaOptionalSubject
that
(com.google.common.base.Optional<?> actual) final MultimapSubject
that
(com.google.common.collect.Multimap<?, ?> actual) final MultisetSubject
that
(com.google.common.collect.Multiset<?> actual) final TableSubject
that
(com.google.common.collect.Table<?, ?, ?> actual) final <ComparableT extends Comparable<?>>
ComparableSubject<ComparableT>that
(ComparableT actual) final BooleanSubject
final ClassSubject
final DoubleSubject
final FloatSubject
final IntegerSubject
final IterableSubject
final LongSubject
final Subject
final StringSubject
final ThrowableSubject
final BigDecimalSubject
that
(BigDecimal actual) final MapSubject
final <T> ObjectArraySubject<T>
that
(T[] actual) final StandardSubjectBuilder
withMessage
(String messageToPrepend) Returns a new instance that will output the given message before the main failure message.final StandardSubjectBuilder
withMessage
(String format, Object... args) Returns a new instance that will output the given message before the main failure message.
-
Field Details
-
metadataDoNotReferenceDirectly
-
-
Constructor Details
-
StandardSubjectBuilder
StandardSubjectBuilder(FailureMetadata metadata)
-
-
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(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
-
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)
). -
metadata
-
checkStatePreconditions
void checkStatePreconditions()Extension point invoked before every assertion. This allowsExpect
to check that it's been set up properly as aTestRule
.
-