public class StandardSubjectBuilder extends Object
withMessage(java.lang.String)
.
Subject
to create with about(Subject.Factory)
.
Subject
built into Truth, directly specify the value under test
with that(Object)
.
For more information about the methods in this class, see this FAQ entry.
You won't extend this type. When you write a custom subject, see our doc on extensions.
Modifier and Type | Method and Description |
---|---|
<CustomSubjectBuilderT extends CustomSubjectBuilder> |
about(CustomSubjectBuilder.Factory<CustomSubjectBuilderT> factory) |
<S extends Subject,A> |
about(Subject.Factory<S,A> factory)
Given a factory for some
Subject class, returns a builder whose that(actual)
method creates instances of that class. |
void |
fail()
Reports a failure.
|
void |
fail(String format,
Object... args)
Deprecated.
Instead of
assert_().fail(...) , use assertWithMessage(...).fail() .
Similarly, instead of expect.fail(...) , use expect.withMessage(...).fail() ,
and so forth. |
static StandardSubjectBuilder |
forCustomFailureStrategy(FailureStrategy failureStrategy)
Returns a new instance that invokes the given
FailureStrategy when a check fails. |
AtomicLongMapSubject |
that(AtomicLongMap<?> actual)
Deprecated.
Perform assertions on the
AtomicLongMap.asMap() view. |
BigDecimalSubject |
that(BigDecimal actual) |
BooleanSubject |
that(Boolean actual) |
PrimitiveBooleanArraySubject |
that(boolean[] actual) |
PrimitiveByteArraySubject |
that(byte[] actual) |
PrimitiveCharArraySubject |
that(char[] actual) |
ClassSubject |
that(Class<?> actual) |
<ComparableT extends Comparable<?>> |
that(ComparableT actual) |
DoubleSubject |
that(Double actual) |
PrimitiveDoubleArraySubject |
that(double[] actual) |
FloatSubject |
that(Float actual) |
PrimitiveFloatArraySubject |
that(float[] actual) |
PrimitiveIntArraySubject |
that(int[] actual) |
IntegerSubject |
that(Integer actual) |
IterableSubject |
that(Iterable<?> actual) |
LongSubject |
that(Long actual) |
PrimitiveLongArraySubject |
that(long[] actual) |
MapSubject |
that(Map<?,?> actual) |
MultimapSubject |
that(Multimap<?,?> actual) |
MultisetSubject |
that(Multiset<?> actual) |
Subject |
that(Object actual) |
GuavaOptionalSubject |
that(Optional<?> actual) |
PrimitiveShortArraySubject |
that(short[] actual) |
StringSubject |
that(String actual) |
<T> ObjectArraySubject<T> |
that(T[] actual) |
TableSubject |
that(Table<?,?,?> actual) |
ThrowableSubject |
that(Throwable actual) |
StandardSubjectBuilder |
withMessage(String messageToPrepend)
Returns a new instance that will output the given message before the main failure message.
|
StandardSubjectBuilder |
withMessage(String format,
Object... args)
Returns a new instance that will output the given message before the main failure message.
|
public static StandardSubjectBuilder forCustomFailureStrategy(FailureStrategy failureStrategy)
FailureStrategy
when a check fails. Most
users should not need this. If you think you do, see the documentation on FailureStrategy
.public final <ComparableT extends Comparable<?>> ComparableSubject<ComparableT> that(@NullableDecl ComparableT actual)
public final BigDecimalSubject that(@NullableDecl BigDecimal actual)
@GwtIncompatible(value="ClassSubject.java") public final ClassSubject that(@NullableDecl Class<?> actual)
public final ThrowableSubject that(@NullableDecl Throwable actual)
public final LongSubject that(@NullableDecl Long actual)
public final DoubleSubject that(@NullableDecl Double actual)
public final FloatSubject that(@NullableDecl Float actual)
public final IntegerSubject that(@NullableDecl Integer actual)
public final BooleanSubject that(@NullableDecl Boolean actual)
public final StringSubject that(@NullableDecl String actual)
public final IterableSubject that(@NullableDecl Iterable<?> actual)
public final <T> ObjectArraySubject<T> that(@NullableDecl T[] actual)
public final PrimitiveBooleanArraySubject that(@NullableDecl boolean[] actual)
public final PrimitiveShortArraySubject that(@NullableDecl short[] actual)
public final PrimitiveIntArraySubject that(@NullableDecl int[] actual)
public final PrimitiveLongArraySubject that(@NullableDecl long[] actual)
public final PrimitiveCharArraySubject that(@NullableDecl char[] actual)
public final PrimitiveByteArraySubject that(@NullableDecl byte[] actual)
public final PrimitiveFloatArraySubject that(@NullableDecl float[] actual)
public final PrimitiveDoubleArraySubject that(@NullableDecl double[] actual)
public final GuavaOptionalSubject that(@NullableDecl Optional<?> actual)
public final MapSubject that(@NullableDecl Map<?,?> actual)
public final MultimapSubject that(@NullableDecl Multimap<?,?> actual)
public final MultisetSubject that(@NullableDecl Multiset<?> actual)
public final TableSubject that(@NullableDecl Table<?,?,?> actual)
@Deprecated public final AtomicLongMapSubject that(@NullableDecl AtomicLongMap<?> actual)
AtomicLongMap.asMap()
view.public final StandardSubjectBuilder withMessage(@NullableDecl String messageToPrepend)
public final StandardSubjectBuilder withMessage(String format, Object... args)
Note: the arguments will be substituted into the format template using Strings.lenientFormat
. Note this only supports
the %s
specifier.
IllegalArgumentException
- if the number of placeholders in the format string does not
equal the number of given argumentspublic final <S extends Subject,A> SimpleSubjectBuilder<S,A> about(Subject.Factory<S,A> factory)
Subject
class, returns a builder whose that(actual)
method creates instances of that class. Created subjects use the previously set failure
strategy and any previously set failure message.public final <CustomSubjectBuilderT extends CustomSubjectBuilder> CustomSubjectBuilderT about(CustomSubjectBuilder.Factory<CustomSubjectBuilderT> factory)
public final void fail()
To set a message, first call withMessage(java.lang.String)
(or, more commonly, use the shortcut
Truth.assertWithMessage(java.lang.String)
).
@Deprecated public final void fail(String format, Object... args)
assert_().fail(...)
, use assertWithMessage(...).fail()
.
Similarly, instead of expect.fail(...)
, use expect.withMessage(...).fail()
,
and so forth.Copyright © 2019. All rights reserved.