Package com.google.common.truth
Class StandardSubjectBuilder
- java.lang.Object
-
- com.google.common.truth.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:- 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 Modifier and Type Field Description private FailureMetadata
metadataDoNotReferenceDirectly
-
Constructor Summary
Constructors Constructor Description StandardSubjectBuilder(FailureMetadata metadata)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <CustomSubjectBuilderT extends CustomSubjectBuilder>
CustomSubjectBuilderTabout(CustomSubjectBuilder.Factory<CustomSubjectBuilderT> factory)
<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
checkStatePreconditions()
Extension point invoked before every assertion.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()
PrimitiveBooleanArraySubject
that(boolean[] actual)
PrimitiveByteArraySubject
that(byte[] actual)
PrimitiveCharArraySubject
that(char[] actual)
PrimitiveDoubleArraySubject
that(double[] actual)
PrimitiveFloatArraySubject
that(float[] actual)
PrimitiveIntArraySubject
that(int[] actual)
PrimitiveLongArraySubject
that(long[] actual)
PrimitiveShortArraySubject
that(short[] actual)
GuavaOptionalSubject
that(com.google.common.base.Optional<?> actual)
MultimapSubject
that(com.google.common.collect.Multimap<?,?> actual)
MultisetSubject
that(com.google.common.collect.Multiset<?> actual)
TableSubject
that(com.google.common.collect.Table<?,?,?> actual)
<ComparableT extends java.lang.Comparable<?>>
ComparableSubject<ComparableT>that(ComparableT actual)
BooleanSubject
that(java.lang.Boolean actual)
ClassSubject
that(java.lang.Class<?> actual)
DoubleSubject
that(java.lang.Double actual)
FloatSubject
that(java.lang.Float actual)
IntegerSubject
that(java.lang.Integer actual)
IterableSubject
that(java.lang.Iterable<?> actual)
LongSubject
that(java.lang.Long actual)
Subject
that(java.lang.Object actual)
StringSubject
that(java.lang.String actual)
ThrowableSubject
that(java.lang.Throwable actual)
BigDecimalSubject
that(java.math.BigDecimal actual)
MapSubject
that(java.util.Map<?,?> actual)
<T> ObjectArraySubject<T>
that(T[] actual)
StandardSubjectBuilder
withMessage(java.lang.String messageToPrepend)
Returns a new instance that will output the given message before the main failure message.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.
-
-
-
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 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 java.lang.Comparable<?>> ComparableSubject<ComparableT> that(ComparableT actual)
-
that
public final BigDecimalSubject that(java.math.BigDecimal actual)
-
that
public final Subject that(java.lang.Object actual)
-
that
public final ClassSubject that(java.lang.Class<?> actual)
-
that
public final ThrowableSubject that(java.lang.Throwable 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 <T> ObjectArraySubject<T> that(T[] actual)
-
that
public final PrimitiveBooleanArraySubject that(boolean[] actual)
-
that
public final PrimitiveShortArraySubject that(short[] actual)
-
that
public final PrimitiveIntArraySubject that(int[] actual)
-
that
public final PrimitiveLongArraySubject that(long[] actual)
-
that
public final PrimitiveCharArraySubject that(char[] actual)
-
that
public final PrimitiveByteArraySubject that(byte[] actual)
-
that
public final PrimitiveFloatArraySubject that(float[] actual)
-
that
public final PrimitiveDoubleArraySubject that(double[] actual)
-
that
public final GuavaOptionalSubject that(com.google.common.base.Optional<?> 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 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
private FailureMetadata metadata()
-
checkStatePreconditions
void checkStatePreconditions()
Extension point invoked before every assertion. This allowsExpect
to check that it's been set up properly as aTestRule
.
-
-