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 void isLessThan(int other) {
// For discussion of this delegation, see isGreaterThan.
asDouble.isLessThan(other);
} | Checks that the actual value is less than {@code other}.
<p>To check that the actual value is less than <i>or equal to</i> {@code other}, use {@link
#isAtMost} . | isLessThan | java | google/truth | core/src/main/java/com/google/common/truth/FloatSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/FloatSubject.java | Apache-2.0 |
public void isAtMost(int other) {
// For discussion of this delegation, see isGreaterThan.
asDouble.isAtMost(other);
} | Checks that the actual value is less than or equal to {@code other}.
<p>To check that the actual value is <i>strictly</i> less than {@code other}, use {@link
#isLessThan}. | isAtMost | java | google/truth | core/src/main/java/com/google/common/truth/FloatSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/FloatSubject.java | Apache-2.0 |
public void isAtLeast(int other) {
// For discussion of this delegation, see isGreaterThan.
asDouble.isAtLeast(other);
} | Checks that the actual value is greater than or equal to {@code other}.
<p>To check that the actual value is <i>strictly</i> greater than {@code other}, use {@link
#isGreaterThan}. | isAtLeast | java | google/truth | core/src/main/java/com/google/common/truth/FloatSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/FloatSubject.java | Apache-2.0 |
static Factory<FloatSubject, Float> floats() {
return FloatSubject::new;
} | Checks that the actual value is greater than or equal to {@code other}.
<p>To check that the actual value is <i>strictly</i> greater than {@code other}, use {@link
#isGreaterThan}. | floats | java | google/truth | core/src/main/java/com/google/common/truth/FloatSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/FloatSubject.java | Apache-2.0 |
static <U, V> ImmutableBiMap<U, V> maximumCardinalityBipartiteMatching(Multimap<U, V> graph) {
return HopcroftKarp.overBipartiteGraph(graph).perform();
} | Finds a <a
href="https://en.wikipedia.org/wiki/Matching_(graph_theory)#In_unweighted_bipartite_graphs">
maximum cardinality matching of a bipartite graph</a>. The vertices of one part of the
bipartite graph are identified by objects of type {@code U} using object equality. The vertices
of the other part are similarly i... | maximumCardinalityBipartiteMatching | java | google/truth | core/src/main/java/com/google/common/truth/GraphMatching.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/GraphMatching.java | Apache-2.0 |
static <U, V> HopcroftKarp<U, V> overBipartiteGraph(Multimap<U, V> graph) {
return new HopcroftKarp<>(graph);
} | Factory method which returns an instance ready to perform the algorithm over the bipartite
graph described by the given multimap. | overBipartiteGraph | java | google/truth | core/src/main/java/com/google/common/truth/GraphMatching.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/GraphMatching.java | Apache-2.0 |
ImmutableBiMap<U, V> perform() {
BiMap<U, V> matching = HashBiMap.create();
while (true) {
// Perform the BFS as described below. This finds the length of the shortest augmenting path
// and a guide which locates all the augmenting paths of that length.
Map<U, Integer> layers = new H... | Performs the algorithm, and returns a bimap describing the matching found. | perform | java | google/truth | core/src/main/java/com/google/common/truth/GraphMatching.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/GraphMatching.java | Apache-2.0 |
private @Nullable Integer breadthFirstSearch(BiMap<U, V> matching, Map<U, Integer> layers) {
Queue<U> queue = new ArrayDeque<>();
Integer freeRhsVertexLayer = null;
// Enqueue all free LHS vertices and assign them to layer 1.
for (U lhs : graph.keySet()) {
if (!matching.containsKey(lhs)... | Performs the Breadth-First Search phase of the algorithm. Specifically, treats the bipartite
graph as a directed graph where every unmatched edge (i.e. every edge not in the current
matching) is directed from the LHS vertex to the RHS vertex and every matched edge is
directed from the RHS vertex to the LHS vertex, and ... | breadthFirstSearch | java | google/truth | core/src/main/java/com/google/common/truth/GraphMatching.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/GraphMatching.java | Apache-2.0 |
@CanIgnoreReturnValue
private boolean depthFirstSearch(
BiMap<U, V> matching, Map<U, Integer> layers, int freeRhsVertexLayer, U lhs) {
// Note that this differs from the method described in the text of the wikipedia article (at
// time of writing) in two ways. Firstly, we proceed from a free LHS... | Performs the Depth-First Search phase of the algorithm. The DFS is guided by the BFS phase,
i.e. it only uses paths which were used in the BFS. That means the steps in the DFS proceed
from an LHS vertex via an unmatched edge to an RHS vertex and from an RHS vertex via a
matched edge to an LHS vertex only if that LHS ve... | depthFirstSearch | java | google/truth | core/src/main/java/com/google/common/truth/GraphMatching.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/GraphMatching.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/GuavaOptionalSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/GuavaOptionalSubject.java | Apache-2.0 |
public void isAbsent() {
if (actual == null) {
failWithActual(simpleFact("expected absent optional"));
} else if (actual.isPresent()) {
failWithoutActual(
simpleFact("expected to be absent"), fact("but was present with value", actual.get()));
}
} | Checks that the actual {@link Optional} does not contain a value. | isAbsent | java | google/truth | core/src/main/java/com/google/common/truth/GuavaOptionalSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/GuavaOptionalSubject.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... | 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/GuavaOptionalSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/GuavaOptionalSubject.java | Apache-2.0 |
static Factory<GuavaOptionalSubject, Optional<?>> guavaOptionals() {
return GuavaOptionalSubject::new;
} | 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> | guavaOptionals | java | google/truth | core/src/main/java/com/google/common/truth/GuavaOptionalSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/GuavaOptionalSubject.java | Apache-2.0 |
@Deprecated
@Override
public boolean equals(@Nullable Object o) {
throw new UnsupportedOperationException(
"If you meant to compare ints, use .of(int) instead.");
} | @throws UnsupportedOperationException always
@deprecated {@link Object#equals(Object)} is not supported on TolerantIntegerComparison. If
you meant to compare ints, use {@link #of(int)} instead. | equals | java | google/truth | core/src/main/java/com/google/common/truth/IntegerSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IntegerSubject.java | Apache-2.0 |
@Deprecated
@Override
public int hashCode() {
throw new UnsupportedOperationException("Subject.hashCode() is not supported.");
} | @throws UnsupportedOperationException always
@deprecated {@link Object#hashCode()} is not supported on TolerantIntegerComparison | hashCode | java | google/truth | core/src/main/java/com/google/common/truth/IntegerSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IntegerSubject.java | Apache-2.0 |
static TolerantIntegerComparison create(IntegerComparer comparer) {
return new TolerantIntegerComparison(comparer);
} | @throws UnsupportedOperationException always
@deprecated {@link Object#hashCode()} is not supported on TolerantIntegerComparison | create | java | google/truth | core/src/main/java/com/google/common/truth/IntegerSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IntegerSubject.java | Apache-2.0 |
public TolerantIntegerComparison isWithin(int tolerance) {
return TolerantIntegerComparison.create(
other -> {
if (tolerance < 0) {
failWithoutActual(
simpleFact(
"could not perform approximate-equality check because tolerance is negative"),
... | Prepares for a check that the actual value is a number within the given tolerance of an
expected value that will be provided in the next call in the fluent chain.
@param tolerance an inclusive upper bound on the difference between the actual value and
expected value allowed by the check, which must be a non-negati... | isWithin | java | google/truth | core/src/main/java/com/google/common/truth/IntegerSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IntegerSubject.java | Apache-2.0 |
public TolerantIntegerComparison isNotWithin(int tolerance) {
return TolerantIntegerComparison.create(
other -> {
if (tolerance < 0) {
failWithoutActual(
simpleFact(
"could not perform approximate-equality check because tolerance is negative"),
... | Prepares for a check that the actual value is a number not within the given tolerance of an
expected value that will be provided in the next call in the fluent chain.
@param tolerance an exclusive lower bound on the difference between the actual value and
expected value allowed by the check, which must be a non-ne... | isNotWithin | java | google/truth | core/src/main/java/com/google/common/truth/IntegerSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IntegerSubject.java | Apache-2.0 |
@Override
@Deprecated
public final void isEquivalentAccordingToCompareTo(@Nullable Integer other) {
super.isEquivalentAccordingToCompareTo(other);
} | @deprecated Use {@link #isEqualTo} instead. Integer comparison is consistent with equality. | isEquivalentAccordingToCompareTo | java | google/truth | core/src/main/java/com/google/common/truth/IntegerSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IntegerSubject.java | Apache-2.0 |
static Factory<IntegerSubject, Integer> integers() {
return IntegerSubject::new;
} | @deprecated Use {@link #isEqualTo} instead. Integer comparison is consistent with equality. | integers | java | google/truth | core/src/main/java/com/google/common/truth/IntegerSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IntegerSubject.java | Apache-2.0 |
@Deprecated
@SuppressWarnings("InlineMeSuggester") // We want users to remove the surrounding call entirely.
public static Factory<IntStreamSubject, IntStream> intStreams() {
return IntStreamSubject::new;
} | Obsolete factory instance. This factory was previously necessary for assertions like {@code
assertWithMessage(...).about(intStreams()).that(stream)....}. Now, you can perform assertions
like that without the {@code about(...)} call.
@deprecated Instead of {@code about(intStreams()).that(...)}, use just {@code that(...... | intStreams | java | google/truth | core/src/main/java/com/google/common/truth/IntStreamSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IntStreamSubject.java | Apache-2.0 |
@SuppressWarnings("GoodTime") // false positive; b/122617528
public void containsAnyOf(int first, int second, int... rest) {
checkThatContentsList().containsAnyOf(first, second, box(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/IntStreamSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IntStreamSubject.java | Apache-2.0 |
@SuppressWarnings("GoodTime") // false positive; b/122617528
@CanIgnoreReturnValue
public Ordered containsAtLeast(int first, int second, int... rest) {
return checkThatContentsList().containsAtLeast(first, second, box(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... | containsAtLeast | java | google/truth | core/src/main/java/com/google/common/truth/IntStreamSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IntStreamSubject.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... | containsAtLeastElementsIn | java | google/truth | core/src/main/java/com/google/common/truth/IntStreamSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IntStreamSubject.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, ma... | containsExactlyElementsIn | java | google/truth | core/src/main/java/com/google/common/truth/IntStreamSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IntStreamSubject.java | Apache-2.0 |
@SuppressWarnings("GoodTime") // false positive; b/122617528
public void containsNoneOf(int first, int second, int... rest) {
checkThatContentsList().containsNoneOf(first, second, box(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/IntStreamSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IntStreamSubject.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/IntStreamSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IntStreamSubject.java | Apache-2.0 |
private static Supplier<@Nullable List<?>> listCollector(@Nullable IntStream actual) {
return () -> actual == null ? null : actual.boxed().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/IntStreamSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IntStreamSubject.java | Apache-2.0 |
private static Object[] box(int[] rest) {
return IntStream.of(rest).boxed().toArray(Integer[]::new);
} | Be careful with using this, as documented on {@link Subject#substituteCheck}. | box | java | google/truth | core/src/main/java/com/google/common/truth/IntStreamSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IntStreamSubject.java | Apache-2.0 |
@Override
protected String actualCustomStringRepresentation() {
if (actual != null) {
// Check the value of iterable.toString() against the default Object.toString() implementation
// so that we can avoid things like
// "com.google.common.graph.Traverser$GraphTraverser$1@5e316c74"
String o... | Constructor for use by subclasses. If you want to create an instance of this class itself, call
{@link Subject#check(String, Object...) check(...)}{@code .that(actual)}. | actualCustomStringRepresentation | java | google/truth | core/src/main/java/com/google/common/truth/IterableSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java | Apache-2.0 |
@Override
public void isEqualTo(@Nullable Object expected) {
@SuppressWarnings("UndefinedEquals") // method contract requires testing iterables for equality
boolean equal = Objects.equals(actual, expected);
if (equal) {
return;
}
// Fail but with a more descriptive message:
if (actual ... | Constructor for use by subclasses. If you want to create an instance of this class itself, call
{@link Subject#check(String, Object...) check(...)}{@code .that(actual)}. | isEqualTo | java | google/truth | core/src/main/java/com/google/common/truth/IterableSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java | Apache-2.0 |
public final void isEmpty() {
if (!Iterables.isEmpty(checkNotNull(actual))) {
failWithActual(simpleFact("expected to be empty"));
}
} | Checks that the actual iterable is empty. | isEmpty | java | google/truth | core/src/main/java/com/google/common/truth/IterableSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java | Apache-2.0 |
public final void isNotEmpty() {
if (Iterables.isEmpty(checkNotNull(actual))) {
failWithoutActual(simpleFact("expected not to be empty"));
}
} | Checks that the actual iterable is not empty. | isNotEmpty | java | google/truth | core/src/main/java/com/google/common/truth/IterableSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java | Apache-2.0 |
public final void hasSize(int expectedSize) {
checkArgument(expectedSize >= 0, "expectedSize(%s) must be >= 0", expectedSize);
int actualSize = size(checkNotNull(actual));
check("size()").that(actualSize).isEqualTo(expectedSize);
} | Checks that the actual iterable has the given size. | hasSize | java | google/truth | core/src/main/java/com/google/common/truth/IterableSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java | Apache-2.0 |
public final void contains(@Nullable Object element) {
if (!Iterables.contains(checkNotNull(actual), element)) {
List<@Nullable Object> elementList = asList(element);
if (hasMatchingToStringPair(actual, elementList)) {
failWithoutActual(
fact("expected to contain", element),
... | Checks that the actual iterable contains the supplied item. | contains | java | google/truth | core/src/main/java/com/google/common/truth/IterableSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java | Apache-2.0 |
public final void doesNotContain(@Nullable Object element) {
if (Iterables.contains(checkNotNull(actual), element)) {
failWithActual("expected not to contain", element);
}
} | Checks that the actual iterable does not contain the supplied item. | doesNotContain | java | google/truth | core/src/main/java/com/google/common/truth/IterableSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java | Apache-2.0 |
public final void containsNoDuplicates() {
List<Multiset.Entry<?>> duplicates = new ArrayList<>();
for (Multiset.Entry<?> entry : LinkedHashMultiset.create(checkNotNull(actual)).entrySet()) {
if (entry.getCount() > 1) {
duplicates.add(entry);
}
}
if (!duplicates.isEmpty()) {
fa... | Checks that the actual iterable does not contain duplicate elements. | containsNoDuplicates | java | google/truth | core/src/main/java/com/google/common/truth/IterableSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java | Apache-2.0 |
public final void containsAnyOf(
@Nullable Object first, @Nullable Object second, @Nullable Object @Nullable ... rest) {
containsAnyIn(accumulate(first, second, rest));
} | Checks that the actual iterable contains at least one of the provided objects. | containsAnyOf | java | google/truth | core/src/main/java/com/google/common/truth/IterableSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java | Apache-2.0 |
public final void containsAnyIn(@Nullable Iterable<?> expected) {
checkNotNull(expected);
Collection<?> actual = iterableToCollection(checkNotNull(this.actual));
for (Object item : expected) {
if (actual.contains(item)) {
return;
}
}
if (hasMatchingToStringPair(actual, expected))... | Checks that the actual iterable contains at least one of the objects contained in the provided
collection. | containsAnyIn | java | google/truth | core/src/main/java/com/google/common/truth/IterableSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java | Apache-2.0 |
@SuppressWarnings("AvoidObjectArrays")
public final void containsAnyIn(@Nullable Object[] expected) {
containsAnyIn(asList(expected));
} | Checks that the actual iterable contains at least one of the objects contained in the provided
array. | containsAnyIn | java | google/truth | core/src/main/java/com/google/common/truth/IterableSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java | Apache-2.0 |
@CanIgnoreReturnValue
public final Ordered containsAtLeast(
@Nullable Object firstExpected,
@Nullable Object secondExpected,
@Nullable Object @Nullable ... restOfExpected) {
return containsAtLeastElementsIn(accumulate(firstExpected, secondExpected, restOfExpected));
} | Checks that the actual iterable contains at least all the expected elements. If an element
appears more than once in the expected elements to this call 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()}... | containsAtLeast | java | google/truth | core/src/main/java/com/google/common/truth/IterableSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java | Apache-2.0 |
@SuppressWarnings("BuilderCollapser")
@CanIgnoreReturnValue
public final Ordered containsAtLeastElementsIn(@Nullable Iterable<?> expectedIterable) {
List<?> actual = Lists.newLinkedList(checkNotNull(this.actual));
Collection<?> expected = iterableToCollection(expectedIterable);
List<@Nullable Object> m... | Checks that the actual iterable contains at least all the expected elements. If an element
appears more than once in the expected 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 objec... | containsAtLeastElementsIn | java | google/truth | core/src/main/java/com/google/common/truth/IterableSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java | Apache-2.0 |
@CanIgnoreReturnValue
@SuppressWarnings("AvoidObjectArrays")
public final Ordered containsAtLeastElementsIn(@Nullable Object[] expected) {
return containsAtLeastElementsIn(asList(expected));
} | Checks that the actual iterable contains at least all the expected elements. If an element
appears more than once in the expected 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 objec... | containsAtLeastElementsIn | java | google/truth | core/src/main/java/com/google/common/truth/IterableSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java | Apache-2.0 |
private Ordered failAtLeast(Collection<?> expected, Collection<?> missingRawObjects) {
List<?> nearMissRawObjects =
retainMatchingToString(checkNotNull(actual), /* itemsToCheck= */ missingRawObjects);
ImmutableList.Builder<Fact> facts = ImmutableList.builder();
facts.addAll(
makeElementFact... | Checks that the actual iterable contains at least all the expected elements. If an element
appears more than once in the expected 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 objec... | failAtLeast | java | google/truth | core/src/main/java/com/google/common/truth/IterableSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java | Apache-2.0 |
private static void moveElements(
List<?> input, Collection<@Nullable Object> output, int maxElements) {
for (int i = 0; i < maxElements; i++) {
output.add(input.remove(0));
}
} | Removes at most the given number of available elements from the input list and adds them to the
given output collection. | moveElements | java | google/truth | core/src/main/java/com/google/common/truth/IterableSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java | Apache-2.0 |
@CanIgnoreReturnValue
public final Ordered containsExactly(@Nullable Object @Nullable ... expected) {
List<@Nullable Object> expectedAsList =
expected == null ? asList((@Nullable Object) null) : asList(expected);
return containsExactlyElementsIn(
expectedAsList,
expected != null && exp... | Checks that the actual iterable contains exactly the provided objects.
<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
iterable.
<p>To also test that the contents appear in the given ord... | containsExactly | java | google/truth | core/src/main/java/com/google/common/truth/IterableSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java | Apache-2.0 |
@CanIgnoreReturnValue
public final Ordered containsExactlyElementsIn(@Nullable Iterable<?> expected) {
return containsExactlyElementsIn(expected, /* addElementsInWarning= */ false);
} | Checks that the actual iterable contains exactly the provided objects.
<p>Multiplicity is respected. For example, an object duplicated exactly 3 times in the {@code
Iterable} parameter asserts that the object must likewise be duplicated exactly 3 times in the
actual iterable.
<p>To also test that the contents appear ... | containsExactlyElementsIn | java | google/truth | core/src/main/java/com/google/common/truth/IterableSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java | Apache-2.0 |
@CanIgnoreReturnValue
@SuppressWarnings({
"AvoidObjectArrays",
"ContainsExactlyElementsInUnnecessaryWrapperAroundArray",
"ContainsExactlyElementsInWithVarArgsToExactly"
})
public final Ordered containsExactlyElementsIn(@Nullable Object @Nullable [] expected) {
return containsExactlyElementsIn(asLi... | Checks that the actual iterable contains exactly the provided objects.
<p>Multiplicity is respected. For example, an object duplicated exactly 3 times in the array
parameter asserts that the object must likewise be duplicated exactly 3 times in the actual
iterable.
<p>To also test that the contents appear in the give... | containsExactlyElementsIn | java | google/truth | core/src/main/java/com/google/common/truth/IterableSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java | Apache-2.0 |
private Ordered containsExactlyElementsIn(
@Nullable Iterable<?> required, boolean addElementsInWarning) {
checkNotNull(required);
Iterator<?> actualIter = checkNotNull(actual).iterator();
Iterator<?> requiredIter = required.iterator();
if (!requiredIter.hasNext()) {
if (actualIter.hasNext(... | Checks that the actual iterable contains exactly the provided objects.
<p>Multiplicity is respected. For example, an object duplicated exactly 3 times in the array
parameter asserts that the object must likewise be duplicated exactly 3 times in the actual
iterable.
<p>To also test that the contents appear in the give... | containsExactlyElementsIn | java | google/truth | core/src/main/java/com/google/common/truth/IterableSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java | Apache-2.0 |
private Ordered failExactly(
Iterable<?> required,
boolean addElementsInWarning,
Collection<?> missingRawObjects,
Collection<?> extraRawObjects) {
ImmutableList.Builder<Fact> facts = ImmutableList.builder();
facts.addAll(
makeElementFactsForBoth("missing", missingRawObjects, "une... | Checks that the actual iterable contains exactly the provided objects.
<p>Multiplicity is respected. For example, an object duplicated exactly 3 times in the array
parameter asserts that the object must likewise be duplicated exactly 3 times in the actual
iterable.
<p>To also test that the contents appear in the give... | failExactly | java | google/truth | core/src/main/java/com/google/common/truth/IterableSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java | Apache-2.0 |
private static ImmutableList<Fact> makeElementFactsForBoth(
String firstKey,
Collection<?> firstCollection,
String secondKey,
Collection<?> secondCollection) {
// TODO(kak): Possible enhancement: Include "[1 copy]" if the element does appear in
// the actual iterable but not enough times... | Checks that the actual iterable contains exactly the provided objects.
<p>Multiplicity is respected. For example, an object duplicated exactly 3 times in the array
parameter asserts that the object must likewise be duplicated exactly 3 times in the actual
iterable.
<p>To also test that the contents appear in the give... | makeElementFactsForBoth | java | google/truth | core/src/main/java/com/google/common/truth/IterableSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java | Apache-2.0 |
private static ImmutableList<Fact> makeElementFacts(
String label, DuplicateGroupedAndTyped elements, ElementFactGrouping grouping) {
if (elements.isEmpty()) {
return ImmutableList.of();
}
if (grouping == ALL_IN_ONE_FACT) {
return ImmutableList.of(fact(keyToGoWithElementsString(label, ele... | Returns a list of facts (zero, one, or many, depending on the number of elements and the
grouping policy) describing the given missing, unexpected, or near-miss elements. | makeElementFacts | java | google/truth | core/src/main/java/com/google/common/truth/IterableSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java | Apache-2.0 |
private static String keyToGoWithElementsString(String label, DuplicateGroupedAndTyped elements) {
/*
* elements.toString(), which the caller is going to use, includes the homogeneous type (if
* any), so we don't want to include it here. (And it's better to have it in the value, rather
* than in the ... | Returns a list of facts (zero, one, or many, depending on the number of elements and the
grouping policy) describing the given missing, unexpected, or near-miss elements. | keyToGoWithElementsString | java | google/truth | core/src/main/java/com/google/common/truth/IterableSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java | Apache-2.0 |
private static String keyToServeAsHeader(String label, DuplicateGroupedAndTyped elements) {
/*
* The caller of this method outputs each individual element manually (as opposed to calling
* elements.toString()), so the homogeneous type isn't present unless we add it. Fortunately, we
* can add it here ... | Returns a list of facts (zero, one, or many, depending on the number of elements and the
grouping policy) describing the given missing, unexpected, or near-miss elements. | keyToServeAsHeader | java | google/truth | core/src/main/java/com/google/common/truth/IterableSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java | Apache-2.0 |
private static String numberString(int n, int count) {
return count == 1 ? lenientFormat("#%s", n) : lenientFormat("#%s [%s copies]", n, count);
} | Returns a list of facts (zero, one, or many, depending on the number of elements and the
grouping policy) describing the given missing, unexpected, or near-miss elements. | numberString | java | google/truth | core/src/main/java/com/google/common/truth/IterableSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java | Apache-2.0 |
private static ElementFactGrouping pickGrouping(
Iterable<Multiset.Entry<?>> first, Iterable<Multiset.Entry<?>> second) {
boolean firstHasMultiple = hasMultiple(first);
boolean secondHasMultiple = hasMultiple(second);
if ((firstHasMultiple || secondHasMultiple) && anyContainsCommaOrNewline(first, seco... | Returns a list of facts (zero, one, or many, depending on the number of elements and the
grouping policy) describing the given missing, unexpected, or near-miss elements. | pickGrouping | java | google/truth | core/src/main/java/com/google/common/truth/IterableSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java | Apache-2.0 |
private static boolean anyContainsCommaOrNewline(Iterable<Multiset.Entry<?>>... lists) {
for (Multiset.Entry<?> entry : concat(lists)) {
String s = String.valueOf(entry.getElement());
if (s.contains("\n") || s.contains(",")) {
return true;
}
}
return false;
} | Returns a list of facts (zero, one, or many, depending on the number of elements and the
grouping policy) describing the given missing, unexpected, or near-miss elements. | anyContainsCommaOrNewline | java | google/truth | core/src/main/java/com/google/common/truth/IterableSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java | Apache-2.0 |
private static boolean hasMultiple(Iterable<Multiset.Entry<?>> entries) {
int totalCount = 0;
for (Multiset.Entry<?> entry : entries) {
totalCount += entry.getCount();
if (totalCount > 1) {
return true;
}
}
return false;
} | Returns a list of facts (zero, one, or many, depending on the number of elements and the
grouping policy) describing the given missing, unexpected, or near-miss elements. | hasMultiple | java | google/truth | core/src/main/java/com/google/common/truth/IterableSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java | Apache-2.0 |
private static boolean containsEmptyOrLong(Iterable<Multiset.Entry<?>> entries) {
int totalLength = 0;
for (Multiset.Entry<?> entry : entries) {
String s = entryString(entry);
if (s.isEmpty()) {
return true;
}
totalLength += s.length();
}
return totalLength > 200;
} | Returns a list of facts (zero, one, or many, depending on the number of elements and the
grouping policy) describing the given missing, unexpected, or near-miss elements. | containsEmptyOrLong | java | google/truth | core/src/main/java/com/google/common/truth/IterableSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java | Apache-2.0 |
public final void containsNoneOf(
@Nullable Object firstExcluded,
@Nullable Object secondExcluded,
@Nullable Object @Nullable ... restOfExcluded) {
containsNoneIn(accumulate(firstExcluded, secondExcluded, restOfExcluded));
}
/**
* Checks that the actual iterable contains none of the elemen... | Checks that the actual iterable contains none of the excluded objects. | containsNoneOf | java | google/truth | core/src/main/java/com/google/common/truth/IterableSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java | Apache-2.0 |
@SuppressWarnings("AvoidObjectArrays")
public final void containsNoneIn(@Nullable Object[] excluded) {
containsNoneIn(asList(excluded));
} | Checks that the actual iterable contains none of the elements contained in the excluded array. | containsNoneIn | java | google/truth | core/src/main/java/com/google/common/truth/IterableSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java | Apache-2.0 |
@SuppressWarnings({"unchecked"})
public final void isInStrictOrder(Comparator<?> comparator) {
checkNotNull(comparator);
pairwiseCheck(
"expected to be in strict order",
(prev, next) -> ((Comparator<@Nullable Object>) comparator).compare(prev, next) < 0);
} | Checks that the actual iterable is strictly ordered, according to the given comparator.
Strictly ordered means that each element in the iterable is <i>strictly</i> greater than the
element that preceded it.
@throws ClassCastException if any pair of elements is not mutually Comparable | isInStrictOrder | java | google/truth | core/src/main/java/com/google/common/truth/IterableSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java | Apache-2.0 |
@SuppressWarnings({"unchecked"})
public final void isInOrder(Comparator<?> comparator) {
checkNotNull(comparator);
pairwiseCheck(
"expected to be in order",
(prev, next) -> ((Comparator<@Nullable Object>) comparator).compare(prev, next) <= 0);
} | Checks that the actual iterable is ordered, according to the given comparator. Ordered means
that each element in the iterable is greater than or equal to the element that preceded it.
@throws ClassCastException if any pair of elements is not mutually Comparable | isInOrder | java | google/truth | core/src/main/java/com/google/common/truth/IterableSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java | Apache-2.0 |
private void pairwiseCheck(String expectedFact, PairwiseChecker checker) {
Iterator<?> iterator = checkNotNull(actual).iterator();
if (iterator.hasNext()) {
Object prev = iterator.next();
while (iterator.hasNext()) {
Object next = iterator.next();
if (!checker.check(prev, next)) {
... | Checks that the actual iterable is ordered, according to the given comparator. Ordered means
that each element in the iterable is greater than or equal to the element that preceded it.
@throws ClassCastException if any pair of elements is not mutually Comparable | pairwiseCheck | java | google/truth | core/src/main/java/com/google/common/truth/IterableSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java | Apache-2.0 |
@Override
@Deprecated
public void isNoneOf(
@Nullable Object first, @Nullable Object second, @Nullable Object @Nullable ... rest) {
super.isNoneOf(first, second, rest);
} | @deprecated You probably meant to call {@link #containsNoneOf} instead. | isNoneOf | java | google/truth | core/src/main/java/com/google/common/truth/IterableSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java | Apache-2.0 |
@Override
@Deprecated
public void isNotIn(@Nullable Iterable<?> iterable) {
checkNotNull(iterable);
if (Iterables.contains(iterable, actual)) {
failWithActual("expected not to be any of", iterable);
}
List<@Nullable Object> nonIterables = new ArrayList<>();
for (Object element : iterable) ... | @deprecated You probably meant to call {@link #containsNoneIn} instead. | isNotIn | java | google/truth | core/src/main/java/com/google/common/truth/IterableSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java | Apache-2.0 |
private Fact fullContents() {
return fact("full contents", actualCustomStringRepresentationForPackageMembersToCall());
} | @deprecated You probably meant to call {@link #containsNoneIn} instead. | fullContents | java | google/truth | core/src/main/java/com/google/common/truth/IterableSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java | Apache-2.0 |
public <A extends @Nullable Object, E extends @Nullable Object>
UsingCorrespondence<A, E> comparingElementsUsing(
Correspondence<? super A, ? super E> correspondence) {
return new UsingCorrespondence<>(this, correspondence);
} | Starts a method chain for a check in which the actual elements (i.e. the elements of the {@link
Iterable} under test) are compared to expected elements using the given {@link Correspondence}.
The actual elements must be of type {@code A}, the expected elements must be of type {@code E}.
The check is actually executed b... | comparingElementsUsing | java | google/truth | core/src/main/java/com/google/common/truth/IterableSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java | Apache-2.0 |
public <T extends @Nullable Object> UsingCorrespondence<T, T> formattingDiffsUsing(
DiffFormatter<? super T, ? super T> formatter) {
return comparingElementsUsing(Correspondence.<T>equality().formattingDiffsUsing(formatter));
} | Starts a method chain for a check in which failure messages may use the given {@link
DiffFormatter} to describe the difference between an actual element (i.e. an element of the
{@link Iterable} under test) and the element it is expected to be equal to, but isn't. The
actual and expected elements must be of type {@code ... | formattingDiffsUsing | java | google/truth | core/src/main/java/com/google/common/truth/IterableSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java | Apache-2.0 |
@DoNotCall(
"UsingCorrespondence.equals() is not supported. Did you mean to call"
+ " containsExactlyElementsIn(expected) instead of equals(expected)?")
@Deprecated
@Override
public final boolean equals(@Nullable Object o) {
throw new UnsupportedOperationException(
"Using... | @throws UnsupportedOperationException always
@deprecated {@link Object#equals(Object)} is not supported on Truth subjects or intermediate
classes. If you are writing a test assertion (actual vs. expected), use methods liks
{@link #containsExactlyElementsIn(Iterable)} instead. | equals | java | google/truth | core/src/main/java/com/google/common/truth/IterableSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java | Apache-2.0 |
@DoNotCall("UsingCorrespondence.hashCode() is not supported.")
@Deprecated
@Override
public final int hashCode() {
throw new UnsupportedOperationException("UsingCorrespondence.hashCode() is not supported.");
} | @throws UnsupportedOperationException always
@deprecated {@link Object#hashCode()} is not supported on Truth types. | hashCode | java | google/truth | core/src/main/java/com/google/common/truth/IterableSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java | Apache-2.0 |
@Deprecated
@DoNotCall("UsingCorrespondence.toString() is not supported.")
@Override
public final String toString() {
throw new UnsupportedOperationException(
"UsingCorrespondence.toString() is not supported. Did you mean to call"
+ " assertThat(foo.toString()) instead of asser... | @throws UnsupportedOperationException always
@deprecated {@link Object#toString()} is not supported on Truth subjects. | toString | java | google/truth | core/src/main/java/com/google/common/truth/IterableSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java | Apache-2.0 |
public UsingCorrespondence<A, E> displayingDiffsPairedBy(Function<? super E, ?> keyFunction) {
@SuppressWarnings("unchecked") // throwing ClassCastException is the correct behaviour
Function<? super A, ?> actualKeyFunction = (Function<? super A, ?>) keyFunction;
return displayingDiffsPairedBy(actualKe... | Specifies a way to pair up unexpected and missing elements in the message when an assertion
fails. For example:
<pre>{@code
assertThat(actualRecords)
.comparingElementsUsing(RECORD_CORRESPONDENCE)
.displayingDiffsPairedBy(MyRecord::getId)
.containsExactlyElementsIn(expectedRecords);
}</pre>
<p><b>Importan... | displayingDiffsPairedBy | java | google/truth | core/src/main/java/com/google/common/truth/IterableSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java | Apache-2.0 |
public UsingCorrespondence<A, E> displayingDiffsPairedBy(
Function<? super A, ?> actualKeyFunction, Function<? super E, ?> expectedKeyFunction) {
return new UsingCorrespondence<>(
subject, correspondence, Pairer.create(actualKeyFunction, expectedKeyFunction));
} | Specifies a way to pair up unexpected and missing elements in the message when an assertion
fails. For example:
<pre>{@code
assertThat(actualFoos)
.comparingElementsUsing(FOO_BAR_CORRESPONDENCE)
.displayingDiffsPairedBy(Foo::getId, Bar::getFooId)
.containsExactlyElementsIn(expectedBar);
}</pre>
<p>On asse... | displayingDiffsPairedBy | java | google/truth | core/src/main/java/com/google/common/truth/IterableSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java | Apache-2.0 |
public void contains(E expected) {
Correspondence.ExceptionStore exceptions = Correspondence.ExceptionStore.forIterable();
for (A actual : getCastActual()) {
if (correspondence.safeCompare(actual, expected, exceptions)) {
// Found a match, but we still need to fail if we hit an exception a... | Checks that the actual iterable contains at least one element that corresponds to the given
expected element. | contains | java | google/truth | core/src/main/java/com/google/common/truth/IterableSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java | Apache-2.0 |
public void doesNotContain(E excluded) {
Correspondence.ExceptionStore exceptions = Correspondence.ExceptionStore.forIterable();
List<A> matchingElements = new ArrayList<>();
for (A actual : getCastActual()) {
if (correspondence.safeCompare(actual, excluded, exceptions)) {
matchingEl... | Checks that none of the actual elements correspond to the given element. | doesNotContain | java | google/truth | core/src/main/java/com/google/common/truth/IterableSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java | Apache-2.0 |
@SafeVarargs
@CanIgnoreReturnValue
public final Ordered containsExactly(@Nullable E @Nullable ... expected) {
return containsExactlyElementsIn(expected == null ? asList((E) null) : asList(expected));
} | Checks that actual iterable contains exactly elements that correspond to the expected
elements, i.e. that there is a 1:1 mapping between the actual elements and the expected
elements where each pair of elements correspond.
<p>To also test that the contents appear in the given order, make a call to {@code inOrder()}
on... | containsExactly | java | google/truth | core/src/main/java/com/google/common/truth/IterableSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java | Apache-2.0 |
@CanIgnoreReturnValue
public Ordered containsExactlyElementsIn(@Nullable Iterable<? extends E> expected) {
List<A> actualList = iterableToList(getCastActual());
List<? extends E> expectedList = iterableToList(checkNotNull(expected));
if (expectedList.isEmpty()) {
if (actualList.isEmpty())... | Checks that actual iterable contains exactly elements that correspond to the expected
elements, i.e. that there is a 1:1 mapping between the actual elements and the expected
elements where each pair of elements correspond.
<p>To also test that the contents appear in the given order, make a call to {@code inOrder()}
on... | containsExactlyElementsIn | java | google/truth | core/src/main/java/com/google/common/truth/IterableSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java | Apache-2.0 |
@CanIgnoreReturnValue
@SuppressWarnings("AvoidObjectArrays")
public Ordered containsExactlyElementsIn(E @Nullable [] expected) {
return containsExactlyElementsIn(asList(checkNotNull(expected)));
} | Checks that actual iterable contains exactly elements that correspond to the expected
elements, i.e. that there is a 1:1 mapping between the actual elements and the expected
elements where each pair of elements correspond.
<p>To also test that the contents appear in the given order, make a call to {@code inOrder()}
on... | containsExactlyElementsIn | java | google/truth | core/src/main/java/com/google/common/truth/IterableSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java | Apache-2.0 |
private boolean correspondInOrderExactly(
Iterator<? extends A> actual, Iterator<? extends E> expected) {
Correspondence.ExceptionStore exceptions = Correspondence.ExceptionStore.forIterable();
while (actual.hasNext() && expected.hasNext()) {
A actualElement = actual.next();
E expect... | Returns whether the actual and expected iterators have the same number of elements and, when
iterated pairwise, every pair of actual and expected values satisfies the correspondence.
Returns false if any comparison threw an exception. | correspondInOrderExactly | java | google/truth | core/src/main/java/com/google/common/truth/IterableSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java | Apache-2.0 |
private ImmutableSetMultimap<Integer, Integer> findCandidateMapping(
List<? extends A> actual,
List<? extends E> expected,
Correspondence.ExceptionStore exceptions) {
ImmutableSetMultimap.Builder<Integer, Integer> mapping = ImmutableSetMultimap.builder();
for (int actualIndex = 0; ac... | Given a list of actual elements and a list of expected elements, finds a many:many mapping
between actual and expected elements where a pair of elements maps if it satisfies the
correspondence. Returns this mapping as a multimap where the keys are indexes into the actual
list and the values are indexes into the expecte... | findCandidateMapping | java | google/truth | core/src/main/java/com/google/common/truth/IterableSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java | Apache-2.0 |
private boolean failIfCandidateMappingHasMissingOrExtra(
List<? extends A> actual,
List<? extends E> expected,
ImmutableSetMultimap<Integer, Integer> mapping,
Correspondence.ExceptionStore exceptions) {
List<? extends A> extra = findNotIndexed(actual, mapping.keySet());
List<... | Given a list of actual elements, a list of expected elements, and a many:many mapping between
actual and expected elements specified as a multimap of indexes into the actual list to
indexes into the expected list, checks that every actual element maps to at least one
expected element and vice versa, and fails if this i... | failIfCandidateMappingHasMissingOrExtra | java | google/truth | core/src/main/java/com/google/common/truth/IterableSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java | Apache-2.0 |
private ImmutableList<Fact> describeMissingOrExtra(
List<? extends E> missing,
List<? extends A> extra,
Correspondence.ExceptionStore exceptions) {
if (pairer != null) {
Pairing<A, E> pairing = pairer.pair(missing, extra, exceptions);
if (pairing != null) {
return... | Given a list of missing elements and a list of extra elements, at least one of which must be
non-empty, returns facts describing them. Exceptions from calling {@link
Correspondence#formatDiff} are stored in {@code exceptions}. | describeMissingOrExtra | java | google/truth | core/src/main/java/com/google/common/truth/IterableSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java | Apache-2.0 |
private ImmutableList<Fact> describeMissingOrExtraWithoutPairing(
List<? extends E> missing, List<? extends A> extra) {
return makeElementFactsForBoth("missing", missing, "unexpected", extra);
} | Given a list of missing elements and a list of extra elements, at least one of which must be
non-empty, returns facts describing them. Exceptions from calling {@link
Correspondence#formatDiff} are stored in {@code exceptions}. | describeMissingOrExtraWithoutPairing | java | google/truth | core/src/main/java/com/google/common/truth/IterableSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java | Apache-2.0 |
private ImmutableList<Fact> describeMissingOrExtraWithPairing(
Pairing<A, E> pairing, Correspondence.ExceptionStore exceptions) {
ImmutableList.Builder<Fact> facts = ImmutableList.builder();
for (Object key : pairing.pairedKeysToExpectedValues.keySet()) {
E missing = pairing.pairedKeysToExpe... | Given a list of missing elements and a list of extra elements, at least one of which must be
non-empty, returns facts describing them. Exceptions from calling {@link
Correspondence#formatDiff} are stored in {@code exceptions}. | describeMissingOrExtraWithPairing | java | google/truth | core/src/main/java/com/google/common/truth/IterableSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java | Apache-2.0 |
private ImmutableList<Fact> formatExtras(
String label,
E missing,
List<? extends A> extras,
Correspondence.ExceptionStore exceptions) {
List<@Nullable String> diffs = new ArrayList<>(extras.size());
boolean hasDiffs = false;
for (int i = 0; i < extras.size(); i++) {
... | Given a list of missing elements and a list of extra elements, at least one of which must be
non-empty, returns facts describing them. Exceptions from calling {@link
Correspondence#formatDiff} are stored in {@code exceptions}. | formatExtras | java | google/truth | core/src/main/java/com/google/common/truth/IterableSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java | Apache-2.0 |
private static <T extends @Nullable Object> List<T> findNotIndexed(
List<T> list, Set<Integer> indexes) {
if (indexes.size() == list.size()) {
// If there are as many distinct valid indexes are there are elements in the list then every
// index must be in there once.
return asList(... | Returns all the elements of the given list other than those with the given indexes. Assumes
that all the given indexes really are valid indexes into the list. | findNotIndexed | java | google/truth | core/src/main/java/com/google/common/truth/IterableSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java | Apache-2.0 |
private static ImmutableBiMap<Integer, Integer> findMaximalOneToOneMapping(
ImmutableMultimap<Integer, Integer> edges) {
/*
* Finding this 1:1 mapping is analogous to finding a maximum cardinality bipartite matching
* (https://en.wikipedia.org/wiki/Matching_(graph_theory)#In_unweighted_bipar... | Given a many:many mapping between actual elements and expected elements, finds a 1:1 mapping
which is the subset of that many:many mapping which includes the largest possible number of
elements. The input and output mappings are each described as a map or multimap where the
keys are indexes into the actual list and the... | findMaximalOneToOneMapping | java | google/truth | core/src/main/java/com/google/common/truth/IterableSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java | Apache-2.0 |
private boolean failIfOneToOneMappingHasMissingOrExtra(
List<? extends A> actual,
List<? extends E> expected,
BiMap<Integer, Integer> mapping,
Correspondence.ExceptionStore exceptions) {
List<? extends A> extra = findNotIndexed(actual, mapping.keySet());
List<? extends E> mis... | Given a list of actual elements, a list of expected elements, and a 1:1 mapping between
actual and expected elements specified as a bimap of indexes into the actual list to indexes
into the expected list, checks that every actual element maps to an expected element and vice
versa, and fails if this is not the case. Ret... | failIfOneToOneMappingHasMissingOrExtra | java | google/truth | core/src/main/java/com/google/common/truth/IterableSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java | Apache-2.0 |
@SafeVarargs
@CanIgnoreReturnValue
public final Ordered containsAtLeast(E first, E second, E @Nullable ... rest) {
return containsAtLeastElementsIn(accumulate(first, second, rest));
} | Checks that the actual iterable contains elements that correspond to all the expected
elements, i.e. that there is a 1:1 mapping between any subset of the actual elements and the
expected elements where each pair of elements correspond.
<p>To also test that the contents appear in the given order, make a call to {@code... | containsAtLeast | java | google/truth | core/src/main/java/com/google/common/truth/IterableSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java | Apache-2.0 |
@CanIgnoreReturnValue
public Ordered containsAtLeastElementsIn(Iterable<? extends E> expected) {
List<A> actualList = iterableToList(getCastActual());
List<? extends E> expectedList = iterableToList(expected);
// Check if the expected elements correspond in order to any subset of the actual elemen... | Checks that the actual iterable contains elements that correspond to all the expected
elements, i.e. that there is a 1:1 mapping between any subset of the actual elements and the
expected elements where each pair of elements correspond.
<p>To also test that the contents appear in the given order, make a call to {@code... | containsAtLeastElementsIn | java | google/truth | core/src/main/java/com/google/common/truth/IterableSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java | Apache-2.0 |
@CanIgnoreReturnValue
@SuppressWarnings("AvoidObjectArrays")
public Ordered containsAtLeastElementsIn(E[] expected) {
return containsAtLeastElementsIn(asList(expected));
} | Checks that the actual iterable contains elements that correspond to all the expected
elements, i.e. that there is a 1:1 mapping between any subset of the actual elements and the
expected elements where each pair of elements correspond.
<p>To also test that the contents appear in the given order, make a call to {@code... | containsAtLeastElementsIn | java | google/truth | core/src/main/java/com/google/common/truth/IterableSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java | Apache-2.0 |
private boolean correspondInOrderAllIn(
Iterator<? extends A> actual, Iterator<? extends E> expected) {
// We take a greedy approach here, iterating through the expected elements and pairing each
// with the first applicable actual element. This is fine for the in-order test, since there's
// ... | Returns whether all the elements of the expected iterator and any subset of the elements of
the actual iterator can be paired up in order, such that every pair of actual and expected
elements satisfies the correspondence. Returns false if any comparison threw an exception. | correspondInOrderAllIn | java | google/truth | core/src/main/java/com/google/common/truth/IterableSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java | Apache-2.0 |
private boolean findCorresponding(
Iterator<? extends A> actual, E expectedElement, Correspondence.ExceptionStore exceptions) {
while (actual.hasNext()) {
A actualElement = actual.next();
if (correspondence.safeCompare(actualElement, expectedElement, exceptions)) {
return true;
... | Advances the actual iterator looking for an element which corresponds to the expected
element. Returns whether or not it finds one. | findCorresponding | java | google/truth | core/src/main/java/com/google/common/truth/IterableSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java | Apache-2.0 |
private boolean failIfCandidateMappingHasMissing(
List<? extends A> actual,
List<? extends E> expected,
ImmutableSetMultimap<Integer, Integer> mapping,
Correspondence.ExceptionStore exceptions) {
List<? extends E> missing = findNotIndexed(expected, mapping.inverse().keySet());
... | Given a list of actual elements, a list of expected elements, and a many:many mapping between
actual and expected elements specified as a multimap of indexes into the actual list to
indexes into the expected list, checks that every expected element maps to at least one
actual element, and fails if this is not the case.... | failIfCandidateMappingHasMissing | java | google/truth | core/src/main/java/com/google/common/truth/IterableSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java | Apache-2.0 |
private ImmutableList<Fact> describeMissing(
List<? extends E> missing,
List<? extends A> extra,
Correspondence.ExceptionStore exceptions) {
if (pairer != null) {
Pairing<A, E> pairing = pairer.pair(missing, extra, exceptions);
if (pairing != null) {
return descri... | Given a list of missing elements, which must be non-empty, and a list of extra elements,
returns a list of facts describing the missing elements, diffing against the extra ones where
appropriate. | describeMissing | java | google/truth | core/src/main/java/com/google/common/truth/IterableSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java | Apache-2.0 |
private ImmutableList<Fact> describeMissingWithoutPairing(List<? extends E> missing) {
return makeElementFactsForBoth("missing", missing, "unexpected", ImmutableList.of());
} | Given a list of missing elements, which must be non-empty, and a list of extra elements,
returns a list of facts describing the missing elements, diffing against the extra ones where
appropriate. | describeMissingWithoutPairing | java | google/truth | core/src/main/java/com/google/common/truth/IterableSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java | Apache-2.0 |
private ImmutableList<Fact> describeMissingWithPairing(
Pairing<A, E> pairing, Correspondence.ExceptionStore exceptions) {
ImmutableList.Builder<Fact> facts = ImmutableList.builder();
for (Object key : pairing.pairedKeysToExpectedValues.keySet()) {
E missing = pairing.pairedKeysToExpectedVal... | Given a list of missing elements, which must be non-empty, and a list of extra elements,
returns a list of facts describing the missing elements, diffing against the extra ones where
appropriate. | describeMissingWithPairing | java | google/truth | core/src/main/java/com/google/common/truth/IterableSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java | Apache-2.0 |
private boolean failIfOneToOneMappingHasMissing(
List<? extends A> actual,
List<? extends E> expected,
BiMap<Integer, Integer> mapping,
Correspondence.ExceptionStore exceptions) {
List<? extends E> missing = findNotIndexed(expected, mapping.values());
if (!missing.isEmpty()) ... | Given a list of expected elements, and a 1:1 mapping between actual and expected elements
specified as a bimap of indexes into the actual list to indexes into the expected list,
checks that every expected element maps to an actual element. Actual elements which do not
map to any expected elements are ignored. | failIfOneToOneMappingHasMissing | java | google/truth | core/src/main/java/com/google/common/truth/IterableSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java | Apache-2.0 |
@SafeVarargs
public final void containsAnyOf(E first, E second, E @Nullable ... rest) {
containsAnyIn(accumulate(first, second, rest));
} | Checks that the actual iterable contains at least one element that corresponds to at least
one of the expected elements. | containsAnyOf | java | google/truth | core/src/main/java/com/google/common/truth/IterableSubject.java | https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/IterableSubject.java | Apache-2.0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.