public final class Truth extends Object
Compare these example JUnit assertions...
assertEquals(b, a);
assertTrue(c);
assertTrue(d.contains(a));
assertTrue(d.contains(a) && d.contains(b));
assertTrue(d.contains(a) || d.contains(b) || d.contains(c));
...to their Truth equivalents...
assertThat(a).isEqualTo(b);
assertThat(c).isTrue();
assertThat(d).contains(a);
assertThat(d).containsAllOf(a, b);
assertThat(d).containsAnyOf(a, b, c);
Advantages of Truth:
IterableSubject.containsExactly(java.lang.Object...)
)
TODO(cpovirk): Link to a doc about the full assertion chain.
TODO(cpovirk): Link to a doc about custom subjects.
TODO(cpovirk): Also talk about FailureStrategy
.
Modifier and Type | Field and Description |
---|---|
static FailureStrategy |
THROW_ASSERTION_ERROR |
Modifier and Type | Method and Description |
---|---|
static StandardSubjectBuilder |
assert_()
Begins a call chain with the fluent Truth API.
|
static <CustomSubjectBuilderT extends CustomSubjectBuilder> |
assertAbout(CustomSubjectBuilderFactory<CustomSubjectBuilderT> factory)
A generic, advanced method of extension of Truth to new types, which is documented on
CustomSubjectBuilder . |
static <V extends AbstractDelegatedVerb> |
assertAbout(DelegatedVerbFactory<V> factory)
Deprecated.
When you switch from implementing
DelegatedVerbFactory to implementing
CustomSubjectBuilderFactory , you'll switch from this overload to the overload that accepts a CustomSubjectBuilderFactory . |
static <S extends Subject<S,T>,T> |
assertAbout(SubjectFactory<S,T> factory)
The recommended method of extension of Truth to new types, which is documented in
com.google.common.truth.delegation.DelegationTest . |
static AtomicLongMapSubject |
assertThat(com.google.common.util.concurrent.AtomicLongMap<?> target) |
static BigDecimalSubject |
assertThat(BigDecimal target) |
static BooleanSubject |
assertThat(Boolean target) |
static PrimitiveBooleanArraySubject |
assertThat(boolean[] target) |
static PrimitiveByteArraySubject |
assertThat(byte[] target) |
static PrimitiveCharArraySubject |
assertThat(char[] target) |
static ClassSubject |
assertThat(Class<?> target) |
static DoubleSubject |
assertThat(Double target) |
static PrimitiveDoubleArraySubject |
assertThat(double[] target) |
static FloatSubject |
assertThat(Float target) |
static PrimitiveFloatArraySubject |
assertThat(float[] target) |
static PrimitiveIntArraySubject |
assertThat(int[] target) |
static IntegerSubject |
assertThat(Integer target) |
static IterableSubject |
assertThat(Iterable<?> target) |
static ListMultimapSubject |
assertThat(com.google.common.collect.ListMultimap<?,?> target) |
static LongSubject |
assertThat(Long target) |
static PrimitiveLongArraySubject |
assertThat(long[] target) |
static MapSubject |
assertThat(Map<?,?> target) |
static MultimapSubject |
assertThat(com.google.common.collect.Multimap<?,?> target) |
static MultisetSubject |
assertThat(com.google.common.collect.Multiset<?> target) |
static Subject<DefaultSubject,Object> |
assertThat(Object target) |
static GuavaOptionalSubject |
assertThat(com.google.common.base.Optional<?> target) |
static SetMultimapSubject |
assertThat(com.google.common.collect.SetMultimap<?,?> target) |
static PrimitiveShortArraySubject |
assertThat(short[] target) |
static SortedMapSubject |
assertThat(SortedMap<?,?> target) |
static SortedSetSubject |
assertThat(SortedSet<?> target) |
static StringSubject |
assertThat(String target) |
static <T extends Comparable<?>> |
assertThat(T target) |
static <T> ObjectArraySubject<T> |
assertThat(T[] target) |
static TableSubject |
assertThat(com.google.common.collect.Table<?,?,?> target) |
static ThrowableSubject |
assertThat(Throwable target) |
static StandardSubjectBuilder |
assertWithMessage(String messageToPrepend)
Returns a
TestVerb that will prepend the given message to the failure message in the
event of a test failure. |
static StandardSubjectBuilder |
assertWithMessage(String format,
Object... args)
Returns a
TestVerb that will prepend the formatted message using the specified
arguments to the failure message in the event of a test failure. |
public static final FailureStrategy THROW_ASSERTION_ERROR
public static StandardSubjectBuilder assert_()
AssertionError
.public static StandardSubjectBuilder assertWithMessage(String messageToPrepend)
TestVerb
that will prepend the given message to the failure message in the
event of a test failure.public static StandardSubjectBuilder assertWithMessage(String format, Object... args)
TestVerb
that will prepend the formatted message using the specified
arguments to the failure message in the event of a test failure.
Note: The failure message template string only supports the "%s"
specifier,
not the full range of Formatter
specifiers.
IllegalArgumentException
- if the number of placeholders in the format string does not
equal the number of given argumentspublic static <S extends Subject<S,T>,T> SimpleSubjectBuilder<S,T> assertAbout(SubjectFactory<S,T> factory)
com.google.common.truth.delegation.DelegationTest
.factory
- a SubjectFactorypublic static <CustomSubjectBuilderT extends CustomSubjectBuilder> CustomSubjectBuilderT assertAbout(CustomSubjectBuilderFactory<CustomSubjectBuilderT> factory)
CustomSubjectBuilder
. Extension creators should prefer SubjectFactory
if possible.@Deprecated public static <V extends AbstractDelegatedVerb> V assertAbout(DelegatedVerbFactory<V> factory)
DelegatedVerbFactory
to implementing
CustomSubjectBuilderFactory
, you'll switch from this overload to the overload that accepts a CustomSubjectBuilderFactory
.DelegatedVerbFactory
. Extension creators should prefer SubjectFactory
if possible.V
- the type of AbstractDelegatedVerb
to returnfactory
- a DelegatedVerbFactory<V>
implementation<V>
public static <T extends Comparable<?>> ComparableSubject<?,T> assertThat(@Nullable T target)
public static BigDecimalSubject assertThat(@Nullable BigDecimal target)
public static Subject<DefaultSubject,Object> assertThat(@Nullable Object target)
@GwtIncompatible(value="ClassSubject.java") public static ClassSubject assertThat(@Nullable Class<?> target)
public static ThrowableSubject assertThat(@Nullable Throwable target)
public static LongSubject assertThat(@Nullable Long target)
public static DoubleSubject assertThat(@Nullable Double target)
public static FloatSubject assertThat(@Nullable Float target)
public static IntegerSubject assertThat(@Nullable Integer target)
public static BooleanSubject assertThat(@Nullable Boolean target)
public static StringSubject assertThat(@Nullable String target)
public static IterableSubject assertThat(@Nullable Iterable<?> target)
public static SortedSetSubject assertThat(@Nullable SortedSet<?> target)
public static <T> ObjectArraySubject<T> assertThat(@Nullable T[] target)
public static PrimitiveBooleanArraySubject assertThat(@Nullable boolean[] target)
public static PrimitiveShortArraySubject assertThat(@Nullable short[] target)
public static PrimitiveIntArraySubject assertThat(@Nullable int[] target)
public static PrimitiveLongArraySubject assertThat(@Nullable long[] target)
public static PrimitiveByteArraySubject assertThat(@Nullable byte[] target)
public static PrimitiveCharArraySubject assertThat(@Nullable char[] target)
public static PrimitiveFloatArraySubject assertThat(@Nullable float[] target)
public static PrimitiveDoubleArraySubject assertThat(@Nullable double[] target)
public static GuavaOptionalSubject assertThat(@Nullable com.google.common.base.Optional<?> target)
public static MapSubject assertThat(@Nullable Map<?,?> target)
public static SortedMapSubject assertThat(@Nullable SortedMap<?,?> target)
public static MultimapSubject assertThat(@Nullable com.google.common.collect.Multimap<?,?> target)
public static ListMultimapSubject assertThat(@Nullable com.google.common.collect.ListMultimap<?,?> target)
public static SetMultimapSubject assertThat(@Nullable com.google.common.collect.SetMultimap<?,?> target)
public static MultisetSubject assertThat(@Nullable com.google.common.collect.Multiset<?> target)
public static TableSubject assertThat(@Nullable com.google.common.collect.Table<?,?,?> target)
public static AtomicLongMapSubject assertThat(@Nullable com.google.common.util.concurrent.AtomicLongMap<?> target)
Copyright © 2017. All rights reserved.