Package com.google.common.truth
Class StandardSubjectBuilder
- java.lang.Object
-
- com.google.common.truth.StandardSubjectBuilder
-
- Direct Known Subclasses:
Expect
public class StandardSubjectBuilder extends 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.
-
-
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.void
fail()
Reports a failure.static StandardSubjectBuilder
forCustomFailureStrategy(FailureStrategy failureStrategy)
Returns a new instance that invokes the givenFailureStrategy
when a check fails.PrimitiveBooleanArraySubject
that(boolean @Nullable [] actual)
PrimitiveByteArraySubject
that(byte @Nullable [] actual)
PrimitiveCharArraySubject
that(char @Nullable [] actual)
PrimitiveDoubleArraySubject
that(double @Nullable [] actual)
PrimitiveFloatArraySubject
that(float @Nullable [] actual)
PrimitiveIntArraySubject
that(int @Nullable [] actual)
PrimitiveLongArraySubject
that(long @Nullable [] actual)
PrimitiveShortArraySubject
that(short @Nullable [] actual)
GuavaOptionalSubject
that(@Nullable Optional<?> actual)
MultimapSubject
that(@Nullable Multimap<?,?> actual)
MultisetSubject
that(@Nullable Multiset<?> actual)
TableSubject
that(@Nullable Table<?,?,?> actual)
<ComparableT extends Comparable<?>>
ComparableSubject<ComparableT>that(@Nullable ComparableT actual)
BooleanSubject
that(@Nullable Boolean actual)
ClassSubject
that(@Nullable Class<?> actual)
DoubleSubject
that(@Nullable Double actual)
FloatSubject
that(@Nullable Float actual)
IntegerSubject
that(@Nullable Integer actual)
IterableSubject
that(@Nullable Iterable<?> actual)
LongSubject
that(@Nullable Long actual)
Subject
that(@Nullable Object actual)
StringSubject
that(@Nullable String actual)
ThrowableSubject
that(@Nullable Throwable actual)
BigDecimalSubject
that(@Nullable BigDecimal actual)
PathSubject
that(@Nullable Path actual)
MapSubject
that(@Nullable Map<?,?> actual)
OptionalSubject
that(@Nullable Optional<?> actual)
OptionalDoubleSubject
that(@Nullable OptionalDouble actual)
OptionalIntSubject
that(@Nullable OptionalInt actual)
OptionalLongSubject
that(@Nullable OptionalLong actual)
IntStreamSubject
that(@Nullable IntStream actual)
LongStreamSubject
that(@Nullable LongStream actual)
StreamSubject
that(@Nullable Stream<?> actual)
<T extends @Nullable Object>
ObjectArraySubject<T>that(T @Nullable [] actual)
StandardSubjectBuilder
withMessage(@Nullable String messageToPrepend)
Returns a new instance that will output the given message before the main failure message.StandardSubjectBuilder
withMessage(String format, @Nullable Object... args)
Returns a new instance that will output the given message before the main failure message.
-
-
-
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 Comparable<?>> ComparableSubject<ComparableT> that(@Nullable ComparableT actual)
-
that
public final BigDecimalSubject that(@Nullable BigDecimal actual)
-
that
@GwtIncompatible("ClassSubject.java") public final ClassSubject that(@Nullable Class<?> actual)
-
that
public final ThrowableSubject that(@Nullable Throwable actual)
-
that
public final LongSubject that(@Nullable Long actual)
-
that
public final DoubleSubject that(@Nullable Double actual)
-
that
public final FloatSubject that(@Nullable Float actual)
-
that
public final IntegerSubject that(@Nullable Integer actual)
-
that
public final BooleanSubject that(@Nullable Boolean actual)
-
that
public final StringSubject that(@Nullable String actual)
-
that
public final IterableSubject that(@Nullable Iterable<?> actual)
-
that
public final <T extends @Nullable Object> ObjectArraySubject<T> that(T @Nullable [] actual)
-
that
public final PrimitiveBooleanArraySubject that(boolean @Nullable [] actual)
-
that
public final PrimitiveShortArraySubject that(short @Nullable [] actual)
-
that
public final PrimitiveIntArraySubject that(int @Nullable [] actual)
-
that
public final PrimitiveLongArraySubject that(long @Nullable [] actual)
-
that
public final PrimitiveCharArraySubject that(char @Nullable [] actual)
-
that
public final PrimitiveByteArraySubject that(byte @Nullable [] actual)
-
that
public final PrimitiveFloatArraySubject that(float @Nullable [] actual)
-
that
public final PrimitiveDoubleArraySubject that(double @Nullable [] actual)
-
that
public final GuavaOptionalSubject that(@Nullable Optional<?> actual)
-
that
public final MapSubject that(@Nullable Map<?,?> actual)
-
that
public final MultimapSubject that(@Nullable Multimap<?,?> actual)
-
that
public final MultisetSubject that(@Nullable Multiset<?> actual)
-
that
public final TableSubject that(@Nullable Table<?,?,?> actual)
-
that
public final OptionalSubject that(@Nullable Optional<?> actual)
- Since:
- 1.3.0 (with access to
OptionalSubject
previously part oftruth-java8-extension
)
-
that
public final OptionalIntSubject that(@Nullable OptionalInt actual)
- Since:
- 1.4.0 (with access to
OptionalIntSubject
previously part oftruth-java8-extension
)
-
that
public final OptionalLongSubject that(@Nullable OptionalLong actual)
- Since:
- 1.4.0 (with access to
OptionalLongSubject
previously part oftruth-java8-extension
)
-
that
public final OptionalDoubleSubject that(@Nullable OptionalDouble actual)
- Since:
- 1.4.0 (with access to
OptionalDoubleSubject
previously part oftruth-java8-extension
)
-
that
public final StreamSubject that(@Nullable Stream<?> actual)
- Since:
- 1.3.0 (with access to
StreamSubject
previously part oftruth-java8-extension
)
-
that
public final IntStreamSubject that(@Nullable IntStream actual)
- Since:
- 1.4.0 (with access to
IntStreamSubject
previously part oftruth-java8-extension
)
-
that
public final LongStreamSubject that(@Nullable LongStream actual)
- Since:
- 1.4.0 (with access to
LongStreamSubject
previously part oftruth-java8-extension
)
-
that
@GwtIncompatible @J2ObjCIncompatible public final PathSubject that(@Nullable Path actual)
- Since:
- 1.4.0 (with access to
PathSubject
previously part oftruth-java8-extension
)
-
withMessage
public final StandardSubjectBuilder withMessage(@Nullable 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(String format, @Nullable 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:
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)
).
-
-