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 |
|---|---|---|---|---|---|---|---|
private static String countDuplicatesMultimap(Multimap<?, ?> multimap) {
List<String> entries = new ArrayList<>();
for (Object key : multimap.keySet()) {
entries.add(key + "=" + countDuplicates(get(multimap, key)));
}
StringBuilder sb = new StringBuilder();
sb.append("{");
Joiner.on(", ").appendTo(sb, entries);
sb.append("}");
return sb.toString();
}
|
Advances the iterator until it either returns value, or has no more elements.
<p>Returns true if the value was found, false if the end was reached before finding it.
<p>This is basically the same as {@link com.google.common.collect.Iterables#contains}, but
where the contract explicitly states that the iterator isn't advanced beyond the value if the
value is found.
|
countDuplicatesMultimap
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/MultimapSubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/MultimapSubject.java
|
Apache-2.0
|
private static Multimap<?, ?> annotateEmptyStringsMultimap(Multimap<?, ?> multimap) {
if (multimap.containsKey("") || multimap.containsValue("")) {
ListMultimap<@Nullable Object, @Nullable Object> annotatedMultimap =
LinkedListMultimap.create();
for (Map.Entry<?, ?> entry : multimap.entries()) {
Object key =
Objects.equals(entry.getKey(), "") ? HUMAN_UNDERSTANDABLE_EMPTY_STRING : entry.getKey();
Object value =
Objects.equals(entry.getValue(), "")
? HUMAN_UNDERSTANDABLE_EMPTY_STRING
: entry.getValue();
annotatedMultimap.put(key, value);
}
return annotatedMultimap;
} else {
return multimap;
}
}
|
Returns a multimap with all empty strings (as keys or values) replaced by a non-empty human
understandable indicator for an empty string.
<p>Returns the given multimap if it contains no empty strings.
|
annotateEmptyStringsMultimap
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/MultimapSubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/MultimapSubject.java
|
Apache-2.0
|
public <A extends @Nullable Object, E extends @Nullable Object>
UsingCorrespondence<A, E> comparingValuesUsing(
Correspondence<? super A, ? super E> correspondence) {
return UsingCorrespondence.create(this, correspondence);
}
|
Starts a method chain for a check in which the actual values (i.e. the values of the {@link
Multimap} under test) are compared to expected values using the given {@link Correspondence}.
The actual values must be of type {@code A}, and the expected values must be of type {@code E}.
The check is actually executed by continuing the method chain. For example:
<pre>{@code
assertThat(actualMultimap)
.comparingValuesUsing(correspondence)
.containsEntry(expectedKey, expectedValue);
}</pre>
where {@code actualMultimap} is a {@code Multimap<?, A>} (or, more generally, a {@code
Multimap<?, ? extends A>}), {@code correspondence} is a {@code Correspondence<A, E>}, and
{@code expectedValue} is an {@code E}.
<p>Note that keys will always be compared with regular object equality ({@link Object#equals}).
<p>Any of the methods on the returned object may throw {@link ClassCastException} if they
encounter an actual multimap that is not of type {@code A}.
|
comparingValuesUsing
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/MultimapSubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/MultimapSubject.java
|
Apache-2.0
|
@SuppressWarnings("nullness") // TODO: b/423853632 - Remove after checker is fixed.
public void containsEntry(@Nullable Object expectedKey, E expectedValue) {
if (checkNotNull(actual).containsKey(expectedKey)) {
// Found matching key.
Collection<A> actualValues = checkNotNull(getCastActual().asMap().get(expectedKey));
Correspondence.ExceptionStore exceptions = Correspondence.ExceptionStore.forMapValues();
for (A actualValue : actualValues) {
if (correspondence.safeCompare(actualValue, expectedValue, exceptions)) {
// Found matching key and value, but we still need to fail if we hit an exception along
// the way.
if (exceptions.hasCompareException()) {
failWithoutActual(
ImmutableList.<Fact>builder()
.addAll(exceptions.describeAsMainCause())
.add(
fact(
"expected to contain entry",
immutableEntry(expectedKey, expectedValue)))
.addAll(correspondence.describeForMapValues())
.add(
fact(
"found match (but failing because of exception)",
immutableEntry(expectedKey, actualValue)))
.add(
fact(
"full contents",
actualCustomStringRepresentationForPackageMembersToCall()))
.build());
}
return;
}
}
// Found matching key with non-matching values.
failWithoutActual(
ImmutableList.<Fact>builder()
.add(fact("expected to contain entry", immutableEntry(expectedKey, expectedValue)))
.addAll(correspondence.describeForMapValues())
.add(simpleFact("but did not"))
.add(fact("though it did contain values for that key", actualValues))
.add(
fact(
"full contents", actualCustomStringRepresentationForPackageMembersToCall()))
.addAll(exceptions.describeAsAdditionalInfo())
.build());
} else {
// Did not find matching key.
Set<Map.Entry<?, ?>> entries = new LinkedHashSet<>();
Correspondence.ExceptionStore exceptions = Correspondence.ExceptionStore.forMapValues();
for (Map.Entry<?, A> actualEntry : getCastActual().entries()) {
if (correspondence.safeCompare(actualEntry.getValue(), expectedValue, exceptions)) {
entries.add(actualEntry);
}
}
if (!entries.isEmpty()) {
// Found matching values with non-matching keys.
failWithoutActual(
ImmutableList.<Fact>builder()
.add(
fact("expected to contain entry", immutableEntry(expectedKey, expectedValue)))
.addAll(correspondence.describeForMapValues())
.add(simpleFact("but did not"))
// The corresponding failure in the non-Correspondence case reports the keys
// mapping to the expected value. Here, we show the full entries, because for some
// Correspondences it may not be obvious which of the actual values it was that
// corresponded to the expected value.
.add(fact("though it did contain entries with matching values", entries))
.add(
fact(
"full contents",
actualCustomStringRepresentationForPackageMembersToCall()))
.addAll(exceptions.describeAsAdditionalInfo())
.build());
} else {
// Did not find matching key or value.
failWithoutActual(
ImmutableList.<Fact>builder()
.add(
fact("expected to contain entry", immutableEntry(expectedKey, expectedValue)))
.addAll(correspondence.describeForMapValues())
.add(simpleFact("but did not"))
.add(
fact(
"full contents",
actualCustomStringRepresentationForPackageMembersToCall()))
.addAll(exceptions.describeAsAdditionalInfo())
.build());
}
}
}
|
Checks that the actual multimap contains an entry with the given key and a value that
corresponds to the given value.
|
containsEntry
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/MultimapSubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/MultimapSubject.java
|
Apache-2.0
|
public void doesNotContainEntry(@Nullable Object excludedKey, E excludedValue) {
if (checkNotNull(actual).containsKey(excludedKey)) {
Collection<A> actualValues = checkNotNull(getCastActual().asMap().get(excludedKey));
List<A> matchingValues = new ArrayList<>();
Correspondence.ExceptionStore exceptions = Correspondence.ExceptionStore.forMapValues();
for (A actualValue : actualValues) {
if (correspondence.safeCompare(actualValue, excludedValue, exceptions)) {
matchingValues.add(actualValue);
}
}
// Fail if we found a matching value for the key.
if (!matchingValues.isEmpty()) {
failWithoutActual(
ImmutableList.<Fact>builder()
.add(
fact(
"expected not to contain entry",
immutableEntry(excludedKey, excludedValue)))
.addAll(correspondence.describeForMapValues())
.add(fact("but contained that key with matching values", matchingValues))
.add(
fact(
"full contents",
actualCustomStringRepresentationForPackageMembersToCall()))
.addAll(exceptions.describeAsAdditionalInfo())
.build());
} else {
// No value matched, but we still need to fail if we hit an exception along the way.
if (exceptions.hasCompareException()) {
failWithoutActual(
ImmutableList.<Fact>builder()
.addAll(exceptions.describeAsMainCause())
.add(
fact(
"expected not to contain entry",
immutableEntry(excludedKey, excludedValue)))
.addAll(correspondence.describeForMapValues())
.add(simpleFact("found no match (but failing because of exception)"))
.add(
fact(
"full contents",
actualCustomStringRepresentationForPackageMembersToCall()))
.build());
}
}
}
}
|
Checks that the actual multimap does not contain an entry with the given key and a value that
corresponds to the given value.
|
doesNotContainEntry
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/MultimapSubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/MultimapSubject.java
|
Apache-2.0
|
@CanIgnoreReturnValue
public Ordered containsExactlyEntriesIn(Multimap<?, ? extends E> expectedMultimap) {
return internalContainsExactlyEntriesIn(expectedMultimap);
}
|
Checks that the actual multimap contains exactly the keys in the given multimap, mapping to
values that correspond to the values of the given multimap.
<p>A subsequent call to {@link Ordered#inOrder} may be made if the caller wishes to verify
that the two Multimaps iterate fully in the same order. That is, their key sets iterate in
the same order, and the corresponding value collections for each key iterate in the same
order.
|
containsExactlyEntriesIn
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/MultimapSubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/MultimapSubject.java
|
Apache-2.0
|
private <K extends @Nullable Object, V extends E> Ordered internalContainsExactlyEntriesIn(
Multimap<K, V> expectedMultimap) {
// Note: The non-fuzzy MultimapSubject.containsExactlyEntriesIn has a custom implementation
// and produces somewhat better failure messages simply asserting about the iterables of
// entries would: it formats the expected values as k=[v1, v2] rather than k=v1, k=v2; and in
// the case where inOrder() fails it says the keys and/or the values for some keys are out of
// order. We don't bother with that here. It would be nice, but it would be a lot of added
// complexity for little gain.
return subject
.substituteCheck()
.about(subject.iterableEntries())
.that(checkNotNull(actual).entries())
.comparingElementsUsing(MultimapSubject.<K, A, V>entryCorrespondence(correspondence))
.containsExactlyElementsIn(expectedMultimap.entries());
}
|
Checks that the actual multimap contains exactly the keys in the given multimap, mapping to
values that correspond to the values of the given multimap.
<p>A subsequent call to {@link Ordered#inOrder} may be made if the caller wishes to verify
that the two Multimaps iterate fully in the same order. That is, their key sets iterate in
the same order, and the corresponding value collections for each key iterate in the same
order.
|
internalContainsExactlyEntriesIn
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/MultimapSubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/MultimapSubject.java
|
Apache-2.0
|
@CanIgnoreReturnValue
public Ordered containsAtLeastEntriesIn(Multimap<?, ? extends E> expectedMultimap) {
return internalContainsAtLeastEntriesIn(expectedMultimap);
}
|
Checks that the actual multimap contains at least the keys in the given multimap, mapping to
values that correspond to the values of the given multimap.
<p>A subsequent call to {@link Ordered#inOrder} may be made if the caller wishes to verify
that the two Multimaps iterate fully in the same order. That is, their key sets iterate in
the same order, and the corresponding value collections for each key iterate in the same
order.
|
containsAtLeastEntriesIn
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/MultimapSubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/MultimapSubject.java
|
Apache-2.0
|
private <K extends @Nullable Object, V extends E> Ordered internalContainsAtLeastEntriesIn(
Multimap<K, V> expectedMultimap) {
// Note: The non-fuzzy MultimapSubject.containsAtLeastEntriesIn has a custom implementation
// and produces somewhat better failure messages simply asserting about the iterables of
// entries would: it formats the expected values as k=[v1, v2] rather than k=v1, k=v2; and in
// the case where inOrder() fails it says the keys and/or the values for some keys are out of
// order. We don't bother with that here. It would be nice, but it would be a lot of added
// complexity for little gain.
return subject
.substituteCheck()
.about(subject.iterableEntries())
.that(checkNotNull(actual).entries())
.comparingElementsUsing(MultimapSubject.<K, A, V>entryCorrespondence(correspondence))
.containsAtLeastElementsIn(expectedMultimap.entries());
}
|
Checks that the actual multimap contains at least the keys in the given multimap, mapping to
values that correspond to the values of the given multimap.
<p>A subsequent call to {@link Ordered#inOrder} may be made if the caller wishes to verify
that the two Multimaps iterate fully in the same order. That is, their key sets iterate in
the same order, and the corresponding value collections for each key iterate in the same
order.
|
internalContainsAtLeastEntriesIn
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/MultimapSubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/MultimapSubject.java
|
Apache-2.0
|
@CanIgnoreReturnValue
public Ordered containsExactly(@Nullable Object k0, @Nullable E v0, @Nullable Object... rest) {
@SuppressWarnings("unchecked")
Multimap<?, E> expectedMultimap = (Multimap<?, E>) accumulateMultimap(k0, v0, rest);
return containsExactlyEntriesIn(expectedMultimap);
}
|
Checks that the actual multimap contains exactly the given set of key/value pairs.
<p><b>Warning:</b> the use of varargs means that we cannot guarantee an equal number of
key/value pairs at compile time. Please make sure you provide varargs in key/value pairs!
|
containsExactly
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/MultimapSubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/MultimapSubject.java
|
Apache-2.0
|
@CanIgnoreReturnValue
public Ordered containsExactly() {
return subject.containsExactly();
}
|
Checks that the actual multimap is empty.
|
containsExactly
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/MultimapSubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/MultimapSubject.java
|
Apache-2.0
|
@CanIgnoreReturnValue
public Ordered containsAtLeast(@Nullable Object k0, @Nullable E v0, @Nullable Object... rest) {
@SuppressWarnings("unchecked")
Multimap<?, E> expectedMultimap = (Multimap<?, E>) accumulateMultimap(k0, v0, rest);
return containsAtLeastEntriesIn(expectedMultimap);
}
|
Checks that the actual multimap contains at least the given key/value pairs.
<p><b>Warning:</b> the use of varargs means that we cannot guarantee an equal number of
key/value pairs at compile time. Please make sure you provide varargs in key/value pairs!
|
containsAtLeast
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/MultimapSubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/MultimapSubject.java
|
Apache-2.0
|
@SuppressWarnings("unchecked") // throwing ClassCastException is the correct behaviour
private Multimap<?, A> getCastActual() {
return (Multimap<?, A>) checkNotNull(actual);
}
|
Checks that the actual multimap contains at least the given key/value pairs.
<p><b>Warning:</b> the use of varargs means that we cannot guarantee an equal number of
key/value pairs at compile time. Please make sure you provide varargs in key/value pairs!
|
getCastActual
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/MultimapSubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/MultimapSubject.java
|
Apache-2.0
|
private String actualCustomStringRepresentationForPackageMembersToCall() {
return subject.actualCustomStringRepresentationForPackageMembersToCall();
}
|
Checks that the actual multimap contains at least the given key/value pairs.
<p><b>Warning:</b> the use of varargs means that we cannot guarantee an equal number of
key/value pairs at compile time. Please make sure you provide varargs in key/value pairs!
|
actualCustomStringRepresentationForPackageMembersToCall
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/MultimapSubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/MultimapSubject.java
|
Apache-2.0
|
static <E extends @Nullable Object, A extends @Nullable Object>
UsingCorrespondence<A, E> create(
MultimapSubject subject, Correspondence<? super A, ? super E> correspondence) {
return new UsingCorrespondence<>(subject, correspondence);
}
|
Checks that the actual multimap contains at least the given key/value pairs.
<p><b>Warning:</b> the use of varargs means that we cannot guarantee an equal number of
key/value pairs at compile time. Please make sure you provide varargs in key/value pairs!
|
create
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/MultimapSubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/MultimapSubject.java
|
Apache-2.0
|
private static <
K extends @Nullable Object, A extends @Nullable Object, E extends @Nullable Object>
Correspondence<Map.Entry<K, A>, Map.Entry<K, E>> entryCorrespondence(
Correspondence<? super A, ? super E> valueCorrespondence) {
return Correspondence.from(
(Map.Entry<K, A> actual, Map.Entry<K, E> expected) ->
Objects.equals(actual.getKey(), expected.getKey())
&& valueCorrespondence.compare(actual.getValue(), expected.getValue()),
lenientFormat(
"has a key that is equal to and a value that %s the key and value of",
valueCorrespondence));
}
|
Checks that the actual multimap contains at least the given key/value pairs.
<p><b>Warning:</b> the use of varargs means that we cannot guarantee an equal number of
key/value pairs at compile time. Please make sure you provide varargs in key/value pairs!
|
entryCorrespondence
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/MultimapSubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/MultimapSubject.java
|
Apache-2.0
|
static Factory<MultimapSubject, Multimap<?, ?>> multimaps() {
return MultimapSubject::new;
}
|
Checks that the actual multimap contains at least the given key/value pairs.
<p><b>Warning:</b> the use of varargs means that we cannot guarantee an equal number of
key/value pairs at compile time. Please make sure you provide varargs in key/value pairs!
|
multimaps
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/MultimapSubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/MultimapSubject.java
|
Apache-2.0
|
public final void hasCount(@Nullable Object element, int expectedCount) {
checkArgument(expectedCount >= 0, "expectedCount(%s) must be >= 0", expectedCount);
int actualCount = checkNotNull(actual).count(element);
check("count(%s)", element).that(actualCount).isEqualTo(expectedCount);
}
|
Checks that the actual multiset has exactly the given number of occurrences of the given
element.
|
hasCount
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/MultisetSubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/MultisetSubject.java
|
Apache-2.0
|
static Factory<MultisetSubject, Multiset<?>> multisets() {
return MultisetSubject::new;
}
|
Checks that the actual multiset has exactly the given number of occurrences of the given
element.
|
multisets
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/MultisetSubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/MultisetSubject.java
|
Apache-2.0
|
@SuppressWarnings("nullness")
static <T extends @Nullable Object> T uncheckedCastNullableTToT(@Nullable T t) {
return t;
}
|
Accepts a {@code @Nullable T} and returns a plain {@code T}, without performing any check that
that conversion is safe.
<p>This method is intended to help with usages of type parameters that have parametric
nullness. If a type parameter instead ranges over only non-null types (or if the type is a
non-variable type, like {@code String}), then code should almost never use this method,
preferring instead to call {@code requireNonNull} so as to benefit from its runtime check.
<p>An example use case for this method is in implementing an {@code Iterator<T>} whose {@code
next} field is lazily initialized. The type of that field would be {@code @Nullable T}, and the
code would be responsible for populating a "real" {@code T} (which might still be the value
{@code null}!) before returning it to callers. Depending on how the code is structured, a
nullness analysis might not understand that the field has been populated. To avoid that problem
without having to add {@code @SuppressWarnings}, the code can call this method.
<p>Why <i>not</i> just add {@code SuppressWarnings}? The problem is that this method is
typically useful for {@code return} statements. That leaves the code with two options: Either
add the suppression to the whole method (which turns off checking for a large section of code),
or extract a variable, and put the suppression on that. However, a local variable typically
doesn't work: Because nullness analyses typically infer the nullness of local variables,
there's no way to assign a {@code @Nullable T} to a field {@code T foo;} and instruct the
analysis that that means "plain {@code T}" rather than the inferred type {@code @Nullable T}.
(Even if supported added {@code @NonNull}, that would not help, since the problem case
addressed by this method is the case in which {@code T} has parametric nullness -- and thus its
value may be legitimately {@code null}.)
|
uncheckedCastNullableTToT
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/NullnessCasts.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/NullnessCasts.java
|
Apache-2.0
|
public IterableSubject asList() {
if (actual == null) {
failWithoutActual(simpleFact("cannot perform assertions on the contents of a null array"));
return ignoreCheck().that(ImmutableList.of());
}
return checkNoNeedToDisplayBothValues("asList()").that(Arrays.asList(actual));
}
|
A subject for {@code Object[]} and more generically {@code T[]}.
@author Christian Gruber
|
asList
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/ObjectArraySubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/ObjectArraySubject.java
|
Apache-2.0
|
static <T extends @Nullable Object> Factory<ObjectArraySubject<T>, T[]> objectArrays() {
return ObjectArraySubject::new;
}
|
Checks that the actual array has the given length.
|
objectArrays
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/ObjectArraySubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/ObjectArraySubject.java
|
Apache-2.0
|
public void isPresent() {
if (actual == null) {
failWithActual(simpleFact("expected present optional"));
} else if (!actual.isPresent()) {
failWithoutActual(simpleFact("expected to be present"));
}
}
|
Checks that the actual {@link OptionalDouble} contains a value.
|
isPresent
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/OptionalDoubleSubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/OptionalDoubleSubject.java
|
Apache-2.0
|
public void isEmpty() {
if (actual == null) {
failWithActual(simpleFact("expected empty optional"));
} else if (actual.isPresent()) {
failWithoutActual(
simpleFact("expected to be empty"),
fact("but was present with value", doubleToString(actual.getAsDouble())));
}
}
|
Checks that the actual {@link OptionalDouble} does not contain a value.
|
isEmpty
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/OptionalDoubleSubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/OptionalDoubleSubject.java
|
Apache-2.0
|
@Deprecated
@SuppressWarnings("InlineMeSuggester") // We want users to remove the surrounding call entirely.
public static Factory<OptionalDoubleSubject, OptionalDouble> optionalDoubles() {
return OptionalDoubleSubject::new;
}
|
Obsolete factory instance. This factory was previously necessary for assertions like {@code
assertWithMessage(...).about(optionalDoubles()).that(optional)....}. Now, you can perform
assertions like that without the {@code about(...)} call.
@deprecated Instead of {@code about(optionalDoubles()).that(...)}, use just {@code that(...)}.
Similarly, instead of {@code assertAbout(optionalDoubles()).that(...)}, use just {@code
assertThat(...)}.
|
optionalDoubles
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/OptionalDoubleSubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/OptionalDoubleSubject.java
|
Apache-2.0
|
public void isPresent() {
if (actual == null) {
failWithActual(simpleFact("expected present optional"));
} else if (!actual.isPresent()) {
failWithoutActual(simpleFact("expected to be present"));
}
}
|
Checks that the actual {@link OptionalInt} contains a value.
|
isPresent
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/OptionalIntSubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/OptionalIntSubject.java
|
Apache-2.0
|
public void isEmpty() {
if (actual == null) {
failWithActual(simpleFact("expected empty optional"));
} else if (actual.isPresent()) {
failWithoutActual(
simpleFact("expected to be empty"),
fact("but was present with value", actual.getAsInt()));
}
}
|
Checks that the actual {@link OptionalInt} does not contain a value.
|
isEmpty
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/OptionalIntSubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/OptionalIntSubject.java
|
Apache-2.0
|
@Deprecated
@SuppressWarnings("InlineMeSuggester") // We want users to remove the surrounding call entirely.
public static Factory<OptionalIntSubject, OptionalInt> optionalInts() {
return OptionalIntSubject::new;
}
|
Obsolete factory instance. This factory was previously necessary for assertions like {@code
assertWithMessage(...).about(optionalInts()).that(optional)....}. Now, you can perform
assertions like that without the {@code about(...)} call.
@deprecated Instead of {@code about(optionalInts()).that(...)}, use just {@code that(...)}.
Similarly, instead of {@code assertAbout(optionalInts()).that(...)}, use just {@code
assertThat(...)}.
|
optionalInts
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/OptionalIntSubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/OptionalIntSubject.java
|
Apache-2.0
|
public void isPresent() {
if (actual == null) {
failWithActual(simpleFact("expected present optional"));
} else if (!actual.isPresent()) {
failWithoutActual(simpleFact("expected to be present"));
}
}
|
Checks that the actual {@link OptionalLong} contains a value.
|
isPresent
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/OptionalLongSubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/OptionalLongSubject.java
|
Apache-2.0
|
public void isEmpty() {
if (actual == null) {
failWithActual(simpleFact("expected empty optional"));
} else if (actual.isPresent()) {
failWithoutActual(
simpleFact("expected to be empty"),
fact("but was present with value", actual.getAsLong()));
}
}
|
Checks that the actual {@link OptionalLong} does not contain a value.
|
isEmpty
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/OptionalLongSubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/OptionalLongSubject.java
|
Apache-2.0
|
@Deprecated
@SuppressWarnings("InlineMeSuggester") // We want users to remove the surrounding call entirely.
public static Factory<OptionalLongSubject, OptionalLong> optionalLongs() {
return OptionalLongSubject::new;
}
|
Obsolete factory instance. This factory was previously necessary for assertions like {@code
assertWithMessage(...).about(optionalLongs()).that(optional)....}. Now, you can perform
assertions like that without the {@code about(...)} call.
@deprecated Instead of {@code about(optionalLongs()).that(...)}, use just {@code that(...)}.
Similarly, instead of {@code assertAbout(optionalLongs()).that(...)}, use just {@code
assertThat(...)}.
|
optionalLongs
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/OptionalLongSubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/OptionalLongSubject.java
|
Apache-2.0
|
public void isPresent() {
if (actual == null) {
failWithActual(simpleFact("expected present optional"));
} else if (!actual.isPresent()) {
failWithoutActual(simpleFact("expected to be present"));
}
}
|
Checks that the actual {@link Optional} contains a value.
|
isPresent
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/OptionalSubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/OptionalSubject.java
|
Apache-2.0
|
public void isEmpty() {
if (actual == null) {
failWithActual(simpleFact("expected empty optional"));
} else if (actual.isPresent()) {
failWithoutActual(
simpleFact("expected to be empty"), fact("but was present with value", actual.get()));
}
}
|
Checks that the actual {@link Optional} does not contain a value.
|
isEmpty
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/OptionalSubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/OptionalSubject.java
|
Apache-2.0
|
public void hasValue(@Nullable Object expected) {
if (expected == null) {
failWithoutActual(
simpleFact("expected an optional with a null value, but that is impossible"),
fact("was", actual));
} else if (actual == null) {
failWithActual("expected an optional with value", expected);
} else if (!actual.isPresent()) {
failWithoutActual(fact("expected to have value", expected), simpleFact("but was empty"));
} else {
checkNoNeedToDisplayBothValues("get()").that(actual.get()).isEqualTo(expected);
}
}
|
Checks that the actual {@link Optional} contains the given value.
<p>To make more complex assertions on the optional's value, split your assertion in two:
<pre>{@code
assertThat(myOptional).isPresent();
assertThat(myOptional.get()).contains("foo");
}</pre>
|
hasValue
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/OptionalSubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/OptionalSubject.java
|
Apache-2.0
|
@Deprecated
@SuppressWarnings("InlineMeSuggester") // We want users to remove the surrounding call entirely.
public static Factory<OptionalSubject, Optional<?>> optionals() {
return OptionalSubject::new;
}
|
Obsolete factory instance. This factory was previously necessary for assertions like {@code
assertWithMessage(...).about(paths()).that(path)....}. Now, you can perform assertions like
that without the {@code about(...)} call.
@deprecated Instead of {@code about(optionals()).that(...)}, use just {@code that(...)}.
Similarly, instead of {@code assertAbout(optionals()).that(...)}, use just {@code
assertThat(...)}.
|
optionals
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/OptionalSubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/OptionalSubject.java
|
Apache-2.0
|
@Deprecated
@SuppressWarnings("InlineMeSuggester") // We want users to remove the surrounding call entirely.
public static Factory<PathSubject, Path> paths() {
return PathSubject::new;
}
|
Obsolete factory instance. This factory was previously necessary for assertions like {@code
assertWithMessage(...).about(paths()).that(path)....}. Now, you can perform assertions like
that without the {@code about(...)} call.
@deprecated Instead of {@code about(paths()).that(...)}, use just {@code that(...)}. Similarly,
instead of {@code assertAbout(paths()).that(...)}, use just {@code assertThat(...)}.
|
paths
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/PathSubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/PathSubject.java
|
Apache-2.0
|
static boolean isInstanceOfType(Object instance, Class<?> clazz) {
return clazz.isInstance(instance);
}
|
Returns true if the instance is assignable to the type Clazz.
|
isInstanceOfType
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Platform.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Platform.java
|
Apache-2.0
|
static boolean containsMatch(String actual, String regex) {
return Pattern.compile(regex).matcher(actual).find();
}
|
Determines if the given actual value contains a match for the given regex.
|
containsMatch
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Platform.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Platform.java
|
Apache-2.0
|
static @Nullable String inferDescription() {
if (isInferDescriptionDisabled()) {
return null;
}
AssertionError stack = new AssertionError();
/*
* cleanStackTrace() lets users turn off cleaning, so it's possible that we'll end up operating
* on an uncleaned stack trace. That should be mostly harmless. We could try force-enabling
* cleaning for inferDescription() only, but if anyone is turning it off, it might be because of
* bugs or confusing stack traces. Force-enabling it here might trigger those same problems.
*/
cleanStackTrace(stack);
if (stack.getStackTrace().length == 0) {
return null;
}
StackTraceElement top = stack.getStackTrace()[0];
try {
/*
* Invoke ActualValueInference reflectively so that Truth can be compiled and run without its
* dependency, ASM, on the classpath.
*
* Also, mildly obfuscate the class name that we're looking up. The obfuscation prevents R8
* from detecting the usage of ActualValueInference. That in turn lets users exclude it from
* the compile-time classpath if they want. (And then *that* probably makes it easier and/or
* safer for R8 users (i.e., Android users) to exclude it from the *runtime* classpath. It
* would do no good there, anyway, since ASM won't find any .class files to load under
* Android. Perhaps R8 will even omit ASM automatically once it detects that it's "unused?")
*
*/
String clazz =
Joiner.on('.').join("com", "google", "common", "truth", "ActualValueInference");
return (String)
Class.forName(clazz)
.getDeclaredMethod("describeActualValue", String.class, String.class, int.class)
.invoke(null, top.getClassName(), top.getMethodName(), top.getLineNumber());
} catch (IllegalAccessException
| InvocationTargetException
| NoSuchMethodException
| ClassNotFoundException
| LinkageError
| RuntimeException e) {
// Some possible reasons:
// - Someone has omitted ASM from the classpath.
// - An optimizer has stripped ActualValueInference (though it's unusual to optimize tests).
// - There's a bug.
// - We don't handle a new bytecode feature.
// TODO(cpovirk): Log a warning, at least for non-ClassNotFoundException, non-LinkageError?
return null;
}
}
|
Tries to infer a name for the root actual value from the bytecode. The "root" actual value is
the value passed to {@code assertThat} or {@code that}, as distinct from any later actual
values produced by chaining calls like {@code hasMessageThat}.
|
inferDescription
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Platform.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Platform.java
|
Apache-2.0
|
static @Nullable ImmutableList<Fact> makeDiff(String expected, String actual) {
List<String> expectedLines = splitLines(expected);
List<String> actualLines = splitLines(actual);
List<String> unifiedDiff =
generateUnifiedDiff(expectedLines, actualLines, /* contextSize= */ 3);
if (unifiedDiff.isEmpty()) {
return ImmutableList.of(
fact(DIFF_KEY, "(line contents match, but line-break characters differ)"));
// TODO(cpovirk): Possibly include the expected/actual value, too?
}
String result = Joiner.on("\n").join(unifiedDiff);
if (result.length() > expected.length() && result.length() > actual.length()) {
return null;
}
return ImmutableList.of(fact(DIFF_KEY, result));
}
|
Tries to infer a name for the root actual value from the bytecode. The "root" actual value is
the value passed to {@code assertThat} or {@code that}, as distinct from any later actual
values produced by chaining calls like {@code hasMessageThat}.
|
makeDiff
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Platform.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Platform.java
|
Apache-2.0
|
private static List<String> splitLines(String s) {
return Splitter.on(NEWLINE_PATTERN).splitToList(s);
}
|
Tries to infer a name for the root actual value from the bytecode. The "root" actual value is
the value passed to {@code assertThat} or {@code that}, as distinct from any later actual
values produced by chaining calls like {@code hasMessageThat}.
|
splitLines
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Platform.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Platform.java
|
Apache-2.0
|
@Override
public final String getMessage() {
return message;
}
|
Tries to infer a name for the root actual value from the bytecode. The "root" actual value is
the value passed to {@code assertThat} or {@code that}, as distinct from any later actual
values produced by chaining calls like {@code hasMessageThat}.
|
getMessage
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Platform.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Platform.java
|
Apache-2.0
|
@Override
public final String toString() {
return checkNotNull(getLocalizedMessage());
}
|
Tries to infer a name for the root actual value from the bytecode. The "root" actual value is
the value passed to {@code assertThat} or {@code that}, as distinct from any later actual
values produced by chaining calls like {@code hasMessageThat}.
|
toString
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Platform.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Platform.java
|
Apache-2.0
|
static String doubleToString(double value) {
return Double.toString(value);
}
|
Tries to infer a name for the root actual value from the bytecode. The "root" actual value is
the value passed to {@code assertThat} or {@code that}, as distinct from any later actual
values produced by chaining calls like {@code hasMessageThat}.
|
doubleToString
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Platform.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Platform.java
|
Apache-2.0
|
static String floatToString(float value) {
return Float.toString(value);
}
|
Tries to infer a name for the root actual value from the bytecode. The "root" actual value is
the value passed to {@code assertThat} or {@code that}, as distinct from any later actual
values produced by chaining calls like {@code hasMessageThat}.
|
floatToString
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Platform.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Platform.java
|
Apache-2.0
|
static String stringValueOfNonFloatingPoint(@Nullable Object o) {
return String.valueOf(o);
}
|
Turns a non-double, non-float object into a string.
|
stringValueOfNonFloatingPoint
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Platform.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Platform.java
|
Apache-2.0
|
static String getStackTraceAsString(Throwable throwable) {
return Throwables.getStackTraceAsString(throwable);
}
|
Returns a human readable string representation of the throwable's stack trace.
|
getStackTraceAsString
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Platform.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Platform.java
|
Apache-2.0
|
static boolean isAndroid() {
return checkNotNull(System.getProperty("java.runtime.name", "")).contains("Android");
}
|
Tests if current platform is Android.
|
isAndroid
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Platform.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Platform.java
|
Apache-2.0
|
private static boolean isInferDescriptionDisabled() {
// Reading system properties might be forbidden.
try {
return Boolean.parseBoolean(
System.getProperty("com.google.common.truth.disable_infer_description"));
} catch (SecurityException e) {
// Hope for the best.
return false;
}
}
|
Wrapping interface of {@link TestRule} to be used within truth.
<p>Note that the sole purpose of this interface is to allow it to be swapped in GWT
implementation.
|
isInferDescriptionDisabled
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Platform.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Platform.java
|
Apache-2.0
|
static AssertionError makeComparisonFailure(
ImmutableList<String> messages,
ImmutableList<Fact> facts,
String expected,
String actual,
@Nullable Throwable cause) {
Class<?> comparisonFailureClass;
try {
comparisonFailureClass = Class.forName("com.google.common.truth.ComparisonFailureWithFacts");
} catch (LinkageError | ClassNotFoundException probablyJunitNotOnClasspath) {
/*
* We're using reflection because ComparisonFailureWithFacts depends on JUnit 4, a dependency
* that we want to allow open-source users to exclude:
* https://github.com/google/truth/issues/333
*
* Even if users do exclude JUnit 4, Truth's ComparisonFailureWithFacts class itself should
* still exist; it's only the subsequent class loading that should ever fail. That means that
* we should see only LinkageError in practice, not ClassNotFoundException.
*
* Still, we catch ClassNotFoundException anyway because the compiler makes us. Fortunately,
* it's harmless to catch an "impossible" exception, and if someone decides to strip the class
* out (perhaps along with Platform.PlatformComparisonFailure, to satisfy a tool that is
* unhappy because it can't find the latter's superclass because JUnit 4 is also missing?),
* presumably we should still fall back to a plain AssertionError.
*
* TODO(cpovirk): Consider creating and using yet another class like AssertionErrorWithFacts,
* not actually extending ComparisonFailure but still exposing getExpected() and getActual()
* methods.
*/
return AssertionErrorWithFacts.create(messages, facts, cause);
}
Method createMethod;
try {
createMethod =
comparisonFailureClass.getDeclaredMethod(
"create",
ImmutableList.class,
ImmutableList.class,
String.class,
String.class,
Throwable.class);
} catch (NoSuchMethodException e) {
// Should not happen: the factory method exists.
throw newLinkageError(e);
}
try {
return (AssertionError) createMethod.invoke(null, messages, facts, expected, actual, cause);
} catch (InvocationTargetException e) {
// The factory method has no `throws` clause so this will be an unchecked exception anyway.
throw sneakyThrow(e.getCause());
} catch (IllegalAccessException e) {
// Should not happen: we're accessing a package-private method from within its package.
throw newLinkageError(e);
}
}
|
Wrapping interface of {@link TestRule} to be used within truth.
<p>Note that the sole purpose of this interface is to allow it to be swapped in GWT
implementation.
|
makeComparisonFailure
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Platform.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Platform.java
|
Apache-2.0
|
private static LinkageError newLinkageError(Throwable cause) {
return new LinkageError(cause.toString(), cause);
}
|
Wrapping interface of {@link TestRule} to be used within truth.
<p>Note that the sole purpose of this interface is to allow it to be swapped in GWT
implementation.
|
newLinkageError
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Platform.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Platform.java
|
Apache-2.0
|
static boolean isKotlinRange(Iterable<?> iterable) {
return closedRangeClassIfAvailable.get() != null
&& closedRangeClassIfAvailable.get().isInstance(iterable);
// (If the class isn't available, then nothing could be an instance of ClosedRange.)
}
|
Wrapping interface of {@link TestRule} to be used within truth.
<p>Note that the sole purpose of this interface is to allow it to be swapped in GWT
implementation.
|
isKotlinRange
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Platform.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Platform.java
|
Apache-2.0
|
static boolean kotlinRangeContains(Iterable<?> haystack, @Nullable Object needle) {
try {
return (boolean) closedRangeContainsMethod.get().invoke(haystack, needle);
} catch (InvocationTargetException e) {
if (e.getCause() instanceof ClassCastException) {
// icky but no worse than what we normally do for isIn(Iterable)
return false;
// TODO(cpovirk): Should we also look for NullPointerException?
}
// That method has no `throws` clause.
throw sneakyThrow(e.getCause());
} catch (IllegalAccessException e) {
// We're calling a public method on a public class.
throw newLinkageError(e);
}
}
|
Wrapping interface of {@link TestRule} to be used within truth.
<p>Note that the sole purpose of this interface is to allow it to be swapped in GWT
implementation.
|
kotlinRangeContains
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Platform.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Platform.java
|
Apache-2.0
|
static boolean classMetadataUnsupported() {
// https://github.com/google/truth/issues/198
// TODO(cpovirk): Consider whether to remove instanceof tests under GWT entirely.
// TODO(cpovirk): Run more Truth tests under GWT, and add tests for this.
return false;
}
|
Wrapping interface of {@link TestRule} to be used within truth.
<p>Note that the sole purpose of this interface is to allow it to be swapped in GWT
implementation.
|
classMetadataUnsupported
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Platform.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Platform.java
|
Apache-2.0
|
public IterableSubject asList() {
if (actual == null) {
failWithoutActual(simpleFact("cannot perform assertions on the contents of a null array"));
return ignoreCheck().that(ImmutableList.of());
}
return checkNoNeedToDisplayBothValues("asList()").that(Booleans.asList(actual));
}
|
A subject for {@code boolean[]}.
@author Christian Gruber (cgruber@israfil.net)
|
asList
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/PrimitiveBooleanArraySubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/PrimitiveBooleanArraySubject.java
|
Apache-2.0
|
static Factory<PrimitiveBooleanArraySubject, boolean[]> booleanArrays() {
return PrimitiveBooleanArraySubject::new;
}
|
Checks that the actual array has the given length.
|
booleanArrays
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/PrimitiveBooleanArraySubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/PrimitiveBooleanArraySubject.java
|
Apache-2.0
|
public IterableSubject asList() {
if (actual == null) {
failWithoutActual(simpleFact("cannot perform assertions on the contents of a null array"));
return ignoreCheck().that(emptyList());
}
return checkNoNeedToDisplayBothValues("asList()").that(Bytes.asList(actual));
}
|
A subject for {@code byte[]}.
@author Kurt Alfred Kluever
|
asList
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/PrimitiveByteArraySubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/PrimitiveByteArraySubject.java
|
Apache-2.0
|
static Factory<PrimitiveByteArraySubject, byte[]> byteArrays() {
return PrimitiveByteArraySubject::new;
}
|
Checks that the actual array has the given length.
|
byteArrays
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/PrimitiveByteArraySubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/PrimitiveByteArraySubject.java
|
Apache-2.0
|
public IterableSubject asList() {
if (actual == null) {
failWithoutActual(simpleFact("cannot perform assertions on the contents of a null array"));
return ignoreCheck().that(emptyList());
}
return checkNoNeedToDisplayBothValues("asList()").that(Chars.asList(actual));
}
|
A subject for {@code char[]}.
@author Christian Gruber (cgruber@israfil.net)
|
asList
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/PrimitiveCharArraySubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/PrimitiveCharArraySubject.java
|
Apache-2.0
|
static Factory<PrimitiveCharArraySubject, char[]> charArrays() {
return PrimitiveCharArraySubject::new;
}
|
Checks that the actual array has the given length.
|
charArrays
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/PrimitiveCharArraySubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/PrimitiveCharArraySubject.java
|
Apache-2.0
|
public DoubleArrayAsIterable usingTolerance(double tolerance) {
if (actual == null) {
failWithoutActual(simpleFact("cannot perform assertions on the contents of a null array"));
return ignoreCheck().that(new double[0]).usingTolerance(tolerance);
}
return DoubleArrayAsIterable.create(tolerance(tolerance), iterableSubject(actual));
}
|
Starts a method chain for a check in which the actual values (i.e. the elements of the array
under test) are compared to expected elements using a {@link Correspondence} which considers
values to correspond if they are finite values within {@code tolerance} of each other. The
check is actually executed by continuing the method chain. For example:
<pre>{@code
assertThat(actualDoubleArray).usingTolerance(1.0e-5).contains(3.14159);
}</pre>
<ul>
<li>It does not consider values to correspond if either value is infinite or NaN.
<li>It considers {@code -0.0} to be within any tolerance of {@code 0.0}.
<li>The expected values provided later in the chain will be {@link Number} instances which
will be converted to doubles, which may result in a loss of precision for some numeric
types.
<li>The subsequent methods in the chain may throw a {@link NullPointerException} if any
expected {@link Number} instance is null.
</ul>
@param tolerance an inclusive upper bound on the difference between the double values of the
actual and expected numbers, which must be a non-negative finite value, i.e. not {@link
Double#NaN}, {@link Double#POSITIVE_INFINITY}, or negative, including {@code -0.0}
|
usingTolerance
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/PrimitiveDoubleArraySubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/PrimitiveDoubleArraySubject.java
|
Apache-2.0
|
private static double checkedToDouble(Number expected) {
checkNotNull(expected);
checkArgument(
expected instanceof Double
|| expected instanceof Float
|| expected instanceof Integer
|| expected instanceof Long,
"Expected value in assertion using exact double equality was of unsupported type %s "
+ "(it may not have an exact double representation)",
expected.getClass());
if (expected instanceof Long) {
checkArgument(
Math.abs((Long) expected) <= 1L << 53,
"Expected value %s in assertion using exact double equality was a long with an absolute "
+ "value greater than 2^52 which has no exact double representation",
expected);
}
return expected.doubleValue();
}
|
Starts a method chain for a check in which the actual values (i.e. the elements of the array
under test) are compared to expected elements using a {@link Correspondence} which considers
values to correspond if they are finite values within {@code tolerance} of each other. The
check is actually executed by continuing the method chain. For example:
<pre>{@code
assertThat(actualDoubleArray).usingTolerance(1.0e-5).contains(3.14159);
}</pre>
<ul>
<li>It does not consider values to correspond if either value is infinite or NaN.
<li>It considers {@code -0.0} to be within any tolerance of {@code 0.0}.
<li>The expected values provided later in the chain will be {@link Number} instances which
will be converted to doubles, which may result in a loss of precision for some numeric
types.
<li>The subsequent methods in the chain may throw a {@link NullPointerException} if any
expected {@link Number} instance is null.
</ul>
@param tolerance an inclusive upper bound on the difference between the double values of the
actual and expected numbers, which must be a non-negative finite value, i.e. not {@link
Double#NaN}, {@link Double#POSITIVE_INFINITY}, or negative, including {@code -0.0}
|
checkedToDouble
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/PrimitiveDoubleArraySubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/PrimitiveDoubleArraySubject.java
|
Apache-2.0
|
public DoubleArrayAsIterable usingExactEquality() {
if (actual == null) {
failWithoutActual(simpleFact("cannot perform assertions on the contents of a null array"));
return ignoreCheck().that(new double[0]).usingExactEquality();
}
return DoubleArrayAsIterable.create(EXACT_EQUALITY_CORRESPONDENCE, iterableSubject(actual));
}
|
Starts a method chain for a check in which the actual values (i.e. the elements of the array
under test) are compared to expected elements using a {@link Correspondence} which considers
values to correspond if they are exactly equal, with equality defined by {@link Double#equals}.
This method is <i>not</i> recommended when the code under test is doing any kind of arithmetic:
use {@link #usingTolerance} with a suitable tolerance in that case. (Remember that the exact
result of floating point arithmetic is sensitive to apparently trivial changes such as
replacing {@code (a + b) + c} with {@code a + (b + c)}, and that unless {@code strictfp} is in
force even the result of {@code (a + b) + c} is sensitive to the JVM's choice of precision for
the intermediate result.) This method is recommended when the code under test is specified as
either copying a value without modification from its input or returning a well-defined literal
or constant value. The check is actually executed by continuing the method chain. For example:
<pre>{@code
assertThat(actualDoubleArray).usingExactEquality().contains(3.14159);
}</pre>
<p>For convenience, some subsequent methods accept expected values as {@link Number} instances.
These numbers must be either of type {@link Double}, {@link Float}, {@link Integer}, or {@link
Long}, and if they are {@link Long} then their absolute values must not exceed 2^53 which is
just over 9e15. (This restriction ensures that the expected values have exact {@link Double}
representations: using exact equality makes no sense if they do not.)
<ul>
<li>It considers {@link Double#POSITIVE_INFINITY}, {@link Double#NEGATIVE_INFINITY}, and
{@link Double#NaN} to be equal to themselves (contrast with {@code usingTolerance(0.0)}
which does not).
<li>It does <i>not</i> consider {@code -0.0} to be equal to {@code 0.0} (contrast with {@code
usingTolerance(0.0)} which does).
<li>The subsequent methods in the chain may throw a {@link NullPointerException} if any
expected {@link Double} instance is null.
</ul>
|
usingExactEquality
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/PrimitiveDoubleArraySubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/PrimitiveDoubleArraySubject.java
|
Apache-2.0
|
public FloatArrayAsIterable usingTolerance(double tolerance) {
if (actual == null) {
failWithoutActual(simpleFact("cannot perform assertions on the contents of a null array"));
return ignoreCheck().that(new float[0]).usingTolerance(tolerance);
}
return FloatArrayAsIterable.create(tolerance(tolerance), iterableSubject(actual));
}
|
Starts a method chain for a check in which the actual values (i.e. the elements of the array
under test) are compared to expected elements using a {@link Correspondence} which considers
values to correspond if they are finite values within {@code tolerance} of each other. The
check is actually executed by continuing the method chain. For example:
<pre>{@code
assertThat(actualFloatArray).usingTolerance(1.0e-5f).contains(3.14159f);
}</pre>
<ul>
<li>It does not consider values to correspond if either value is infinite or NaN.
<li>It considers {@code -0.0f} to be within any tolerance of {@code 0.0f}.
<li>The expected values provided later in the chain will be {@link Number} instances which
will be converted to floats, which may result in a loss of precision for some numeric
types.
<li>The subsequent methods in the chain may throw a {@link NullPointerException} if any
expected {@link Number} instance is null.
</ul>
@param tolerance an inclusive upper bound on the difference between the float values of the
actual and expected numbers, which must be a non-negative finite value, i.e. not {@link
Float#NaN}, {@link Float#POSITIVE_INFINITY}, or negative, including {@code -0.0f}
|
usingTolerance
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/PrimitiveFloatArraySubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/PrimitiveFloatArraySubject.java
|
Apache-2.0
|
private static float checkedToFloat(Number expected) {
checkNotNull(expected);
checkArgument(
!(expected instanceof Double),
"Expected value in assertion using exact float equality was a double, which is not "
+ "supported as a double may not have an exact float representation");
checkArgument(
expected instanceof Float || expected instanceof Integer || expected instanceof Long,
"Expected value in assertion using exact float equality was of unsupported type %s "
+ "(it may not have an exact float representation)",
expected.getClass());
if (expected instanceof Integer) {
checkArgument(
Math.abs((Integer) expected) <= 1 << 24,
"Expected value %s in assertion using exact float equality was an int with an absolute "
+ "value greater than 2^24 which has no exact float representation",
expected);
}
if (expected instanceof Long) {
checkArgument(
Math.abs((Long) expected) <= 1L << 24,
"Expected value %s in assertion using exact float equality was a long with an absolute "
+ "value greater than 2^24 which has no exact float representation",
expected);
}
return expected.floatValue();
}
|
Starts a method chain for a check in which the actual values (i.e. the elements of the array
under test) are compared to expected elements using a {@link Correspondence} which considers
values to correspond if they are finite values within {@code tolerance} of each other. The
check is actually executed by continuing the method chain. For example:
<pre>{@code
assertThat(actualFloatArray).usingTolerance(1.0e-5f).contains(3.14159f);
}</pre>
<ul>
<li>It does not consider values to correspond if either value is infinite or NaN.
<li>It considers {@code -0.0f} to be within any tolerance of {@code 0.0f}.
<li>The expected values provided later in the chain will be {@link Number} instances which
will be converted to floats, which may result in a loss of precision for some numeric
types.
<li>The subsequent methods in the chain may throw a {@link NullPointerException} if any
expected {@link Number} instance is null.
</ul>
@param tolerance an inclusive upper bound on the difference between the float values of the
actual and expected numbers, which must be a non-negative finite value, i.e. not {@link
Float#NaN}, {@link Float#POSITIVE_INFINITY}, or negative, including {@code -0.0f}
|
checkedToFloat
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/PrimitiveFloatArraySubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/PrimitiveFloatArraySubject.java
|
Apache-2.0
|
public FloatArrayAsIterable usingExactEquality() {
if (actual == null) {
failWithoutActual(simpleFact("cannot perform assertions on the contents of a null array"));
return ignoreCheck().that(new float[0]).usingExactEquality();
}
return FloatArrayAsIterable.create(EXACT_EQUALITY_CORRESPONDENCE, iterableSubject(actual));
}
|
Starts a method chain for a check in which the actual values (i.e. the elements of the array
under test) are compared to expected elements using a {@link Correspondence} which considers
values to correspond if they are exactly equal, with equality defined by {@link Float#equals}.
This method is <i>not</i> recommended when the code under test is doing any kind of arithmetic:
use {@link #usingTolerance} with a suitable tolerance in that case. (Remember that the exact
result of floating point arithmetic is sensitive to apparently trivial changes such as
replacing {@code (a + b) + c} with {@code a + (b + c)}, and that unless {@code strictfp} is in
force even the result of {@code (a + b) + c} is sensitive to the JVM's choice of precision for
the intermediate result.) This method is recommended when the code under test is specified as
either copying a value without modification from its input or returning a well-defined literal
or constant value. The check is actually executed by continuing the method chain. For example:
<pre>{@code
assertThat(actualFloatArray).usingExactEquality().contains(3.14159f);
}</pre>
<p>For convenience, some subsequent methods accept expected values as {@link Number} instances.
These numbers must be either of type {@link Float}, {@link Integer}, or {@link Long}, and if
they are {@link Integer} or {@link Long} then their absolute values must not exceed 2^24 which
is 16,777,216. (This restriction ensures that the expected values have exact {@link Float}
representations: using exact equality makes no sense if they do not.)
<ul>
<li>It considers {@link Float#POSITIVE_INFINITY}, {@link Float#NEGATIVE_INFINITY}, and {@link
Float#NaN} to be equal to themselves (contrast with {@code usingTolerance(0.0)} which
does not).
<li>It does <i>not</i> consider {@code -0.0f} to be equal to {@code 0.0f} (contrast with
{@code usingTolerance(0.0)} which does).
<li>The subsequent methods in the chain may throw a {@link NullPointerException} if any
expected {@link Float} instance is null.
</ul>
|
usingExactEquality
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/PrimitiveFloatArraySubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/PrimitiveFloatArraySubject.java
|
Apache-2.0
|
public IterableSubject asList() {
if (actual == null) {
failWithoutActual(simpleFact("cannot perform assertions on the contents of a null array"));
return ignoreCheck().that(emptyList());
}
return checkNoNeedToDisplayBothValues("asList()").that(Ints.asList(actual));
}
|
A subject for {@code int[]}.
@author Christian Gruber (cgruber@israfil.net)
|
asList
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/PrimitiveIntArraySubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/PrimitiveIntArraySubject.java
|
Apache-2.0
|
static Factory<PrimitiveIntArraySubject, int[]> intArrays() {
return PrimitiveIntArraySubject::new;
}
|
Checks that the actual array has the given length.
|
intArrays
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/PrimitiveIntArraySubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/PrimitiveIntArraySubject.java
|
Apache-2.0
|
public IterableSubject asList() {
if (actual == null) {
failWithoutActual(simpleFact("cannot perform assertions on the contents of a null array"));
return ignoreCheck().that(emptyList());
}
return checkNoNeedToDisplayBothValues("asList()").that(Longs.asList(actual));
}
|
A subject for {@code long[]}.
@author Christian Gruber (cgruber@israfil.net)
|
asList
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/PrimitiveLongArraySubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/PrimitiveLongArraySubject.java
|
Apache-2.0
|
static Factory<PrimitiveLongArraySubject, long[]> longArrays() {
return PrimitiveLongArraySubject::new;
}
|
Checks that the actual array has the given length.
|
longArrays
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/PrimitiveLongArraySubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/PrimitiveLongArraySubject.java
|
Apache-2.0
|
public IterableSubject asList() {
if (actual == null) {
failWithoutActual(simpleFact("cannot perform assertions on the contents of a null array"));
return ignoreCheck().that(emptyList());
}
return checkNoNeedToDisplayBothValues("asList()").that(Shorts.asList(actual));
}
|
A subject for {@code short[]}.
@author Christian Gruber (cgruber@israfil.net)
|
asList
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/PrimitiveShortArraySubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/PrimitiveShortArraySubject.java
|
Apache-2.0
|
static Factory<PrimitiveShortArraySubject, short[]> shortArrays() {
return PrimitiveShortArraySubject::new;
}
|
Checks that the actual array has the given length.
|
shortArrays
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/PrimitiveShortArraySubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/PrimitiveShortArraySubject.java
|
Apache-2.0
|
public SubjectT that(@Nullable ActualT actual) {
return subjectFactory.createSubject(metadata, actual);
}
|
In a fluent assertion chain, exposes the most common {@code that} method, which accepts a value
under test and returns a {@link Subject}.
<p>For more information about the methods in this class, see <a
href="https://truth.dev/faq#full-chain">this FAQ entry</a>.
<h3>For people extending Truth</h3>
<p>You won't extend this type. When you write a custom subject, see <a
href="https://truth.dev/extension">our doc on extensions</a>.
|
that
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/SimpleSubjectBuilder.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/SimpleSubjectBuilder.java
|
Apache-2.0
|
@CanIgnoreReturnValue
static Error sneakyThrow(Throwable t) {
throw new SneakyThrows<Error>().throwIt(t);
}
|
Throws {@code t} as if it were an unchecked {@link Throwable}.
<p>This method is useful primarily when we make a reflective call to a method with no {@code
throws} clause: Java forces us to handle an arbitrary {@link Throwable} from that method,
rather than just the {@link RuntimeException} or {@link Error} that should be possible. (And in
fact the static type of {@link Throwable} is occasionally justified even for a method with no
{@code throws} clause: Some such methods can in fact throw a checked exception (e.g., by
calling code written in Kotlin).) Typically, we want to let a {@link Throwable} from such a
method propagate untouched, just as we'd typically let it do for a non-reflective call.
However, we can't usually write {@code throw t;} when {@code t} has a static type of {@link
Throwable}. But we <i>can</i> write {@code sneakyThrow(t);}.
<p>We sometimes also use {@code sneakyThrow} for testing how our code responds to sneaky
checked exceptions.
@return never; this method declares a return type of {@link Error} only so that callers can
write {@code throw sneakyThrow(t);} to convince the compiler that the statement will always
throw.
|
sneakyThrow
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/SneakyThrows.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/SneakyThrows.java
|
Apache-2.0
|
@SuppressWarnings("unchecked") // not really safe, but that's the point
private Error throwIt(Throwable t) throws T {
throw (T) t;
}
|
Throws {@code t} as if it were an unchecked {@link Throwable}.
<p>This method is useful primarily when we make a reflective call to a method with no {@code
throws} clause: Java forces us to handle an arbitrary {@link Throwable} from that method,
rather than just the {@link RuntimeException} or {@link Error} that should be possible. (And in
fact the static type of {@link Throwable} is occasionally justified even for a method with no
{@code throws} clause: Some such methods can in fact throw a checked exception (e.g., by
calling code written in Kotlin).) Typically, we want to let a {@link Throwable} from such a
method propagate untouched, just as we'd typically let it do for a non-reflective call.
However, we can't usually write {@code throw t;} when {@code t} has a static type of {@link
Throwable}. But we <i>can</i> write {@code sneakyThrow(t);}.
<p>We sometimes also use {@code sneakyThrow} for testing how our code responds to sneaky
checked exceptions.
@return never; this method declares a return type of {@link Error} only so that callers can
write {@code throw sneakyThrow(t);} to convince the compiler that the statement will always
throw.
|
throwIt
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/SneakyThrows.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/SneakyThrows.java
|
Apache-2.0
|
static void cleanStackTrace(Throwable throwable) {
new StackTraceCleaner(throwable).clean(newIdentityHashSet());
}
|
<b>Call {@link Platform#cleanStackTrace} rather than calling this directly.</b>
<p>Cleans the stack trace on the given {@link Throwable}, replacing the original stack trace
stored on the instance (see {@link Throwable#setStackTrace(StackTraceElement[])}).
<p>Removes Truth stack frames from the top and JUnit framework and reflective call frames from
the bottom. Collapses the frames for various frameworks in the middle of the trace as well.
|
cleanStackTrace
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/StackTraceCleaner.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/StackTraceCleaner.java
|
Apache-2.0
|
@SuppressWarnings("SetAll") // not available under old versions of Android
private void clean(Set<Throwable> seenThrowables) {
// Stack trace cleaning can be disabled using a system property.
if (isStackTraceCleaningDisabled()) {
return;
}
/*
* TODO(cpovirk): Consider wrapping this whole method in a try-catch in case there are any bugs.
* It would be a shame for us to fail to report the "real" assertion failure because we're
* instead reporting a bug in Truth's cosmetic stack cleaning.
*/
// Prevent infinite recursion if there is a reference cycle between Throwables.
if (seenThrowables.contains(throwable)) {
return;
}
seenThrowables.add(throwable);
StackTraceElement[] stackFrames = throwable.getStackTrace();
int stackIndex = stackFrames.length - 1;
for (; stackIndex >= 0 && !isTruthEntrance(stackFrames[stackIndex]); stackIndex--) {
// Find first frame that enters Truth's world, and remove all above.
}
stackIndex += 1;
int endIndex = 0;
for (;
endIndex < stackFrames.length && !isJUnitIntrastructure(stackFrames[endIndex]);
endIndex++) {
// Find last frame of setup frames, and remove from there down.
}
/*
* If the stack trace would be empty, the error was probably thrown from "JUnit infrastructure"
* frames. Keep those frames around (though much of JUnit itself and related startup frames will
* still be removed by the remainder of this method) so that the user sees a useful stack.
*/
if (stackIndex >= endIndex) {
endIndex = stackFrames.length;
}
for (; stackIndex < endIndex; stackIndex++) {
StackTraceElementWrapper stackTraceElementWrapper =
new StackTraceElementWrapper(stackFrames[stackIndex]);
// Always keep frames that might be useful.
if (stackTraceElementWrapper.getStackFrameType() == StackFrameType.NEVER_REMOVE) {
endStreak();
cleanedStackTrace.add(stackTraceElementWrapper);
continue;
}
// Otherwise, process the current frame for collapsing
addToStreak(stackTraceElementWrapper);
lastStackFrameElementWrapper = stackTraceElementWrapper;
}
// Close out the streak on the bottom of the stack.
endStreak();
// Filter out testing framework and reflective calls from the bottom of the stack
ListIterator<StackTraceElementWrapper> iterator =
cleanedStackTrace.listIterator(cleanedStackTrace.size());
while (iterator.hasPrevious()) {
StackTraceElementWrapper stackTraceElementWrapper = iterator.previous();
if (stackTraceElementWrapper.getStackFrameType() == StackFrameType.TEST_FRAMEWORK
|| stackTraceElementWrapper.getStackFrameType() == StackFrameType.REFLECTION) {
iterator.remove();
} else {
break;
}
}
// Replace the stack trace on the Throwable with the cleaned one.
StackTraceElement[] result = new StackTraceElement[cleanedStackTrace.size()];
for (int i = 0; i < result.length; i++) {
result[i] = cleanedStackTrace.get(i).getStackTraceElement();
}
throwable.setStackTrace(result);
// Recurse on any related Throwables that are attached to this one
if (throwable.getCause() != null) {
new StackTraceCleaner(throwable.getCause()).clean(seenThrowables);
}
for (Throwable suppressed : throwable.getSuppressed()) {
new StackTraceCleaner(suppressed).clean(seenThrowables);
}
}
|
Cleans the stack trace on {@code throwable}, replacing the trace that was originally on it.
|
clean
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/StackTraceCleaner.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/StackTraceCleaner.java
|
Apache-2.0
|
private void addToStreak(StackTraceElementWrapper stackTraceElementWrapper) {
if (stackTraceElementWrapper.getStackFrameType() != currentStreakType) {
endStreak();
currentStreakType = stackTraceElementWrapper.getStackFrameType();
currentStreakLength = 1;
} else {
currentStreakLength++;
}
}
|
Either adds the given frame to the running streak or closes out the running streak and starts a
new one.
|
addToStreak
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/StackTraceCleaner.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/StackTraceCleaner.java
|
Apache-2.0
|
private void endStreak() {
if (currentStreakLength == 0) {
return;
}
if (currentStreakLength == 1) {
// A single frame isn't a streak. Just include the frame as-is in the result.
cleanedStackTrace.add(checkNotNull(lastStackFrameElementWrapper));
} else {
// Add a single frame to the result summarizing the streak of framework frames
cleanedStackTrace.add(
createStreakReplacementFrame(checkNotNull(currentStreakType), currentStreakLength));
}
clearStreak();
}
|
Ends the current streak, adding a summary frame to the result. Resets the streak counter.
|
endStreak
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/StackTraceCleaner.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/StackTraceCleaner.java
|
Apache-2.0
|
StackFrameType getStackFrameType() {
return stackFrameType;
}
|
Returns the type of this frame.
|
getStackFrameType
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/StackTraceCleaner.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/StackTraceCleaner.java
|
Apache-2.0
|
private static StackFrameType forClassName(String fullyQualifiedClassName) {
// Never remove the frames from a test class. These will probably be the frame of a failing
// assertion.
// TODO(cpovirk): This is really only for tests in Truth itself, so this doesn't matter yet,
// but.... If the Truth tests someday start calling into nested classes, we may want to add:
// || fullyQualifiedClassName.contains("Test$")
if (fullyQualifiedClassName.endsWith("Test")
&& !fullyQualifiedClassName.equals(
"androidx.test.internal.runner.junit3.NonLeakyTestSuite$NonLeakyTest")) {
return StackFrameType.NEVER_REMOVE;
}
for (StackFrameType stackFrameType : StackFrameType.values()) {
if (stackFrameType.belongsToType(fullyQualifiedClassName)) {
return stackFrameType;
}
}
return StackFrameType.NEVER_REMOVE;
}
|
Helper method to determine the frame type from the fully qualified class name.
|
forClassName
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/StackTraceCleaner.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/StackTraceCleaner.java
|
Apache-2.0
|
String getName() {
return name;
}
|
Returns the name of this frame type to display in the cleaned trace
|
getName
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/StackTraceCleaner.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/StackTraceCleaner.java
|
Apache-2.0
|
boolean belongsToType(String fullyQualifiedClassName) {
for (String prefix : prefixes) {
// TODO(cpovirk): Should we also check prefix + "$"?
if (fullyQualifiedClassName.equals(prefix)
|| fullyQualifiedClassName.startsWith(prefix + ".")) {
return true;
}
}
return false;
}
|
Returns true if the given frame belongs to this frame type based on the package and/or class
name of the frame.
|
belongsToType
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/StackTraceCleaner.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/StackTraceCleaner.java
|
Apache-2.0
|
private static boolean isStackTraceCleaningDisabled() {
// Reading system properties might be forbidden.
try {
return Boolean.parseBoolean(
System.getProperty("com.google.common.truth.disable_stack_trace_cleaning"));
} catch (SecurityException e) {
// Hope for the best.
return false;
// TODO(cpovirk): Log a warning? Or is that likely to trigger other violations?
}
}
|
Returns true if stack trace cleaning is explicitly disabled in a system property. This switch
is intended to be used when attempting to debug the frameworks which are collapsed or filtered
out of stack traces by the cleaner.
|
isStackTraceCleaningDisabled
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/StackTraceCleaner.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/StackTraceCleaner.java
|
Apache-2.0
|
public static StandardSubjectBuilder forCustomFailureStrategy(FailureStrategy failureStrategy) {
return new StandardSubjectBuilder(FailureMetadata.forFailureStrategy(failureStrategy));
}
|
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}.
|
forCustomFailureStrategy
|
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 <ComparableT extends Comparable<?>> ComparableSubject<ComparableT> that(
@Nullable ComparableT actual) {
return about(ComparableSubject.<ComparableT>comparables()).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 BigDecimalSubject that(@Nullable BigDecimal actual) {
return about(bigDecimals()).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 Subject that(@Nullable Object actual) {
return about(objects()).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
|
@GwtIncompatible("ClassSubject.java")
@J2ktIncompatible
public final ClassSubject that(@Nullable Class<?> actual) {
return about(classes()).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 ThrowableSubject that(@Nullable Throwable actual) {
return about(throwables()).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 LongSubject that(@Nullable Long actual) {
return about(longs()).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 DoubleSubject that(@Nullable Double actual) {
return about(doubles()).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 FloatSubject that(@Nullable Float actual) {
return about(floats()).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 IntegerSubject that(@Nullable Integer actual) {
return about(integers()).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 BooleanSubject that(@Nullable Boolean actual) {
return about(booleans()).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 StringSubject that(@Nullable String actual) {
return about(strings()).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 IterableSubject that(@Nullable Iterable<?> actual) {
return about(iterables()).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("AvoidObjectArrays")
public final <T extends @Nullable Object> ObjectArraySubject<T> that(T @Nullable [] actual) {
return about(ObjectArraySubject.<T>objectArrays()).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 PrimitiveBooleanArraySubject that(boolean @Nullable [] actual) {
return about(booleanArrays()).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 PrimitiveShortArraySubject that(short @Nullable [] actual) {
return about(shortArrays()).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
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.