code
stringlengths 23
201k
| docstring
stringlengths 17
96.2k
| func_name
stringlengths 0
235
| language
stringclasses 1
value | repo
stringlengths 8
72
| path
stringlengths 11
317
| url
stringlengths 57
377
| license
stringclasses 7
values |
|---|---|---|---|---|---|---|---|
public final PrimitiveIntArraySubject that(int @Nullable [] actual) {
return about(intArrays()).that(actual);
}
|
Returns a new instance that invokes the given {@code FailureStrategy} when a check fails. Most
users should not need this. If you think you do, see the documentation on {@link
FailureStrategy}.
|
that
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/StandardSubjectBuilder.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/StandardSubjectBuilder.java
|
Apache-2.0
|
public final PrimitiveLongArraySubject that(long @Nullable [] actual) {
return about(longArrays()).that(actual);
}
|
Returns a new instance that invokes the given {@code FailureStrategy} when a check fails. Most
users should not need this. If you think you do, see the documentation on {@link
FailureStrategy}.
|
that
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/StandardSubjectBuilder.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/StandardSubjectBuilder.java
|
Apache-2.0
|
public final PrimitiveCharArraySubject that(char @Nullable [] actual) {
return about(charArrays()).that(actual);
}
|
Returns a new instance that invokes the given {@code FailureStrategy} when a check fails. Most
users should not need this. If you think you do, see the documentation on {@link
FailureStrategy}.
|
that
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/StandardSubjectBuilder.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/StandardSubjectBuilder.java
|
Apache-2.0
|
public final PrimitiveByteArraySubject that(byte @Nullable [] actual) {
return about(byteArrays()).that(actual);
}
|
Returns a new instance that invokes the given {@code FailureStrategy} when a check fails. Most
users should not need this. If you think you do, see the documentation on {@link
FailureStrategy}.
|
that
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/StandardSubjectBuilder.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/StandardSubjectBuilder.java
|
Apache-2.0
|
public final PrimitiveFloatArraySubject that(float @Nullable [] actual) {
return about(floatArrays()).that(actual);
}
|
Returns a new instance that invokes the given {@code FailureStrategy} when a check fails. Most
users should not need this. If you think you do, see the documentation on {@link
FailureStrategy}.
|
that
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/StandardSubjectBuilder.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/StandardSubjectBuilder.java
|
Apache-2.0
|
public final PrimitiveDoubleArraySubject that(double @Nullable [] actual) {
return about(doubleArrays()).that(actual);
}
|
Returns a new instance that invokes the given {@code FailureStrategy} when a check fails. Most
users should not need this. If you think you do, see the documentation on {@link
FailureStrategy}.
|
that
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/StandardSubjectBuilder.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/StandardSubjectBuilder.java
|
Apache-2.0
|
public final GuavaOptionalSubject that(com.google.common.base.@Nullable Optional<?> actual) {
return about(guavaOptionals()).that(actual);
}
|
Returns a new instance that invokes the given {@code FailureStrategy} when a check fails. Most
users should not need this. If you think you do, see the documentation on {@link
FailureStrategy}.
|
that
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/StandardSubjectBuilder.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/StandardSubjectBuilder.java
|
Apache-2.0
|
public final MapSubject that(@Nullable Map<?, ?> actual) {
return about(maps()).that(actual);
}
|
Returns a new instance that invokes the given {@code FailureStrategy} when a check fails. Most
users should not need this. If you think you do, see the documentation on {@link
FailureStrategy}.
|
that
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/StandardSubjectBuilder.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/StandardSubjectBuilder.java
|
Apache-2.0
|
public final MultimapSubject that(@Nullable Multimap<?, ?> actual) {
return about(multimaps()).that(actual);
}
|
Returns a new instance that invokes the given {@code FailureStrategy} when a check fails. Most
users should not need this. If you think you do, see the documentation on {@link
FailureStrategy}.
|
that
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/StandardSubjectBuilder.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/StandardSubjectBuilder.java
|
Apache-2.0
|
public final MultisetSubject that(@Nullable Multiset<?> actual) {
return about(multisets()).that(actual);
}
|
Returns a new instance that invokes the given {@code FailureStrategy} when a check fails. Most
users should not need this. If you think you do, see the documentation on {@link
FailureStrategy}.
|
that
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/StandardSubjectBuilder.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/StandardSubjectBuilder.java
|
Apache-2.0
|
public final TableSubject that(@Nullable Table<?, ?, ?> actual) {
return about(tables()).that(actual);
}
|
Returns a new instance that invokes the given {@code FailureStrategy} when a check fails. Most
users should not need this. If you think you do, see the documentation on {@link
FailureStrategy}.
|
that
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/StandardSubjectBuilder.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/StandardSubjectBuilder.java
|
Apache-2.0
|
@SuppressWarnings("NullableOptional") // Truth always accepts nulls, no matter the type
public final OptionalSubject that(@Nullable Optional<?> actual) {
return about(optionals()).that(actual);
}
|
@since 1.3.0 (with access to {@link OptionalSubject} previously part of {@code
truth-java8-extension})
|
that
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/StandardSubjectBuilder.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/StandardSubjectBuilder.java
|
Apache-2.0
|
public final OptionalIntSubject that(@Nullable OptionalInt actual) {
return about(optionalInts()).that(actual);
}
|
@since 1.4.0 (with access to {@link OptionalIntSubject} previously part of {@code
truth-java8-extension})
|
that
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/StandardSubjectBuilder.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/StandardSubjectBuilder.java
|
Apache-2.0
|
public final OptionalLongSubject that(@Nullable OptionalLong actual) {
return about(optionalLongs()).that(actual);
}
|
@since 1.4.0 (with access to {@link OptionalLongSubject} previously part of {@code
truth-java8-extension})
|
that
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/StandardSubjectBuilder.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/StandardSubjectBuilder.java
|
Apache-2.0
|
public final OptionalDoubleSubject that(@Nullable OptionalDouble actual) {
return about(optionalDoubles()).that(actual);
}
|
@since 1.4.0 (with access to {@link OptionalDoubleSubject} previously part of {@code
truth-java8-extension})
|
that
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/StandardSubjectBuilder.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/StandardSubjectBuilder.java
|
Apache-2.0
|
public final StreamSubject that(@Nullable Stream<?> actual) {
return about(streams()).that(actual);
}
|
@since 1.3.0 (with access to {@link StreamSubject} previously part of {@code
truth-java8-extension})
|
that
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/StandardSubjectBuilder.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/StandardSubjectBuilder.java
|
Apache-2.0
|
public final IntStreamSubject that(@Nullable IntStream actual) {
return about(intStreams()).that(actual);
}
|
@since 1.4.0 (with access to {@link IntStreamSubject} previously part of {@code
truth-java8-extension})
|
that
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/StandardSubjectBuilder.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/StandardSubjectBuilder.java
|
Apache-2.0
|
public final LongStreamSubject that(@Nullable LongStream actual) {
return about(longStreams()).that(actual);
}
|
@since 1.4.0 (with access to {@link LongStreamSubject} previously part of {@code
truth-java8-extension})
|
that
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/StandardSubjectBuilder.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/StandardSubjectBuilder.java
|
Apache-2.0
|
@GwtIncompatible
@J2ObjCIncompatible
@J2ktIncompatible
public final PathSubject that(@Nullable Path actual) {
return about(paths()).that(actual);
}
|
@since 1.4.0 (with access to {@link PathSubject} previously part of {@code
truth-java8-extension})
|
that
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/StandardSubjectBuilder.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/StandardSubjectBuilder.java
|
Apache-2.0
|
public final StandardSubjectBuilder withMessage(@Nullable String messageToPrepend) {
return withMessage("%s", messageToPrepend);
}
|
Returns a new instance that will output the given message before the main failure message. If
this method is called multiple times, the messages will appear in the order that they were
specified.
|
withMessage
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/StandardSubjectBuilder.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/StandardSubjectBuilder.java
|
Apache-2.0
|
public final StandardSubjectBuilder withMessage(String format, @Nullable Object... args) {
return new StandardSubjectBuilder(metadata().withMessage(format, args));
}
|
Returns a new instance that will output the given message before the main failure message. If
this method is called multiple times, the messages will appear in the order that they were
specified.
<p><b>Note:</b> the arguments will be substituted into the format template using {@link
com.google.common.base.Strings#lenientFormat Strings.lenientFormat}. Note this only supports
the {@code %s} specifier.
@throws IllegalArgumentException if the number of placeholders in the format string does not
equal the number of given arguments
|
withMessage
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/StandardSubjectBuilder.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/StandardSubjectBuilder.java
|
Apache-2.0
|
public final <S extends Subject, A> SimpleSubjectBuilder<S, A> about(
Subject.Factory<S, A> factory) {
return new SimpleSubjectBuilder<>(metadata(), factory);
}
|
Given a factory for some {@code Subject} class, returns a builder whose {@code that(actual)}
method creates instances of that class. Created subjects use the previously set failure
strategy and any previously set failure message.
|
about
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/StandardSubjectBuilder.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/StandardSubjectBuilder.java
|
Apache-2.0
|
public final <CustomSubjectBuilderT extends CustomSubjectBuilder> CustomSubjectBuilderT about(
CustomSubjectBuilder.Factory<CustomSubjectBuilderT> factory) {
return factory.createSubjectBuilder(metadata());
}
|
Given a factory for some {@code Subject} class, returns a builder whose {@code that(actual)}
method creates instances of that class. Created subjects use the previously set failure
strategy and any previously set failure message.
|
about
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/StandardSubjectBuilder.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/StandardSubjectBuilder.java
|
Apache-2.0
|
private FailureMetadata metadata() {
checkStatePreconditions();
return metadataDoNotReferenceDirectly;
}
|
Reports a failure.
<p>To set a message, first call {@link #withMessage} (or, more commonly, use the shortcut
{@link Truth#assertWithMessage}).
|
metadata
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/StandardSubjectBuilder.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/StandardSubjectBuilder.java
|
Apache-2.0
|
@Deprecated
@SuppressWarnings("InlineMeSuggester") // We want users to remove the surrounding call entirely.
public static Factory<StreamSubject, Stream<?>> streams() {
return StreamSubject::new;
}
|
Obsolete factory instance. This factory was previously necessary for assertions like {@code
assertWithMessage(...).about(streams()).that(stream)....}. Now, you can perform assertions like
that without the {@code about(...)} call.
@deprecated Instead of {@code about(streams()).that(...)}, use just {@code that(...)}.
Similarly, instead of {@code assertAbout(streams()).that(...)}, use just {@code
assertThat(...)}.
|
streams
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/StreamSubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/StreamSubject.java
|
Apache-2.0
|
private static Factory<StreamSubject, Stream<?>> streams(
Supplier<@Nullable List<?>> listSupplier) {
return (metadata, actual) -> new StreamSubject(metadata, actual, listSupplier);
}
|
Factory instance for creating an instance for which we already have a {@code listSupplier} from
an existing instance. Naturally, the resulting factory should be used to create an instance
only for the stream corresponding to {@code listSupplier}.
|
streams
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/StreamSubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/StreamSubject.java
|
Apache-2.0
|
public void containsAnyOf(
@Nullable Object first, @Nullable Object second, @Nullable Object @Nullable ... rest) {
checkThatContentsList().containsAnyOf(first, second, rest);
}
|
Checks that the actual stream contains at least one of the given elements.
|
containsAnyOf
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/StreamSubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/StreamSubject.java
|
Apache-2.0
|
@CanIgnoreReturnValue
public Ordered containsAtLeast(
@Nullable Object first, @Nullable Object second, @Nullable Object @Nullable ... rest) {
return checkThatContentsList().containsAtLeast(first, second, rest);
}
|
Checks that the actual stream contains all of the given elements. If an element appears more
than once in the given elements, then it must appear at least that number of times in the
actual elements.
<p>To also test that the contents appear in the given order, make a call to {@code inOrder()}
on the object returned by this method. The expected elements must appear in the given order
within the actual elements, but they are not required to be consecutive.
|
containsAtLeast
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/StreamSubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/StreamSubject.java
|
Apache-2.0
|
@CanIgnoreReturnValue
public Ordered containsAtLeastElementsIn(@Nullable Iterable<?> expected) {
return checkThatContentsList().containsAtLeastElementsIn(expected);
}
|
Checks that the actual stream contains all of the given elements. If an element appears more
than once in the given elements, then it must appear at least that number of times in the
actual elements.
<p>To also test that the contents appear in the given order, make a call to {@code inOrder()}
on the object returned by this method. The expected elements must appear in the given order
within the actual elements, but they are not required to be consecutive.
|
containsAtLeastElementsIn
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/StreamSubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/StreamSubject.java
|
Apache-2.0
|
@CanIgnoreReturnValue
/*
* We need to call containsExactly, not containsExactlyElementsIn, to get the handling we want for
* containsExactly(null).
*/
@SuppressWarnings("ContainsExactlyVariadic")
public Ordered containsExactly(@Nullable Object @Nullable ... expected) {
return checkThatContentsList().containsExactly(expected);
}
|
Checks that the actual stream contains exactly the given elements.
<p>Multiplicity is respected. For example, an object duplicated exactly 3 times in the
parameters asserts that the object must likewise be duplicated exactly 3 times in the actual
stream.
<p>To also test that the contents appear in the given order, make a call to {@code inOrder()}
on the object returned by this method.
|
containsExactly
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/StreamSubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/StreamSubject.java
|
Apache-2.0
|
@CanIgnoreReturnValue
public Ordered containsExactlyElementsIn(@Nullable Iterable<?> expected) {
return checkThatContentsList().containsExactlyElementsIn(expected);
}
|
Checks that the actual stream contains exactly the given elements.
<p>Multiplicity is respected. For example, an object duplicated exactly 3 times in the
parameters asserts that the object must likewise be duplicated exactly 3 times in the actual
stream.
<p>To also test that the contents appear in the given order, make a call to {@code inOrder()}
on the object returned by this method.
|
containsExactlyElementsIn
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/StreamSubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/StreamSubject.java
|
Apache-2.0
|
public void containsNoneOf(
@Nullable Object first, @Nullable Object second, @Nullable Object @Nullable ... rest) {
checkThatContentsList().containsNoneOf(first, second, rest);
}
|
Checks that the actual stream does not contain any of the given elements.
|
containsNoneOf
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/StreamSubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/StreamSubject.java
|
Apache-2.0
|
@Override
@Deprecated
public void isEqualTo(@Nullable Object expected) {
/*
* We add a warning about stream equality. Doing so is a bit of a pain. (There might be a better
* way.)
*
* We do need to create a StreamSubject (rather than a plain Subject) in order to get our
* desired string representation (unless we edit Subject itself to create and expose a
* Supplier<List> when given a Stream...). And we have to use a special Factory to avoid
* re-collecting the stream.
*/
substituteCheck()
.withMessage(
"Warning: Stream equality is based on object identity. To compare Stream"
+ " contents, use methods like containsExactly.")
.about(streams(listSupplier))
.that(actual)
.superIsEqualTo(expected);
}
|
@deprecated {@code streamA.isEqualTo(streamB)} always fails, except when passed the exact same
stream reference. If you really want to test object identity, you can eliminate this
deprecation warning by using {@link #isSameInstanceAs}. If you instead want to test the
contents of the stream, use {@link #containsExactly} or similar methods.
|
isEqualTo
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/StreamSubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/StreamSubject.java
|
Apache-2.0
|
@Override
@Deprecated
public void isNotEqualTo(@Nullable Object unexpected) {
if (actual() == unexpected) {
/*
* We override the supermethod's message: That method would ask for both
* `String.valueOf(stream)` (for `unexpected`) and `actualCustomStringRepresentation()` (for
* `actual()`). The two strings are almost certain to differ, since `valueOf` is normally
* based on identity and `actualCustomStringRepresentation()` is based on contents. That can
* lead to a confusing error message.
*
* We could include isEqualTo's warning about Stream's identity-based equality here, too. But
* it doesn't seem necessary: The people we really want to warn are the people whose
* assertions *pass*. And we've already attempted to do that with deprecation.
*/
failWithoutActual(
fact("expected not to be", actualCustomStringRepresentationForPackageMembersToCall()));
return;
}
/*
* But, if the objects aren't identical, we delegate to the supermethod (which checks equals())
* just in case someone has decided to override Stream.equals in a strange way. (I haven't
* checked whether this comes up in Google's codebase. I hope that it doesn't.)
*/
super.isNotEqualTo(unexpected);
}
|
@deprecated {@code streamA.isNotEqualTo(streamB)} always passes, except when passed the exact
same stream reference. If you really want to test object identity, you can eliminate this
deprecation warning by using {@link #isNotSameInstanceAs}. If you instead want to test the
contents of the stream, collect both streams to lists and perform assertions like {@link
IterableSubject#isNotEqualTo} on them. In some cases, you may be able to use {@link
StreamSubject} assertions like {@link #doesNotContain}.
|
isNotEqualTo
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/StreamSubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/StreamSubject.java
|
Apache-2.0
|
private IterableSubject checkThatContentsList() {
return substituteCheck().that(listSupplier.get());
}
|
Be careful with using this, as documented on {@link Subject#substituteCheck}.
|
checkThatContentsList
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/StreamSubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/StreamSubject.java
|
Apache-2.0
|
private static Supplier<@Nullable List<?>> listCollector(@Nullable Stream<?> actual) {
return () -> actual == null ? null : actual.collect(toCollection(ArrayList::new));
}
|
Be careful with using this, as documented on {@link Subject#substituteCheck}.
|
listCollector
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/StreamSubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/StreamSubject.java
|
Apache-2.0
|
@Override
@Deprecated
public final void isEquivalentAccordingToCompareTo(@Nullable String other) {
super.isEquivalentAccordingToCompareTo(other);
}
|
@deprecated Use {@link #isEqualTo} instead. String comparison is consistent with equality.
|
isEquivalentAccordingToCompareTo
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/StringSubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/StringSubject.java
|
Apache-2.0
|
public void hasLength(int expectedLength) {
checkArgument(expectedLength >= 0, "expectedLength(%s) must be >= 0", expectedLength);
if (actual == null) {
failWithActual(fact("expected a string with length", expectedLength));
return;
}
check("length()").that(actual.length()).isEqualTo(expectedLength);
}
|
Checks that the actual value has the given length.
|
hasLength
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/StringSubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/StringSubject.java
|
Apache-2.0
|
public void isEmpty() {
if (actual == null) {
failWithActual(simpleFact("expected an empty string"));
} else if (!actual.isEmpty()) {
failWithActual(simpleFact("expected to be empty"));
}
}
|
Checks that the actual value is the empty string.
|
isEmpty
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/StringSubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/StringSubject.java
|
Apache-2.0
|
public void isNotEmpty() {
if (actual == null) {
failWithActual(simpleFact("expected a non-empty string"));
} else if (actual.isEmpty()) {
failWithoutActual(simpleFact("expected not to be empty"));
}
}
|
Checks that the actual value is not the empty string.
|
isNotEmpty
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/StringSubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/StringSubject.java
|
Apache-2.0
|
public void contains(@Nullable CharSequence string) {
checkNotNull(string);
if (actual == null) {
failWithActual("expected a string that contains", string);
} else if (!actual.contains(string)) {
failWithActual("expected to contain", string);
}
}
|
Checks that the actual value contains the given sequence.
|
contains
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/StringSubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/StringSubject.java
|
Apache-2.0
|
public void doesNotContain(@Nullable CharSequence string) {
checkNotNull(string);
if (actual == null) {
failWithActual("expected a string that does not contain", string);
} else if (actual.contains(string)) {
failWithActual("expected not to contain", string);
}
}
|
Checks that the actual value does not contain the given sequence.
|
doesNotContain
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/StringSubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/StringSubject.java
|
Apache-2.0
|
public void startsWith(@Nullable String string) {
checkNotNull(string);
if (actual == null) {
failWithActual("expected a string that starts with", string);
} else if (!actual.startsWith(string)) {
failWithActual("expected to start with", string);
}
}
|
Checks that the actual value starts with the given string.
|
startsWith
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/StringSubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/StringSubject.java
|
Apache-2.0
|
public void endsWith(@Nullable String string) {
checkNotNull(string);
if (actual == null) {
failWithActual("expected a string that ends with", string);
} else if (!actual.endsWith(string)) {
failWithActual("expected to end with", string);
}
}
|
Checks that the actual value ends with the given string.
|
endsWith
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/StringSubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/StringSubject.java
|
Apache-2.0
|
public void matches(@Nullable String regex) {
checkNotNull(regex);
if (actual == null) {
failWithActual("expected a string that matches", regex);
} else if (!actual.matches(regex)) {
if (regex.equals(actual)) {
failWithoutActual(
fact("expected to match", regex),
fact("but was", actual),
simpleFact("Looks like you want to use .isEqualTo() for an exact equality assertion."));
} else if (Platform.containsMatch(actual, regex)) {
failWithoutActual(
fact("expected to match", regex),
fact("but was", actual),
simpleFact("Did you mean to call containsMatch() instead of match()?"));
} else {
failWithActual("expected to match", regex);
}
}
}
|
Checks that the actual value matches the given regex.
|
matches
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/StringSubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/StringSubject.java
|
Apache-2.0
|
@GwtIncompatible("java.util.regex.Pattern")
public void matches(@Nullable Pattern regex) {
checkNotNull(regex);
if (actual == null) {
failWithActual("expected a string that matches", regex);
} else if (!regex.matcher(actual).matches()) {
if (regex.toString().equals(actual)) {
failWithoutActual(
fact("expected to match", regex),
fact("but was", actual),
simpleFact(
"If you want an exact equality assertion you can escape your regex with"
+ " Pattern.quote()."));
} else if (regex.matcher(actual).find()) {
failWithoutActual(
fact("expected to match", regex),
fact("but was", actual),
simpleFact("Did you mean to call containsMatch() instead of match()?"));
} else {
failWithActual("expected to match", regex);
}
}
}
|
Checks that the actual value matches the given regex.
|
matches
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/StringSubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/StringSubject.java
|
Apache-2.0
|
public void doesNotMatch(@Nullable String regex) {
checkNotNull(regex);
if (actual == null) {
failWithActual("expected a string that does not match", regex);
} else if (actual.matches(regex)) {
failWithActual("expected not to match", regex);
}
}
|
Checks that the actual value does not match the given regex.
|
doesNotMatch
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/StringSubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/StringSubject.java
|
Apache-2.0
|
@GwtIncompatible("java.util.regex.Pattern")
public void doesNotMatch(@Nullable Pattern regex) {
checkNotNull(regex);
if (actual == null) {
failWithActual("expected a string that does not match", regex);
} else if (regex.matcher(actual).matches()) {
failWithActual("expected not to match", regex);
}
}
|
Checks that the actual value does not match the given regex.
|
doesNotMatch
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/StringSubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/StringSubject.java
|
Apache-2.0
|
@GwtIncompatible("java.util.regex.Pattern")
public void containsMatch(@Nullable Pattern regex) {
checkNotNull(regex);
if (actual == null) {
failWithActual("expected a string that contains a match for", regex);
} else if (!regex.matcher(actual).find()) {
failWithActual("expected to contain a match for", regex);
}
}
|
Checks that the actual value contains a match on the given regex.
|
containsMatch
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/StringSubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/StringSubject.java
|
Apache-2.0
|
public void containsMatch(@Nullable String regex) {
checkNotNull(regex);
if (actual == null) {
failWithActual("expected a string that contains a match for", regex);
} else if (!Platform.containsMatch(actual, regex)) {
failWithActual("expected to contain a match for", regex);
}
}
|
Checks that the actual value contains a match on the given regex.
|
containsMatch
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/StringSubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/StringSubject.java
|
Apache-2.0
|
@GwtIncompatible("java.util.regex.Pattern")
public void doesNotContainMatch(@Nullable Pattern regex) {
checkNotNull(regex);
if (actual == null) {
failWithActual("expected a string that does not contain a match for", regex);
return;
}
Matcher matcher = regex.matcher(actual);
if (matcher.find()) {
failWithoutActual(
fact("expected not to contain a match for", regex),
fact("but contained", matcher.group()),
fact("full string", actualCustomStringRepresentationForPackageMembersToCall()));
}
}
|
Checks that the actual value does not contain a match on the given regex.
|
doesNotContainMatch
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/StringSubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/StringSubject.java
|
Apache-2.0
|
public void doesNotContainMatch(@Nullable String regex) {
checkNotNull(regex);
if (actual == null) {
failWithActual("expected a string that does not contain a match for", regex);
} else if (Platform.containsMatch(actual, regex)) {
failWithActual("expected not to contain a match for", regex);
}
}
|
Checks that the actual value does not contain a match on the given regex.
|
doesNotContainMatch
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/StringSubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/StringSubject.java
|
Apache-2.0
|
public CaseInsensitiveStringComparison ignoringCase() {
return CaseInsensitiveStringComparison.create(this);
}
|
Returns a {@link StringSubject}-like instance that will ignore the case of the characters.
<p>Character equality ignoring case is defined as follows: Characters must be equal either
after calling {@link Character#toLowerCase} or after calling {@link Character#toUpperCase}.
Note that this is independent of any locale.
|
ignoringCase
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/StringSubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/StringSubject.java
|
Apache-2.0
|
public void isEqualTo(@Nullable String expected) {
if (actual == null) {
if (expected != null) {
failWithoutActual(
fact("expected a string that is equal to", expected),
butWas(),
simpleFact("(case is ignored)"));
}
} else {
if (expected == null) {
failWithoutActual(
fact("expected", "null (null reference)"), butWas(), simpleFact("(case is ignored)"));
} else if (!actual.equalsIgnoreCase(expected)) {
failWithoutActual(fact("expected", expected), butWas(), simpleFact("(case is ignored)"));
}
}
}
|
Checks that the actual value is equal to the given sequence (while ignoring case). For the
purposes of this comparison, two strings are equal if either of the following is true:
<ul>
<li>They are equal according to {@link String#equalsIgnoreCase}. (In Kotlin terms: They are
equal according to <a
href="https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.text/equals.html">{@code
actual.equals(expected, ignoreCase = true)}</a>.)
<li>They are both null.
</ul>
<p>Example: "abc" is equal to "ABC", but not to "abcd".
|
isEqualTo
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/StringSubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/StringSubject.java
|
Apache-2.0
|
public void isNotEqualTo(@Nullable String unexpected) {
if (actual == null) {
if (unexpected == null) {
failWithoutActual(
fact("expected a string that is not equal to", "null (null reference)"),
simpleFact("(case is ignored)"));
}
} else {
if (actual.equalsIgnoreCase(unexpected)) {
failWithoutActual(
fact("expected not to be", unexpected), butWas(), simpleFact("(case is ignored)"));
}
}
}
|
Checks that the actual value is not equal to the given string (while ignoring case). The
meaning of equality is the same as for the {@link #isEqualTo} method.
|
isNotEqualTo
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/StringSubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/StringSubject.java
|
Apache-2.0
|
public void contains(@Nullable CharSequence expectedSequence) {
checkNotNull(expectedSequence);
String expected = expectedSequence.toString();
if (actual == null) {
failWithoutActual(
fact("expected a string that contains", expected),
butWas(),
simpleFact("(case is ignored)"));
} else if (!containsIgnoreCase(actual, expected)) {
failWithoutActual(
fact("expected to contain", expected), butWas(), simpleFact("(case is ignored)"));
}
}
|
Checks that the actual value contains the given sequence (while ignoring case).
|
contains
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/StringSubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/StringSubject.java
|
Apache-2.0
|
public void doesNotContain(@Nullable CharSequence expectedSequence) {
checkNotNull(expectedSequence);
String expected = expectedSequence.toString();
if (actual == null) {
failWithoutActual(
fact("expected a string that does not contain", expected),
butWas(),
simpleFact("(case is ignored)"));
} else if (containsIgnoreCase(actual, expected)) {
failWithoutActual(
fact("expected not to contain", expected), butWas(), simpleFact("(case is ignored)"));
}
}
|
Checks that the actual value does not contain the given sequence (while ignoring case).
|
doesNotContain
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/StringSubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/StringSubject.java
|
Apache-2.0
|
private static boolean containsIgnoreCase(String actual, String string) {
for (int actualOffset = 0;
actualOffset <= actual.length() - string.length();
actualOffset++) {
if (actual.regionMatches(
/* ignoreCase= */ true,
/* toffset= */ actualOffset,
/* other= */ string,
/* ooffset= */ 0,
/* len= */ string.length())) {
return true;
}
}
return false;
}
|
Checks that the actual value does not contain the given sequence (while ignoring case).
|
containsIgnoreCase
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/StringSubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/StringSubject.java
|
Apache-2.0
|
private Fact butWas() {
return subject.butWas();
}
|
Checks that the actual value does not contain the given sequence (while ignoring case).
|
butWas
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/StringSubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/StringSubject.java
|
Apache-2.0
|
private void failWithoutActual(Fact first, Fact... rest) {
subject.failWithoutActual(first, rest);
}
|
Checks that the actual value does not contain the given sequence (while ignoring case).
|
failWithoutActual
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/StringSubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/StringSubject.java
|
Apache-2.0
|
static CaseInsensitiveStringComparison create(StringSubject stringSubject) {
return new CaseInsensitiveStringComparison(stringSubject);
}
|
Checks that the actual value does not contain the given sequence (while ignoring case).
|
create
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/StringSubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/StringSubject.java
|
Apache-2.0
|
static Factory<StringSubject, String> strings() {
return StringSubject::new;
}
|
Checks that the actual value does not contain the given sequence (while ignoring case).
|
strings
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/StringSubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/StringSubject.java
|
Apache-2.0
|
private void standardIsEqualTo(@Nullable Object expected) {
ComparisonResult difference = compareForEquality(expected);
if (!difference.valuesAreEqual()) {
failEqualityCheck(EqualityCheck.EQUAL, expected, difference);
}
}
|
Checks that the value under test is equal to the given object. For the purposes of this
comparison, two objects are equal if any of the following is true:
<ul>
<li>they are equal according to {@link Objects#equals}
<li>they are arrays and are considered equal by the appropriate {@link Arrays#equals}
overload
<li>they are boxed integer types ({@code Byte}, {@code Short}, {@code Character}, {@code
Integer}, or {@code Long}) and they are numerically equal when converted to {@code Long}.
<li>the actual value is a boxed floating-point type ({@code Double} or {@code Float}), the
expected value is an {@code Integer}, and the two are numerically equal when converted to
{@code Double}. (This allows {@code assertThat(someDouble).isEqualTo(0)} to pass.)
</ul>
<p><b>Note:</b> This method does not test the {@link Object#equals} implementation itself; it
<i>assumes</i> that method is functioning correctly according to its contract. Testing an
{@code equals} implementation requires a utility such as <a
href="https://mvnrepository.com/artifact/com.google.guava/guava-testlib">guava-testlib</a>'s <a
href="https://static.javadoc.io/com.google.guava/guava-testlib/23.0/com/google/common/testing/EqualsTester.html">EqualsTester</a>.
<p>In some cases, this method might not even call {@code equals}. It may instead perform other
tests that will return the same result as long as {@code equals} is implemented according to
the contract for its type.
|
standardIsEqualTo
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Subject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Subject.java
|
Apache-2.0
|
private void standardIsNotEqualTo(@Nullable Object unexpected) {
ComparisonResult difference = compareForEquality(unexpected);
if (difference.valuesAreEqual()) {
String unexpectedAsString = formatActualOrExpected(unexpected);
if (actualCustomStringRepresentation().equals(unexpectedAsString)) {
failWithoutActual(fact("expected not to be", unexpectedAsString));
} else {
failWithoutActual(
fact("expected not to be", unexpectedAsString),
fact(
"but was; string representation of actual value",
actualCustomStringRepresentation()));
}
}
}
|
Checks that the value under test is not equal to the given object. The meaning of equality is
the same as for the {@link #isEqualTo} method.
|
standardIsNotEqualTo
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Subject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Subject.java
|
Apache-2.0
|
private ComparisonResult compareForEquality(@Nullable Object expected) {
if (actual == null && expected == null) {
return ComparisonResult.equal();
} else if (actual == null || expected == null) {
return ComparisonResult.differentNoDescription();
} else if (actual instanceof byte[] && expected instanceof byte[]) {
/*
* For a special error message and to use faster Arrays.equals to avoid at least one timeout.
*
* TODO(cpovirk): For performance, use Arrays.equals for other array types (here and/or in
* checkArrayEqualsRecursive)? Exception: double[] and float[], whose GWT implementations I
* think may have both false positives and false negatives (so we can't even use Arrays.equals
* as a fast path for them, nor deepEquals for an Object[] that might contain them). We would
* still fall back to the slower checkArrayEqualsRecursive to produce a nicer failure message
* -- but naturally only for tests that are about to fail, when performance matters less.
*/
return checkByteArrayEquals((byte[]) expected, (byte[]) actual);
} else if (actual.getClass().isArray() && expected.getClass().isArray()) {
return checkArrayEqualsRecursive(expected, actual, "");
} else if (isIntegralBoxedPrimitive(actual) && isIntegralBoxedPrimitive(expected)) {
return ComparisonResult.fromEqualsResult(integralValue(actual) == integralValue(expected));
} else if (actual instanceof Double && expected instanceof Double) {
return ComparisonResult.fromEqualsResult(
Double.compare((Double) actual, (Double) expected) == 0);
} else if (actual instanceof Float && expected instanceof Float) {
return ComparisonResult.fromEqualsResult(
Float.compare((Float) actual, (Float) expected) == 0);
} else if (actual instanceof Double && expected instanceof Integer) {
return ComparisonResult.fromEqualsResult(
Double.compare((Double) actual, (Integer) expected) == 0);
} else if (actual instanceof Float && expected instanceof Integer) {
return ComparisonResult.fromEqualsResult(
Double.compare((Float) actual, (Integer) expected) == 0);
} else {
return ComparisonResult.fromEqualsResult(actual == expected || actual.equals(expected));
}
}
|
Returns whether {@code actual} equals {@code expected} differ and, in some cases, a description
of how they differ.
<p>The equality check follows the rules described on {@link #isEqualTo}.
|
compareForEquality
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Subject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Subject.java
|
Apache-2.0
|
private static boolean isIntegralBoxedPrimitive(@Nullable Object o) {
return o instanceof Byte
|| o instanceof Short
|| o instanceof Character
|| o instanceof Integer
|| o instanceof Long;
}
|
Returns whether {@code actual} equals {@code expected} differ and, in some cases, a description
of how they differ.
<p>The equality check follows the rules described on {@link #isEqualTo}.
|
isIntegralBoxedPrimitive
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Subject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Subject.java
|
Apache-2.0
|
private static long integralValue(Object o) {
if (o instanceof Character) {
return (long) ((Character) o).charValue();
} else if (o instanceof Number) {
return ((Number) o).longValue();
} else {
throw new AssertionError(o + " must be either a Character or a Number.");
}
}
|
Returns whether {@code actual} equals {@code expected} differ and, in some cases, a description
of how they differ.
<p>The equality check follows the rules described on {@link #isEqualTo}.
|
integralValue
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Subject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Subject.java
|
Apache-2.0
|
public final void isSameInstanceAs(@Nullable Object expected) {
if (actual != expected) {
failEqualityCheck(
SAME_INSTANCE,
expected,
/*
* Pass through *whether* the values are equal so that failEqualityCheck() can print that
* information. But remove the description of the difference, which is always about
* content, since people calling isSameInstanceAs() are explicitly not interested in
* content, only object identity.
*/
compareForEquality(expected).withoutDescription());
}
}
|
Checks that the value under test is the same instance as the given object.
<p>This method considers {@code null} to be "the same instance as" {@code null} and not the
same instance as anything else.
|
isSameInstanceAs
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Subject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Subject.java
|
Apache-2.0
|
public final void isNotSameInstanceAs(@Nullable Object unexpected) {
if (actual == unexpected) {
/*
* We use actualCustomStringRepresentation() because it might be overridden to be better than
* actual.toString()/unexpected.toString().
*/
failWithoutActual(
fact("expected not to be specific instance", actualCustomStringRepresentation()));
}
}
|
Checks that the value under test is not the same instance as the given object.
<p>This method considers {@code null} to be "the same instance as" {@code null} and not the
same instance as anything else.
|
isNotSameInstanceAs
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Subject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Subject.java
|
Apache-2.0
|
public void isInstanceOf(Class<?> clazz) {
if (clazz == null) {
throw new NullPointerException("clazz");
}
if (actual == null) {
failWithActual("expected instance of", clazz.getName());
return;
}
if (!isInstanceOfType(actual, clazz)) {
if (Platform.classMetadataUnsupported()) {
throw new UnsupportedOperationException(
actualCustomStringRepresentation()
+ ", an instance of "
+ actual.getClass().getName()
+ ", may or may not be an instance of "
+ clazz.getName()
+ ". Under -XdisableClassMetadata, we do not have enough information to tell.");
}
failWithoutActual(
fact("expected instance of", clazz.getName()),
fact("but was instance of", actual.getClass().getName()),
fact("with value", actualCustomStringRepresentation()));
}
}
|
Checks that the value under test is an instance of the given class.
|
isInstanceOf
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Subject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Subject.java
|
Apache-2.0
|
public void isNotInstanceOf(Class<?> clazz) {
if (clazz == null) {
throw new NullPointerException("clazz");
}
if (Platform.classMetadataUnsupported()) {
throw new UnsupportedOperationException(
"isNotInstanceOf is not supported under -XdisableClassMetadata");
}
if (actual == null) {
return; // null is not an instance of clazz.
}
if (isInstanceOfType(actual, clazz)) {
failWithActual("expected not to be an instance of", clazz.getName());
/*
* TODO(cpovirk): Consider including actual.getClass() if it's not clazz itself but only a
* subtype.
*/
}
}
|
Checks that the value under test is not an instance of the given class.
|
isNotInstanceOf
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Subject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Subject.java
|
Apache-2.0
|
private static boolean isInstanceOfType(Object instance, Class<?> clazz) {
checkArgument(
!clazz.isPrimitive(),
"Cannot check instanceof for primitive type %s. Pass the wrapper class %s instead.",
clazz.getSimpleName(),
Primitives.wrap(clazz).getSimpleName());
return Platform.isInstanceOfType(instance, clazz);
}
|
Checks that the value under test is not an instance of the given class.
|
isInstanceOfType
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Subject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Subject.java
|
Apache-2.0
|
public void isIn(@Nullable Iterable<?> iterable) {
checkNotNull(iterable);
if (!contains(iterable, actual)) {
failWithActual("expected any of", iterable);
}
}
|
Checks that the value under test is equal to any element in the given iterable.
|
isIn
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Subject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Subject.java
|
Apache-2.0
|
private static boolean contains(Iterable<?> haystack, @Nullable Object needle) {
if (isKotlinRange(haystack)) {
return kotlinRangeContains(haystack, needle);
}
return Iterables.contains(haystack, needle);
}
|
Checks that the value under test is equal to any element in the given iterable.
|
contains
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Subject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Subject.java
|
Apache-2.0
|
public void isAnyOf(
@Nullable Object first, @Nullable Object second, @Nullable Object @Nullable ... rest) {
isIn(accumulate(first, second, rest));
}
|
Checks that the value under test is equal to any of the given elements.
|
isAnyOf
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Subject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Subject.java
|
Apache-2.0
|
public void isNotIn(@Nullable Iterable<?> iterable) {
checkNotNull(iterable);
if (Iterables.contains(iterable, actual)) {
failWithActual("expected not to be any of", iterable);
}
}
|
Checks that the value under test is not equal to any element in the given iterable.
|
isNotIn
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Subject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Subject.java
|
Apache-2.0
|
public void isNoneOf(
@Nullable Object first, @Nullable Object second, @Nullable Object @Nullable ... rest) {
isNotIn(accumulate(first, second, rest));
}
|
Checks that the value under test is not equal to any of the given elements.
|
isNoneOf
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Subject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Subject.java
|
Apache-2.0
|
final @Nullable Object actual() {
return actual;
}
|
Returns the actual value under test.
|
actual
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Subject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Subject.java
|
Apache-2.0
|
@ForOverride
protected String actualCustomStringRepresentation() {
return formatActualOrExpected(actual);
}
|
Supplies the direct string representation of the actual value to other methods which may prefix
or otherwise position it in an error message. This should only be overridden to provide an
improved string representation of the value under test, as it would appear in any given error
message, and should not be used for additional prefixing.
<p>Subjects should override this with care.
<p>By default, this returns {@code String.ValueOf(getActualValue())}.
|
actualCustomStringRepresentation
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Subject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Subject.java
|
Apache-2.0
|
final String actualCustomStringRepresentationForPackageMembersToCall() {
return actualCustomStringRepresentation();
}
|
Supplies the direct string representation of the actual value to other methods which may prefix
or otherwise position it in an error message. This should only be overridden to provide an
improved string representation of the value under test, as it would appear in any given error
message, and should not be used for additional prefixing.
<p>Subjects should override this with care.
<p>By default, this returns {@code String.ValueOf(getActualValue())}.
|
actualCustomStringRepresentationForPackageMembersToCall
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Subject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Subject.java
|
Apache-2.0
|
private static String formatActualOrExpected(@Nullable Object o) {
if (o instanceof byte[]) {
return base16((byte[]) o);
} else if (o != null && o.getClass().isArray()) {
return String.valueOf(arrayAsListRecursively(o));
} else if (o instanceof Double) {
return doubleToString((Double) o);
} else if (o instanceof Float) {
return floatToString((Float) o);
} else {
// TODO(cpovirk): Consider renaming the called method to mention "NonArray."
/*
* TODO(cpovirk): Should the called method and arrayAsListRecursively(...) both call back into
* formatActualOrExpected for its handling of byte[] and float/double? Or is there some other
* restructuring of this set of methods that we should undertake?
*/
return stringValueOfNonFloatingPoint(o);
}
}
|
Supplies the direct string representation of the actual value to other methods which may prefix
or otherwise position it in an error message. This should only be overridden to provide an
improved string representation of the value under test, as it would appear in any given error
message, and should not be used for additional prefixing.
<p>Subjects should override this with care.
<p>By default, this returns {@code String.ValueOf(getActualValue())}.
|
formatActualOrExpected
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Subject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Subject.java
|
Apache-2.0
|
private static String base16(byte[] bytes) {
StringBuilder sb = new StringBuilder(2 * bytes.length);
for (byte b : bytes) {
sb.append(hexDigitsUpper[(b >> 4) & 0xf]).append(hexDigitsUpper[b & 0xf]);
}
return sb.toString();
}
|
Supplies the direct string representation of the actual value to other methods which may prefix
or otherwise position it in an error message. This should only be overridden to provide an
improved string representation of the value under test, as it would appear in any given error
message, and should not be used for additional prefixing.
<p>Subjects should override this with care.
<p>By default, this returns {@code String.ValueOf(getActualValue())}.
|
base16
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Subject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Subject.java
|
Apache-2.0
|
private static @Nullable Object arrayAsListRecursively(@Nullable Object input) {
if (input instanceof Object[]) {
return Lists.<@Nullable Object, @Nullable Object>transform(
asList((@Nullable Object[]) input), Subject::arrayAsListRecursively);
} else if (input instanceof boolean[]) {
return Booleans.asList((boolean[]) input);
} else if (input instanceof int[]) {
return Ints.asList((int[]) input);
} else if (input instanceof long[]) {
return Longs.asList((long[]) input);
} else if (input instanceof short[]) {
return Shorts.asList((short[]) input);
} else if (input instanceof byte[]) {
return Bytes.asList((byte[]) input);
} else if (input instanceof double[]) {
return doubleArrayAsString((double[]) input);
} else if (input instanceof float[]) {
return floatArrayAsString((float[]) input);
} else if (input instanceof char[]) {
return Chars.asList((char[]) input);
} else {
return input;
}
}
|
Supplies the direct string representation of the actual value to other methods which may prefix
or otherwise position it in an error message. This should only be overridden to provide an
improved string representation of the value under test, as it would appear in any given error
message, and should not be used for additional prefixing.
<p>Subjects should override this with care.
<p>By default, this returns {@code String.ValueOf(getActualValue())}.
|
arrayAsListRecursively
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Subject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Subject.java
|
Apache-2.0
|
static ComparisonResult fromEqualsResult(boolean equal) {
return equal ? EQUAL : DIFFERENT_NO_DESCRIPTION;
}
|
If {@code equal} is true, returns an equal result; if false, a non-equal result with no
description.
|
fromEqualsResult
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Subject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Subject.java
|
Apache-2.0
|
static ComparisonResult differentWithDescription(Fact... facts) {
return new ComparisonResult(ImmutableList.copyOf(facts));
}
|
Returns a non-equal result with the given description.
|
differentWithDescription
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Subject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Subject.java
|
Apache-2.0
|
static ComparisonResult differentNoDescription() {
return DIFFERENT_NO_DESCRIPTION;
}
|
Returns a non-equal result with no description.
|
differentNoDescription
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Subject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Subject.java
|
Apache-2.0
|
boolean valuesAreEqual() {
return facts == null;
}
|
Returns a non-equal result with no description.
|
valuesAreEqual
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Subject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Subject.java
|
Apache-2.0
|
ImmutableList<Fact> factsOrEmpty() {
return firstNonNull(facts, ImmutableList.of());
}
|
Returns a non-equal result with no description.
|
factsOrEmpty
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Subject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Subject.java
|
Apache-2.0
|
ComparisonResult withoutDescription() {
return fromEqualsResult(valuesAreEqual());
}
|
Returns an instance with the same "equal"/"not-equal" bit but with no description.
|
withoutDescription
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Subject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Subject.java
|
Apache-2.0
|
private static ComparisonResult checkByteArrayEquals(byte[] expected, byte[] actual) {
if (Arrays.equals(expected, actual)) {
return ComparisonResult.equal();
}
return ComparisonResult.differentWithDescription(
fact("expected", Arrays.toString(expected)), fact("but was", Arrays.toString(actual)));
}
|
Returns {@link ComparisonResult#equal} if the arrays are equal. If not equal, returns a string
comparing the two arrays, displaying them in the style "[1, 2, 3]" to supplement the main
failure message, which uses the style "010203."
|
checkByteArrayEquals
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Subject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Subject.java
|
Apache-2.0
|
private static ComparisonResult checkArrayEqualsRecursive(
Object expectedArray, Object actualArray, String lastIndex) {
if (expectedArray == actualArray) {
return ComparisonResult.equal();
}
String expectedType = arrayType(expectedArray);
String actualType = arrayType(actualArray);
if (!expectedType.equals(actualType)) {
Fact indexFact =
lastIndex.isEmpty() ? simpleFact("wrong type") : fact("wrong type for index", lastIndex);
return ComparisonResult.differentWithDescription(
indexFact, fact("expected", expectedType), fact("but was", actualType));
}
int actualLength = getLength(actualArray);
int expectedLength = getLength(expectedArray);
if (expectedLength != actualLength) {
Fact indexFact =
lastIndex.isEmpty()
? simpleFact("wrong length")
: fact("wrong length for index", lastIndex);
return ComparisonResult.differentWithDescription(
indexFact, fact("expected", expectedLength), fact("but was", actualLength));
}
for (int i = 0; i < actualLength; i++) {
String index = lastIndex + "[" + i + "]";
Object expected = Array.get(expectedArray, i);
Object actual = Array.get(actualArray, i);
if (actual != null
&& actual.getClass().isArray()
&& expected != null
&& expected.getClass().isArray()) {
ComparisonResult result = checkArrayEqualsRecursive(expected, actual, index);
if (!result.valuesAreEqual()) {
return result;
}
} else if (!gwtSafeObjectEquals(actual, expected)) {
return ComparisonResult.differentWithDescription(fact("differs at index", index));
}
}
return ComparisonResult.equal();
}
|
Returns {@link ComparisonResult#equal} if the arrays are equal, recursively. If not equal,
returns the string of the index at which they're different.
|
checkArrayEqualsRecursive
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Subject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Subject.java
|
Apache-2.0
|
private static String arrayType(Object array) {
if (array.getClass() == boolean[].class) {
return "boolean[]";
} else if (array.getClass() == int[].class) {
return "int[]";
} else if (array.getClass() == long[].class) {
return "long[]";
} else if (array.getClass() == short[].class) {
return "short[]";
} else if (array.getClass() == byte[].class) {
return "byte[]";
} else if (array.getClass() == double[].class) {
return "double[]";
} else if (array.getClass() == float[].class) {
return "float[]";
} else if (array.getClass() == char[].class) {
return "char[]";
} else {
return "Object[]";
}
}
|
Returns {@link ComparisonResult#equal} if the arrays are equal, recursively. If not equal,
returns the string of the index at which they're different.
|
arrayType
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Subject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Subject.java
|
Apache-2.0
|
private static boolean gwtSafeObjectEquals(@Nullable Object actual, @Nullable Object expected) {
if (actual instanceof Double && expected instanceof Double) {
return Double.doubleToLongBits((Double) actual) == Double.doubleToLongBits((Double) expected);
} else if (actual instanceof Float && expected instanceof Float) {
return Float.floatToIntBits((Float) actual) == Float.floatToIntBits((Float) expected);
} else {
return Objects.equals(actual, expected);
}
}
|
Returns {@link ComparisonResult#equal} if the arrays are equal, recursively. If not equal,
returns the string of the index at which they're different.
|
gwtSafeObjectEquals
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Subject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Subject.java
|
Apache-2.0
|
private static List<String> doubleArrayAsString(double[] items) {
List<String> itemAsStrings = new ArrayList<>(items.length);
for (double item : items) {
itemAsStrings.add(doubleToString(item));
}
return itemAsStrings;
}
|
Returns {@link ComparisonResult#equal} if the arrays are equal, recursively. If not equal,
returns the string of the index at which they're different.
|
doubleArrayAsString
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Subject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Subject.java
|
Apache-2.0
|
private static List<String> floatArrayAsString(float[] items) {
List<String> itemAsStrings = new ArrayList<>(items.length);
for (float item : items) {
itemAsStrings.add(floatToString(item));
}
return itemAsStrings;
}
|
Returns {@link ComparisonResult#equal} if the arrays are equal, recursively. If not equal,
returns the string of the index at which they're different.
|
floatArrayAsString
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Subject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Subject.java
|
Apache-2.0
|
@Deprecated
final StandardSubjectBuilder check() {
return new StandardSubjectBuilder(metadata.updateForCheckCall());
}
|
Returns a builder for creating a derived subject but without providing information about how
the derived subject will relate to the current subject. In most cases, you should provide such
information by using {@linkplain #check(String, Object...) the other overload}.
@deprecated Use {@linkplain #check(String, Object...) the other overload}, which requires you
to supply more information to include in any failure messages.
|
check
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Subject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Subject.java
|
Apache-2.0
|
protected final StandardSubjectBuilder check(String format, @Nullable Object... args) {
return doCheck(OldAndNewValuesAreSimilar.DIFFERENT, format, args);
}
|
Returns a builder for creating a derived subject.
<p>Derived subjects retain the {@link FailureStrategy} and {@linkplain
StandardSubjectBuilder#withMessage messages} of the current subject, and in some cases, they
automatically supplement their failure message with information about the original subject.
<p>For example, {@link ThrowableSubject#hasMessageThat}, which returns a {@link StringSubject},
is implemented with {@code check("getMessage()").that(actual.getMessage())}.
<p>The arguments to {@code check} describe how the new subject was derived from the old,
formatted like a chained method call. This allows Truth to include that information in its
failure messages. For example, {@code assertThat(caught).hasCauseThat().hasMessageThat()} will
produce a failure message that includes the string "throwable.getCause().getMessage()," thanks
to internal {@code check} calls that supplied "getCause()" and "getMessage()" as arguments.
<p>If the method you're delegating to accepts parameters, you can pass {@code check} a format
string. For example, {@link MultimapSubject#valuesForKey} calls {@code
check("valuesForKey(%s)", key)}.
<p>If you aren't really delegating to an instance method on the actual value -- maybe you're
calling a static method, or you're calling a chain of several methods -- you can supply
whatever string will be most useful to users. For example, if you're delegating to {@code
getOnlyElement(actual.colors())}, you might call {@code check("onlyColor()")}.
@param format a template with {@code %s} placeholders
@param args the arguments to be inserted into those placeholders
|
check
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Subject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Subject.java
|
Apache-2.0
|
final StandardSubjectBuilder checkNoNeedToDisplayBothValues(
String format, @Nullable Object... args) {
return doCheck(OldAndNewValuesAreSimilar.SIMILAR, format, args);
}
|
Returns a builder for creating a derived subject.
<p>Derived subjects retain the {@link FailureStrategy} and {@linkplain
StandardSubjectBuilder#withMessage messages} of the current subject, and in some cases, they
automatically supplement their failure message with information about the original subject.
<p>For example, {@link ThrowableSubject#hasMessageThat}, which returns a {@link StringSubject},
is implemented with {@code check("getMessage()").that(actual.getMessage())}.
<p>The arguments to {@code check} describe how the new subject was derived from the old,
formatted like a chained method call. This allows Truth to include that information in its
failure messages. For example, {@code assertThat(caught).hasCauseThat().hasMessageThat()} will
produce a failure message that includes the string "throwable.getCause().getMessage()," thanks
to internal {@code check} calls that supplied "getCause()" and "getMessage()" as arguments.
<p>If the method you're delegating to accepts parameters, you can pass {@code check} a format
string. For example, {@link MultimapSubject#valuesForKey} calls {@code
check("valuesForKey(%s)", key)}.
<p>If you aren't really delegating to an instance method on the actual value -- maybe you're
calling a static method, or you're calling a chain of several methods -- you can supply
whatever string will be most useful to users. For example, if you're delegating to {@code
getOnlyElement(actual.colors())}, you might call {@code check("onlyColor()")}.
@param format a template with {@code %s} placeholders
@param args the arguments to be inserted into those placeholders
|
checkNoNeedToDisplayBothValues
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Subject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Subject.java
|
Apache-2.0
|
final StandardSubjectBuilder substituteCheck() {
return new StandardSubjectBuilder(checkNotNull(metadata));
}
|
Returns a builder for creating a subject for an object that is "close enough" to the original
actual value.
<p>This is a niche API: When one {@link Subject} wants to delegate to another, it should
normally use {@link #check(String, Object...)}, which augments the failure message by:
<ul>
<li>specifying which <i>part</i> of the actual value we are asserting about (e.g., "value of:
foo.size()")
<li>including both the original actual value and the relevant part of that value (e.g., both
the collection and its size)
</ul>
Thus, {@code substituteCheck()} is useful only when the new assertion is still (roughly
speaking) "about" the entire actual value. For example, {@link StreamSubject} uses this method
to create an {@link IterableSubject} for the contents of the stream.
<p>The result of {@code substituteCheck()} should be used carefully. For example, it should
<b>never</b> be returned to users unless the new subject has the exact full actual value as the
original one had. (As of this writing, we never do that, but that may change someday
(b/135436697? b/333091510?).) That's because:
<ul>
<li>If the assertion is about only a <i>part</i> of the actual value (or about some derived
value, as in {@link ObjectArraySubject#asList}), then we should use {@link #check(String,
Object...)}, as discussed above. (In some cases, we should instead introduce a non-{@link
Subject} type, such as {@link StringSubject.CaseInsensitiveStringComparison}.)
<li>Otherwise, we don't want to present an assertion as about the original actual value when
it's actually about some "stand-in" value. For example (though this isn't a great
example), we wouldn't want for {@code assertThat(stream).isEqualTo(expected)} to use
{@code substituteCheck().that(stream.toList())} internally: The test would be comparing
the <i>list</i> for equality, but the message would suggest that it's comparing the
<i>stream</i>.
</ul>
|
substituteCheck
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Subject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Subject.java
|
Apache-2.0
|
private StandardSubjectBuilder doCheck(
OldAndNewValuesAreSimilar valuesAreSimilar, String format, @Nullable Object[] args) {
LazyMessage message = LazyMessage.create(format, args);
return new StandardSubjectBuilder(
metadata.updateForCheckCall(
valuesAreSimilar, /* descriptionUpdate= */ input -> input + "." + message));
}
|
Returns a builder for creating a subject for an object that is "close enough" to the original
actual value.
<p>This is a niche API: When one {@link Subject} wants to delegate to another, it should
normally use {@link #check(String, Object...)}, which augments the failure message by:
<ul>
<li>specifying which <i>part</i> of the actual value we are asserting about (e.g., "value of:
foo.size()")
<li>including both the original actual value and the relevant part of that value (e.g., both
the collection and its size)
</ul>
Thus, {@code substituteCheck()} is useful only when the new assertion is still (roughly
speaking) "about" the entire actual value. For example, {@link StreamSubject} uses this method
to create an {@link IterableSubject} for the contents of the stream.
<p>The result of {@code substituteCheck()} should be used carefully. For example, it should
<b>never</b> be returned to users unless the new subject has the exact full actual value as the
original one had. (As of this writing, we never do that, but that may change someday
(b/135436697? b/333091510?).) That's because:
<ul>
<li>If the assertion is about only a <i>part</i> of the actual value (or about some derived
value, as in {@link ObjectArraySubject#asList}), then we should use {@link #check(String,
Object...)}, as discussed above. (In some cases, we should instead introduce a non-{@link
Subject} type, such as {@link StringSubject.CaseInsensitiveStringComparison}.)
<li>Otherwise, we don't want to present an assertion as about the original actual value when
it's actually about some "stand-in" value. For example (though this isn't a great
example), we wouldn't want for {@code assertThat(stream).isEqualTo(expected)} to use
{@code substituteCheck().that(stream.toList())} internally: The test would be comparing
the <i>list</i> for equality, but the message would suggest that it's comparing the
<i>stream</i>.
</ul>
|
doCheck
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Subject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Subject.java
|
Apache-2.0
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.