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...)
)
For more information about the methods in this class, see this FAQ entry.
The most common way to extend Truth is to write a custom Subject
. (The other, much
less common way is to write a custom FailureStrategy
.) For more information, visit those
types' docs.
Modifier and Type | Method and Description |
---|---|
static StandardSubjectBuilder |
assert_()
Begins a call chain with the fluent Truth API.
|
static <CustomSubjectBuilderT extends CustomSubjectBuilder> |
assertAbout(CustomSubjectBuilder.Factory<CustomSubjectBuilderT> factory)
A generic, advanced method of extension of Truth to new types, which is documented on
CustomSubjectBuilder . |
static <S extends Subject<S,T>,T> |
assertAbout(Subject.Factory<S,T> factory)
Given a factory for some
Subject class, returns a builder whose that(actual)
method creates instances of that class. |
static AtomicLongMapSubject |
assertThat(AtomicLongMap<?> actual) |
static BigDecimalSubject |
assertThat(BigDecimal actual) |
static BooleanSubject |
assertThat(Boolean actual) |
static PrimitiveBooleanArraySubject |
assertThat(boolean[] actual) |
static PrimitiveByteArraySubject |
assertThat(byte[] actual) |
static PrimitiveCharArraySubject |
assertThat(char[] actual) |
static ClassSubject |
assertThat(Class<?> actual) |
static DoubleSubject |
assertThat(Double actual) |
static PrimitiveDoubleArraySubject |
assertThat(double[] actual) |
static FloatSubject |
assertThat(Float actual) |
static PrimitiveFloatArraySubject |
assertThat(float[] actual) |
static PrimitiveIntArraySubject |
assertThat(int[] actual) |
static IntegerSubject |
assertThat(Integer actual) |
static IterableSubject |
assertThat(Iterable<?> actual) |
static ListMultimapSubject |
assertThat(ListMultimap<?,?> actual) |
static LongSubject |
assertThat(Long actual) |
static PrimitiveLongArraySubject |
assertThat(long[] actual) |
static MapSubject |
assertThat(Map<?,?> actual) |
static MultimapSubject |
assertThat(Multimap<?,?> actual) |
static MultisetSubject |
assertThat(Multiset<?> actual) |
static Subject<DefaultSubject,Object> |
assertThat(Object actual) |
static GuavaOptionalSubject |
assertThat(Optional<?> actual) |
static SetMultimapSubject |
assertThat(SetMultimap<?,?> actual) |
static PrimitiveShortArraySubject |
assertThat(short[] actual) |
static SortedMapSubject |
assertThat(SortedMap<?,?> actual) |
static SortedSetSubject |
assertThat(SortedSet<?> actual) |
static StringSubject |
assertThat(String actual) |
static <T extends Comparable<?>> |
assertThat(T actual) |
static <T> ObjectArraySubject<T> |
assertThat(T[] actual) |
static TableSubject |
assertThat(Table<?,?,?> actual) |
static ThrowableSubject |
assertThat(Throwable actual) |
static StandardSubjectBuilder |
assertWithMessage(String messageToPrepend)
Returns a
StandardSubjectBuilder 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
StandardSubjectBuilder that will prepend the formatted message using the
specified arguments to the failure message in the event of a test failure. |
public static StandardSubjectBuilder assert_()
AssertionError
.public static StandardSubjectBuilder assertWithMessage(String messageToPrepend)
StandardSubjectBuilder
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)
StandardSubjectBuilder
that will prepend the formatted message using the
specified arguments to the failure message in the event of a test failure.
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 static <S extends Subject<S,T>,T> SimpleSubjectBuilder<S,T> assertAbout(Subject.Factory<S,T> factory)
Subject
class, returns a builder whose that(actual)
method creates instances of that class.public static <CustomSubjectBuilderT extends CustomSubjectBuilder> CustomSubjectBuilderT assertAbout(CustomSubjectBuilder.Factory<CustomSubjectBuilderT> factory)
CustomSubjectBuilder
. Extension creators should prefer Subject.Factory
if possible.public static <T extends Comparable<?>> ComparableSubject<?,T> assertThat(@NullableDecl T actual)
public static BigDecimalSubject assertThat(@NullableDecl BigDecimal actual)
public static Subject<DefaultSubject,Object> assertThat(@NullableDecl Object actual)
@GwtIncompatible(value="ClassSubject.java") public static ClassSubject assertThat(@NullableDecl Class<?> actual)
public static ThrowableSubject assertThat(@NullableDecl Throwable actual)
public static LongSubject assertThat(@NullableDecl Long actual)
public static DoubleSubject assertThat(@NullableDecl Double actual)
public static FloatSubject assertThat(@NullableDecl Float actual)
public static IntegerSubject assertThat(@NullableDecl Integer actual)
public static BooleanSubject assertThat(@NullableDecl Boolean actual)
public static StringSubject assertThat(@NullableDecl String actual)
public static IterableSubject assertThat(@NullableDecl Iterable<?> actual)
public static SortedSetSubject assertThat(@NullableDecl SortedSet<?> actual)
public static <T> ObjectArraySubject<T> assertThat(@NullableDecl T[] actual)
public static PrimitiveBooleanArraySubject assertThat(@NullableDecl boolean[] actual)
public static PrimitiveShortArraySubject assertThat(@NullableDecl short[] actual)
public static PrimitiveIntArraySubject assertThat(@NullableDecl int[] actual)
public static PrimitiveLongArraySubject assertThat(@NullableDecl long[] actual)
public static PrimitiveByteArraySubject assertThat(@NullableDecl byte[] actual)
public static PrimitiveCharArraySubject assertThat(@NullableDecl char[] actual)
public static PrimitiveFloatArraySubject assertThat(@NullableDecl float[] actual)
public static PrimitiveDoubleArraySubject assertThat(@NullableDecl double[] actual)
public static GuavaOptionalSubject assertThat(@NullableDecl Optional<?> actual)
public static MapSubject assertThat(@NullableDecl Map<?,?> actual)
public static SortedMapSubject assertThat(@NullableDecl SortedMap<?,?> actual)
public static MultimapSubject assertThat(@NullableDecl Multimap<?,?> actual)
public static ListMultimapSubject assertThat(@NullableDecl ListMultimap<?,?> actual)
public static SetMultimapSubject assertThat(@NullableDecl SetMultimap<?,?> actual)
public static MultisetSubject assertThat(@NullableDecl Multiset<?> actual)
public static TableSubject assertThat(@NullableDecl Table<?,?,?> actual)
public static AtomicLongMapSubject assertThat(@NullableDecl AtomicLongMap<?> actual)
Copyright © 2018. All rights reserved.