@CheckReturnValue public final class Truth extends Object
Truth is the simplest entry point class. A developer can statically import the assertThat() method to get easy access to the library's capabilities. Then, instead of writing:
Assert.assertEquals(a, b);
Assert.assertTrue(c);
Assert.assertTrue(d.contains(a));
Assert.assertTrue(d.contains(a) && d.contains(b));
Assert.assertTrue(d.contains(a) || d.contains(b) || d.contains(c));
one would write:
assertThat(a).isEqualTo(b);
assertThat(c).isTrue();
assertThat(d).contains(a);
assertThat(d).containsAllOf(a, b);
assertThat(d).containsAnyOf(a, b, c);
Tests should be easier to read, and flow more clearly.
Often, tests assert a relationship between a value produced by the test (the "actual" value) and some reference value (the "expected" value). It is strongly recommended that the actual value is made the subject of the assertion. For example:
assertThat(actual).isEqualTo(expected); // recommended
assertThat(expected).isEqualTo(actual); // not recommended
assertThat(actual).isIn(expectedPossibilities); // recommended
assertThat(expectedPossibilities).contains(actual); // not recommended
Modifier and Type | Field and Description |
---|---|
static FailureStrategy |
THROW_ASSERTION_ERROR |
Constructor and Description |
---|
Truth() |
Modifier and Type | Method and Description |
---|---|
static TestVerb |
assert_() |
static <S extends Subject<S,T>,T,SF extends SubjectFactory<S,T>> |
assertAbout(SF factory)
The recommended method of extension of Truth to new types, which is
documented in
com.google.common.truth.delegation.DelegationTest . |
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 PrimitiveFloatArraySubject |
assertThat(float[] target) |
static PrimitiveIntArraySubject |
assertThat(int[] target) |
static IntegerSubject |
assertThat(Integer target) |
static <T,C extends Iterable<T>> |
assertThat(Iterable<T> target) |
static <K,V,M extends com.google.common.collect.ListMultimap<K,V>> |
assertThat(com.google.common.collect.ListMultimap<K,V> target) |
static LongSubject |
assertThat(Long target) |
static PrimitiveLongArraySubject |
assertThat(long[] target) |
static MapSubject |
assertThat(Map<?,?> target) |
static <K,V,M extends com.google.common.collect.Multimap<K,V>> |
assertThat(com.google.common.collect.Multimap<K,V> target) |
static <E,M extends com.google.common.collect.Multiset<E>> |
assertThat(com.google.common.collect.Multiset<E> target) |
static Subject<DefaultSubject,Object> |
assertThat(Object target) |
static <T> OptionalSubject<T> |
assertThat(com.google.common.base.Optional<T> target) |
static <K,V,M extends com.google.common.collect.SetMultimap<K,V>> |
assertThat(com.google.common.collect.SetMultimap<K,V> 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 TestVerb |
assertWithMessage(String messageToPrepend)
Returns a
TestVerb that will prepend the given message to the failure message in
the event of a test failure. |
public static final FailureStrategy THROW_ASSERTION_ERROR
public static TestVerb assert_()
public static TestVerb assertWithMessage(String messageToPrepend)
TestVerb
that will prepend the given message to the failure message in
the event of a test failure.public static <S extends Subject<S,T>,T,SF extends SubjectFactory<S,T>> AbstractVerb.DelegatedVerb<S,T> assertAbout(SF factory)
com.google.common.truth.delegation.DelegationTest
.factory
- a SubjectFactorypublic 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 IntegerSubject assertThat(@Nullable Integer target)
public static BooleanSubject assertThat(@Nullable Boolean target)
public static StringSubject assertThat(@Nullable String target)
public static <T,C extends Iterable<T>> IterableSubject<? extends IterableSubject<?,T,C>,T,C> assertThat(@Nullable Iterable<T> target)
public static <T> ObjectArraySubject<T> assertThat(@Nullable T[] target)
public static PrimitiveBooleanArraySubject assertThat(@Nullable boolean[] 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 <T> OptionalSubject<T> assertThat(@Nullable com.google.common.base.Optional<T> target)
public static MapSubject assertThat(@Nullable Map<?,?> target)
public static <K,V,M extends com.google.common.collect.Multimap<K,V>> MultimapSubject<? extends MultimapSubject<?,K,V,M>,K,V,M> assertThat(@Nullable com.google.common.collect.Multimap<K,V> target)
public static <K,V,M extends com.google.common.collect.ListMultimap<K,V>> ListMultimapSubject<? extends ListMultimapSubject<?,K,V,M>,K,V,M> assertThat(@Nullable com.google.common.collect.ListMultimap<K,V> target)
public static <K,V,M extends com.google.common.collect.SetMultimap<K,V>> SetMultimapSubject<? extends SetMultimapSubject<?,K,V,M>,K,V,M> assertThat(@Nullable com.google.common.collect.SetMultimap<K,V> target)
public static <E,M extends com.google.common.collect.Multiset<E>> MultisetSubject<? extends MultisetSubject<?,E,M>,E,M> assertThat(@Nullable com.google.common.collect.Multiset<E> target)
public static TableSubject assertThat(@Nullable com.google.common.collect.Table<?,?,?> target)
Copyright © 2015. All rights reserved.