public final class Truth extends Object
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.Modifier and Type | Field and Description |
---|---|
static TestVerb |
ASSERT |
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 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 <T,C extends Collection<T>> |
assertThat(Collection<T> target)
Deprecated.
Use the
Iterable overload instead. |
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 <T,C extends List<T>> |
assertThat(List<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 <K,V,M extends Map<K,V>> |
assertThat(Map<K,V> 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 <R,C,V,M extends com.google.common.collect.Table<R,C,V>> |
assertThat(com.google.common.collect.Table<R,C,V> 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 final TestVerb ASSERT
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 SubjectFactory@CheckReturnValue public static <T extends Comparable<?>> ComparableSubject<?,T> assertThat(T target)
@CheckReturnValue public static Subject<DefaultSubject,Object> assertThat(Object target)
@CheckReturnValue @GwtIncompatible(value="ClassSubject.java") public static ClassSubject assertThat(Class<?> target)
@CheckReturnValue public static ThrowableSubject assertThat(Throwable target)
@CheckReturnValue public static LongSubject assertThat(Long target)
@CheckReturnValue public static IntegerSubject assertThat(Integer target)
@CheckReturnValue public static BooleanSubject assertThat(Boolean target)
@CheckReturnValue public static StringSubject assertThat(String target)
@CheckReturnValue public static <T,C extends Iterable<T>> IterableSubject<? extends IterableSubject<?,T,C>,T,C> assertThat(Iterable<T> target)
@Deprecated @CheckReturnValue public static <T,C extends Collection<T>> CollectionSubject<? extends CollectionSubject<?,T,C>,T,C> assertThat(Collection<T> target)
Iterable
overload instead.@CheckReturnValue public static <T,C extends List<T>> ListSubject<? extends ListSubject<?,T,C>,T,C> assertThat(List<T> target)
@CheckReturnValue public static <T> ObjectArraySubject<T> assertThat(T[] target)
@CheckReturnValue public static PrimitiveBooleanArraySubject assertThat(boolean[] target)
@CheckReturnValue public static PrimitiveIntArraySubject assertThat(int[] target)
@CheckReturnValue public static PrimitiveLongArraySubject assertThat(long[] target)
@CheckReturnValue public static PrimitiveByteArraySubject assertThat(byte[] target)
@CheckReturnValue public static PrimitiveCharArraySubject assertThat(char[] target)
@CheckReturnValue public static PrimitiveFloatArraySubject assertThat(float[] target)
@CheckReturnValue public static PrimitiveDoubleArraySubject assertThat(double[] target)
@CheckReturnValue public static <T> OptionalSubject<T> assertThat(com.google.common.base.Optional<T> target)
@CheckReturnValue public static <K,V,M extends Map<K,V>> MapSubject<? extends MapSubject<?,K,V,M>,K,V,M> assertThat(Map<K,V> target)
@CheckReturnValue public static <K,V,M extends com.google.common.collect.Multimap<K,V>> MultimapSubject<? extends MultimapSubject<?,K,V,M>,K,V,M> assertThat(com.google.common.collect.Multimap<K,V> target)
@CheckReturnValue public static <K,V,M extends com.google.common.collect.ListMultimap<K,V>> ListMultimapSubject<? extends ListMultimapSubject<?,K,V,M>,K,V,M> assertThat(com.google.common.collect.ListMultimap<K,V> target)
@CheckReturnValue public static <K,V,M extends com.google.common.collect.SetMultimap<K,V>> SetMultimapSubject<? extends SetMultimapSubject<?,K,V,M>,K,V,M> assertThat(com.google.common.collect.SetMultimap<K,V> target)
@CheckReturnValue public static <E,M extends com.google.common.collect.Multiset<E>> MultisetSubject<? extends MultisetSubject<?,E,M>,E,M> assertThat(com.google.common.collect.Multiset<E> target)
@CheckReturnValue public static <R,C,V,M extends com.google.common.collect.Table<R,C,V>> TableSubject<? extends TableSubject<?,R,C,V,M>,R,C,V,M> assertThat(com.google.common.collect.Table<R,C,V> target)
Copyright © 2014. All rights reserved.