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
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.
-
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 someSubjectclass, returns a builder whosethat(actual)method creates instances of that class.(package private) voidExtension point invoked before every assertion.final voidfail()Reports a failure.static StandardSubjectBuilderforCustomFailureStrategy(FailureStrategy failureStrategy) Returns a new instance that invokes the givenFailureStrategywhen a check fails.private FailureMetadatametadata()that(boolean[] actual) that(byte[] actual) that(char[] actual) that(double[] actual) that(float[] actual) final PrimitiveIntArraySubjectthat(int[] actual) that(long[] actual) that(short[] actual) final GuavaOptionalSubjectthat(com.google.common.base.Optional<?> actual) final MultimapSubjectthat(com.google.common.collect.Multimap<?, ?> actual) final MultisetSubjectthat(com.google.common.collect.Multiset<?> actual) final TableSubjectthat(com.google.common.collect.Table<?, ?, ?> actual) final <ComparableT extends Comparable<?>>
ComparableSubject<ComparableT> that(ComparableT actual) final BooleanSubjectfinal ClassSubjectfinal DoubleSubjectfinal FloatSubjectfinal IntegerSubjectfinal IterableSubjectfinal LongSubjectfinal Subjectfinal StringSubjectfinal ThrowableSubjectfinal BigDecimalSubjectthat(BigDecimal actual) final MapSubjectfinal <T> ObjectArraySubject<T> that(T[] actual) final StandardSubjectBuilderwithMessage(String messageToPrepend) Returns a new instance that will output the given message before the main failure message.final StandardSubjectBuilderwithMessage(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 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(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%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) -
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 allowsExpectto check that it's been set up properly as aTestRule.
-