code
stringlengths 25
201k
| docstring
stringlengths 19
96.2k
| func_name
stringlengths 0
235
| language
stringclasses 1
value | repo
stringlengths 8
51
| path
stringlengths 11
314
| url
stringlengths 62
377
| license
stringclasses 7
values |
|---|---|---|---|---|---|---|---|
protected final StandardSubjectBuilder ignoreCheck() {
return StandardSubjectBuilder.forCustomFailureStrategy(failure -> {});
}
|
Begins a new call chain that ignores any failures. This is useful for subjects that normally
delegate with to other subjects by using {@link #check} but have already reported a failure. In
such cases it may still be necessary to return a {@code Subject} instance even though any
subsequent assertions are meaningless. For example, if a user chains together more {@link
ThrowableSubject#hasCauseThat} calls than the actual exception has causes, {@code hasCauseThat}
returns {@code ignoreCheck().that(... a dummy exception ...)}.
|
ignoreCheck
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Subject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Subject.java
|
Apache-2.0
|
protected final void failWithActual(String key, @Nullable Object value) {
failWithActual(fact(key, value));
}
|
Fails, reporting a message with two "{@linkplain Fact facts}":
<ul>
<li><i>key</i>: <i>value</i>
<li>but was: <i>actual value</i>.
</ul>
<p>This is the simplest failure API. For more advanced needs, see {@linkplain
#failWithActual(Fact, Fact...) the other overload} and {@link #failWithoutActual(Fact, Fact...)
failWithoutActual}.
<p>Example usage: The check {@code contains(String)} calls {@code failWithActual("expected to
contain", string)}.
<p><b>Note:</b> While Truth's {@code fail*()} methods usually throw {@link AssertionError},
they do not do so in all cases: When users use an alternative {@link FailureStrategy}, such as
{@link Expect}, the {@code fail*()} methods may instead record the failure somewhere and then
return. To accommodate this, {@link Subject} methods should typically {@code return} after
calling a {@code fail*()} method, rather than continue onward to potentially fail a second time
or throw an exception. For cases in which a method needs to return another {@link Subject} to
the user, see {@link #ignoreCheck()}.
|
failWithActual
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Subject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Subject.java
|
Apache-2.0
|
protected final void failWithActual(Fact first, Fact... rest) {
metadata.fail(sandwich(first, rest, butWas()));
}
|
Fails, reporting a message with the given facts, followed by an automatically added fact of the
form:
<ul>
<li>but was: <i>actual value</i>.
</ul>
<p>If you have only one fact to report (and it's a {@linkplain Fact#fact key-value fact}),
prefer {@linkplain #failWithActual(String, Object) the simpler overload}.
<p>Example usage: The check {@code isEmpty()} calls {@code failWithActual(simpleFact("expected
to be empty"))}.
<p><b>Note:</b> While Truth's {@code fail*()} methods usually throw {@link AssertionError},
they do not do so in all cases: When users use an alternative {@link FailureStrategy}, such as
{@link Expect}, the {@code fail*()} methods may instead record the failure somewhere and then
return. To accommodate this, {@link Subject} methods should typically {@code return} after
calling a {@code fail*()} method, rather than continue onward to potentially fail a second time
or throw an exception. For cases in which a method needs to return another {@link Subject} to
the user, see {@link #ignoreCheck()}.
|
failWithActual
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Subject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Subject.java
|
Apache-2.0
|
final void failWithActual(Iterable<Fact> facts) {
metadata.fail(append(ImmutableList.copyOf(facts), butWas()));
}
|
Internal variant of {@link #failWithActual(Fact, Fact...)} that accepts an {@link Iterable}.
<p><b>Note:</b> While Truth's {@code fail*()} methods usually throw {@link AssertionError},
they do not do so in all cases: When users use an alternative {@link FailureStrategy}, such as
{@link Expect}, the {@code fail*()} methods may instead record the failure somewhere and then
return. To accommodate this, {@link Subject} methods should typically {@code return} after
calling a {@code fail*()} method, rather than continue onward to potentially fail a second time
or throw an exception. For cases in which a method needs to return another {@link Subject} to
the user, see {@link #ignoreCheck()}.
|
failWithActual
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Subject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Subject.java
|
Apache-2.0
|
@Deprecated
final void fail(String check) {
fail(check, new Object[0]);
}
|
Legacy failure method. Prefer the {@code fail*Actual(...)} family of methods.
<p><b>Note:</b> While Truth's {@code fail*()} methods usually throw {@link AssertionError},
they do not do so in all cases: When users use an alternative {@link FailureStrategy}, such as
{@link Expect}, the {@code fail*()} methods may instead record the failure somewhere and then
return. To accommodate this, {@link Subject} methods should typically {@code return} after
calling a {@code fail*()} method, rather than continue onward to potentially fail a second time
or throw an exception. For cases in which a method needs to return another {@link Subject} to
the user, see {@link #ignoreCheck()}.
@param check the check being asserted
@deprecated Prefer to construct {@link Fact}-style methods, typically by using {@link
#failWithActual(Fact, Fact...) failWithActual}{@code (}{@link Fact#simpleFact
simpleFact(...)}{@code )}. However, if you want to preserve your exact failure message as a
migration aid, you can inline this method (and then inline the resulting method call, as
well).
|
fail
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Subject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Subject.java
|
Apache-2.0
|
@Deprecated
final void fail(String verb, Object other) {
fail(verb, new Object[] {other});
}
|
Legacy failure method. Prefer the {@code fail*Actual(...)} family of methods.
<p><b>Note:</b> While Truth's {@code fail*()} methods usually throw {@link AssertionError},
they do not do so in all cases: When users use an alternative {@link FailureStrategy}, such as
{@link Expect}, the {@code fail*()} methods may instead record the failure somewhere and then
return. To accommodate this, {@link Subject} methods should typically {@code return} after
calling a {@code fail*()} method, rather than continue onward to potentially fail a second time
or throw an exception. For cases in which a method needs to return another {@link Subject} to
the user, see {@link #ignoreCheck()}.
@param verb the check being asserted
@param other the value against which the value under test is compared
@deprecated Prefer to construct {@link Fact}-style methods, typically by using {@link
#failWithActual(String, Object)}. However, if you want to preserve your exact failure
message as a migration aid, you can inline this method (and then inline the resulting
method call, as well).
|
fail
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Subject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Subject.java
|
Apache-2.0
|
@Deprecated
final void fail(String verb, @Nullable Object... messageParts) {
StringBuilder message = new StringBuilder("Not true that <");
message.append(actualCustomStringRepresentation()).append("> ").append(verb);
for (Object part : messageParts) {
message.append(" <").append(part).append(">");
}
failWithoutActual(simpleFact(message.toString()));
}
|
Legacy failure method. Prefer the {@code fail*Actual(...)} family of methods.
<p><b>Note:</b> While Truth's {@code fail*()} methods usually throw {@link AssertionError},
they do not do so in all cases: When users use an alternative {@link FailureStrategy}, such as
{@link Expect}, the {@code fail*()} methods may instead record the failure somewhere and then
return. To accommodate this, {@link Subject} methods should typically {@code return} after
calling a {@code fail*()} method, rather than continue onward to potentially fail a second time
or throw an exception. For cases in which a method needs to return another {@link Subject} to
the user, see {@link #ignoreCheck()}.
@param verb the check being asserted
@param messageParts the expectations against which the value under test is compared
@deprecated Prefer to construct {@link Fact}-style methods, typically by using {@link
#failWithActual(Fact, Fact...)}. However, if you want to preserve your exact failure
message as a migration aid, you can inline this method.
|
fail
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Subject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Subject.java
|
Apache-2.0
|
final void failEqualityCheckForEqualsWithoutDescription(@Nullable Object expected) {
failEqualityCheck(EqualityCheck.EQUAL, expected, ComparisonResult.differentNoDescription());
}
|
Special version of {@link #failEqualityCheck} for use from {@link IterableSubject}, documented
further there.
<p><b>Note:</b> While Truth's {@code fail*()} methods usually throw {@link AssertionError},
they do not do so in all cases: When users use an alternative {@link FailureStrategy}, such as
{@link Expect}, the {@code fail*()} methods may instead record the failure somewhere and then
return. To accommodate this, {@link Subject} methods should typically {@code return} after
calling a {@code fail*()} method, rather than continue onward to potentially fail a second time
or throw an exception. For cases in which a method needs to return another {@link Subject} to
the user, see {@link #ignoreCheck()}.
|
failEqualityCheckForEqualsWithoutDescription
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Subject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Subject.java
|
Apache-2.0
|
private void failEqualityCheck(
EqualityCheck equalityCheck, @Nullable Object expected, ComparisonResult difference) {
String actualString = actualCustomStringRepresentation();
String expectedString = formatActualOrExpected(expected);
String actualClass = actual == null ? "(null reference)" : actual.getClass().getName();
String expectedClass = expected == null ? "(null reference)" : expected.getClass().getName();
/*
* It's a little odd for expectedString to be formatActualOrExpected(expected) but actualString
* *not* to be formatActualOrExpected(actual), since we're going to compare the two. Instead,
* actualString is actualCustomStringRepresentation() -- as it is for other assertions, since
* users may have overridden that method. While actualCustomStringRepresentation() defaults to
* formatActualOrExpected(actual), it's only a default.
*
* What we really want here is probably to delete actualCustomStringRepresentation() and migrate
* users to formatActualOrExpected(actual).
*/
boolean sameToStrings = actualString.equals(expectedString);
boolean sameClassNames = actualClass.equals(expectedClass);
// TODO(cpovirk): Handle "same class name, different class loader."
// `equal` is always false for isEqualTo, but it varies for isSameInstanceAs:
boolean equal = difference.valuesAreEqual();
if (equalityCheck == EqualityCheck.EQUAL
&& (tryFailForTrailingWhitespaceOnly(expected) || tryFailForEmptyString(expected))) {
// tryFailForTrailingWhitespaceOnly or tryFailForEmptyString reported a failure, so we're done
return;
}
if (sameToStrings) {
if (sameClassNames) {
String doppelgangerDescription =
equal
? "(different but equal instance of same class with same string representation)"
: "(non-equal instance of same class with same string representation)";
failEqualityCheckNoComparisonFailure(
difference,
fact(equalityCheck.keyForExpected, expectedString),
fact("but was", doppelgangerDescription));
} else {
failEqualityCheckNoComparisonFailure(
difference,
fact(equalityCheck.keyForExpected, expectedString),
fact("an instance of", expectedClass),
fact("but was", "(non-equal value with same string representation)"),
fact("an instance of", actualClass));
}
} else {
if (equalityCheck == EqualityCheck.EQUAL && actual != null && expected != null) {
metadata.failEqualityCheck(difference.factsOrEmpty(), expectedString, actualString);
} else {
failEqualityCheckNoComparisonFailure(
difference,
fact(equalityCheck.keyForExpected, expectedString),
fact("but was", actualString));
}
}
}
|
Fails, potentially producing a {@code ComparisonFailure}.
<p><b>Note:</b> While Truth's {@code fail*()} methods usually throw {@link AssertionError},
they do not do so in all cases: When users use an alternative {@link FailureStrategy}, such as
{@link Expect}, the {@code fail*()} methods may instead record the failure somewhere and then
return. To accommodate this, {@link Subject} methods should typically {@code return} after
calling a {@code fail*()} method, rather than continue onward to potentially fail a second time
or throw an exception. For cases in which a method needs to return another {@link Subject} to
the user, see {@link #ignoreCheck()}.
|
failEqualityCheck
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Subject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Subject.java
|
Apache-2.0
|
@Deprecated
final void failWithBadResults(
String verb, @Nullable Object expected, String failVerb, @Nullable Object actual) {
String message =
lenientFormat(
"Not true that <%s> %s <%s>. It %s <%s>",
actualCustomStringRepresentation(),
verb,
expected,
failVerb,
actual == null ? "null reference" : actual);
failWithoutActual(simpleFact(message));
}
|
Legacy failure method. Prefer the {@code fail*Actual(...)} family of methods.
<p><b>Note:</b> While Truth's {@code fail*()} methods usually throw {@link AssertionError},
they do not do so in all cases: When users use an alternative {@link FailureStrategy}, such as
{@link Expect}, the {@code fail*()} methods may instead record the failure somewhere and then
return. To accommodate this, {@link Subject} methods should typically {@code return} after
calling a {@code fail*()} method, rather than continue onward to potentially fail a second time
or throw an exception. For cases in which a method needs to return another {@link Subject} to
the user, see {@link #ignoreCheck()}.
@param verb the check being asserted
@param expected the expectations against which the value under test is compared
@param failVerb the failure of the check being asserted
@param actual the actual value that the value under test was compared against
@deprecated Prefer to construct {@link Fact}-style methods, typically by using {@link
#failWithActual(Fact, Fact...)}. However, if you want to preserve your exact failure
message as a migration aid, you can inline this method.
|
failWithBadResults
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Subject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Subject.java
|
Apache-2.0
|
@Deprecated
final void failWithCustomSubject(
String verb, @Nullable Object expected, @Nullable Object actual) {
String message =
lenientFormat(
"Not true that <%s> %s <%s>",
actual == null ? "null reference" : actual, verb, expected);
failWithoutActual(simpleFact(message));
}
|
Legacy failure method that accepts an alternative representation of the actual value. Prefer
the {@code fail*Actual(...)} family of methods.
<p><b>Note:</b> While Truth's {@code fail*()} methods usually throw {@link AssertionError},
they do not do so in all cases: When users use an alternative {@link FailureStrategy}, such as
{@link Expect}, the {@code fail*()} methods may instead record the failure somewhere and then
return. To accommodate this, {@link Subject} methods should typically {@code return} after
calling a {@code fail*()} method, rather than continue onward to potentially fail a second time
or throw an exception. For cases in which a method needs to return another {@link Subject} to
the user, see {@link #ignoreCheck()}.
@param verb the check being asserted
@param expected the expected value of the check
@param actual the custom representation of the value under test to be reported in the failure.
@deprecated Prefer to construct {@link Fact}-style methods, typically by using {@link
#failWithoutActual(Fact, Fact...)}. However, if you want to preserve your exact failure
message as a migration aid, you can inline this method.
|
failWithCustomSubject
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Subject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Subject.java
|
Apache-2.0
|
@Deprecated
final void failWithoutSubject(String check) {
failWithoutActual(simpleFact(lenientFormat("Not true that the subject %s", check)));
}
|
Legacy failure method. Prefer the {@code fail*Actual(...)} family of methods.
<p><b>Note:</b> While Truth's {@code fail*()} methods usually throw {@link AssertionError},
they do not do so in all cases: When users use an alternative {@link FailureStrategy}, such as
{@link Expect}, the {@code fail*()} methods may instead record the failure somewhere and then
return. To accommodate this, {@link Subject} methods should typically {@code return} after
calling a {@code fail*()} method, rather than continue onward to potentially fail a second time
or throw an exception. For cases in which a method needs to return another {@link Subject} to
the user, see {@link #ignoreCheck()}.
@deprecated Prefer to construct {@link Fact}-style methods, typically by using {@link
#failWithoutActual(Fact, Fact...) failWithoutActual}{@code (}{@link Fact#simpleFact
simpleFact(...)}{@code )}. However, if you want to preserve your exact failure message as a
migration aid, you can inline this method.
|
failWithoutSubject
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Subject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Subject.java
|
Apache-2.0
|
protected final void failWithoutActual(Fact first, Fact... rest) {
metadata.fail(ImmutableList.copyOf(Lists.asList(first, rest)));
}
|
Fails, reporting a message with the given facts, <i>without automatically adding the actual
value.</i>
<p>Most failure messages should report the actual value, so most checks should call {@link
#failWithActual(Fact, Fact...) failWithActual} instead. However, {@code failWithoutActual} is
useful in some cases:
<ul>
<li>when the actual value is obvious from the rest of the message. For example, {@code
isNotEmpty()} calls {@code failWithoutActual(simpleFact("expected not to be empty")}.
<li>when the actual value shouldn't come last or should have a different key than the default
of "but was." For example, {@code isNotWithin(...).of(...)} calls {@code
failWithoutActual} so that it can put the expected and actual values together, followed
by the tolerance.
</ul>
<p>Example usage: The check {@code isEmpty()} calls {@code failWithActual(simpleFact("expected
to be empty"))}.
<p><b>Note:</b> While Truth's {@code fail*()} methods usually throw {@link AssertionError},
they do not do so in all cases: When users use an alternative {@link FailureStrategy}, such as
{@link Expect}, the {@code fail*()} methods may instead record the failure somewhere and then
return. To accommodate this, {@link Subject} methods should typically {@code return} after
calling a {@code fail*()} method, rather than continue onward to potentially fail a second time
or throw an exception. For cases in which a method needs to return another {@link Subject} to
the user, see {@link #ignoreCheck()}.
|
failWithoutActual
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Subject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Subject.java
|
Apache-2.0
|
@Deprecated
final void failWithoutActual(String check) {
failWithoutSubject(check);
}
|
Legacy failure method that excludes the actual value. Prefer the {@code fail*Actual(...)}
family of methods.
<p><b>Note:</b> While Truth's {@code fail*()} methods usually throw {@link AssertionError},
they do not do so in all cases: When users use an alternative {@link FailureStrategy}, such as
{@link Expect}, the {@code fail*()} methods may instead record the failure somewhere and then
return. To accommodate this, {@link Subject} methods should typically {@code return} after
calling a {@code fail*()} method, rather than continue onward to potentially fail a second time
or throw an exception. For cases in which a method needs to return another {@link Subject} to
the user, see {@link #ignoreCheck()}.
@param check the check being asserted
@deprecated Prefer to construct {@link Fact}-style methods, typically by using {@link
#failWithoutActual(Fact, Fact...) failWithoutActual}{@code (}{@link Fact#simpleFact
simpleFact(...)}{@code )}. However, if you want to preserve your exact failure message as a
migration aid, you can inline this method (and then inline the resulting method call, as
well).
|
failWithoutActual
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Subject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Subject.java
|
Apache-2.0
|
@DoNotCall(
"Subject.equals() is not supported. Did you mean to call"
+ " assertThat(actual).isEqualTo(expected) instead of"
+ " assertThat(actual).equals(expected)?")
@Deprecated
@Override
public final boolean equals(@Nullable Object o) {
throw new UnsupportedOperationException(
"Subject.equals() is not supported. Did you mean to call"
+ " assertThat(actual).isEqualTo(expected) instead of"
+ " assertThat(actual).equals(expected)?");
}
|
@throws UnsupportedOperationException always
@deprecated {@link Object#equals(Object)} is not supported on Truth subjects. If you are
writing a test assertion (actual vs. expected), use {@link #isEqualTo(Object)} instead.
|
equals
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Subject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Subject.java
|
Apache-2.0
|
@DoNotCall("Subject.hashCode() is not supported.")
@Deprecated
@Override
public final int hashCode() {
throw new UnsupportedOperationException("Subject.hashCode() is not supported.");
}
|
@throws UnsupportedOperationException always
@deprecated {@link Object#hashCode()} is not supported on Truth subjects.
|
hashCode
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Subject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Subject.java
|
Apache-2.0
|
static String countDuplicatesAndAddTypeInfo(Iterable<?> itemsIterable) {
Collection<?> items = iterableToCollection(itemsIterable);
String homogeneousTypeName = getHomogeneousTypeName(items);
return homogeneousTypeName != null
? lenientFormat("%s (%s)", countDuplicates(items), homogeneousTypeName)
: countDuplicates(addTypeInfoToEveryItem(items));
}
|
Makes a String representation of {@code items} with collapsed duplicates and additional class
info.
<p>Example: {@code countDuplicatesAndAddTypeInfo([1, 2, 2, 3]) == "[1, 2 [3 copies]]
(java.lang.Integer)"} and {@code countDuplicatesAndAddTypeInfo([1, 2L]) == "[1
(java.lang.Integer), 2 (java.lang.Long)]"}.
|
countDuplicatesAndAddTypeInfo
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/SubjectUtils.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/SubjectUtils.java
|
Apache-2.0
|
static List<@Nullable Object> retainMatchingToString(
Iterable<?> items, Iterable<?> itemsToCheck) {
ListMultimap<String, @Nullable Object> stringValueToItemsToCheck = ArrayListMultimap.create();
for (Object itemToCheck : itemsToCheck) {
stringValueToItemsToCheck.put(String.valueOf(itemToCheck), itemToCheck);
}
List<@Nullable Object> result = new ArrayList<>();
for (Object item : items) {
for (Object itemToCheck : stringValueToItemsToCheck.get(String.valueOf(item))) {
if (!Objects.equals(itemToCheck, item)) {
result.add(item);
break;
}
}
}
return result;
}
|
Returns a new collection containing all elements in {@code items} for which there exists at
least one element in {@code itemsToCheck} that has the same {@code toString()} value without
being equal.
<p>Example: {@code retainMatchingToString([1L, 2L, 2L], [2, 3]) == [2L, 2L]}
|
retainMatchingToString
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/SubjectUtils.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/SubjectUtils.java
|
Apache-2.0
|
public void isEmpty() {
if (!checkNotNull(actual).isEmpty()) {
failWithActual(simpleFact("expected to be empty"));
}
}
|
Checks that the actual table is empty.
|
isEmpty
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/TableSubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/TableSubject.java
|
Apache-2.0
|
public void isNotEmpty() {
if (checkNotNull(actual).isEmpty()) {
failWithoutActual(simpleFact("expected not to be empty"));
}
}
|
Checks that the actual table is not empty.
|
isNotEmpty
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/TableSubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/TableSubject.java
|
Apache-2.0
|
public void hasSize(int expectedSize) {
checkArgument(expectedSize >= 0, "expectedSize(%s) must be >= 0", expectedSize);
check("size()").that(checkNotNull(actual).size()).isEqualTo(expectedSize);
}
|
Checks that the actual table has the given size.
|
hasSize
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/TableSubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/TableSubject.java
|
Apache-2.0
|
public void contains(@Nullable Object rowKey, @Nullable Object columnKey) {
if (!checkNotNull(actual).contains(rowKey, columnKey)) {
/*
* TODO(cpovirk): Consider including information about whether any cell with the given row
* *or* column was present.
*/
failWithActual(
simpleFact("expected to contain mapping for row-column key pair"),
fact("row key", rowKey),
fact("column key", columnKey));
}
}
|
Checks that the actual table contains a mapping for the given row key and column key.
|
contains
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/TableSubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/TableSubject.java
|
Apache-2.0
|
public void doesNotContain(@Nullable Object rowKey, @Nullable Object columnKey) {
if (checkNotNull(actual).contains(rowKey, columnKey)) {
failWithoutActual(
simpleFact("expected not to contain mapping for row-column key pair"),
fact("row key", rowKey),
fact("column key", columnKey),
fact("but contained value", actual.get(rowKey, columnKey)),
fact("full contents", actual));
}
}
|
Checks that the actual table does not contain a mapping for the given row key and column key.
|
doesNotContain
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/TableSubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/TableSubject.java
|
Apache-2.0
|
static Factory<TableSubject, Table<?, ?, ?>> tables() {
return TableSubject::new;
}
|
Checks that the actual table contains the given value.
|
tables
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/TableSubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/TableSubject.java
|
Apache-2.0
|
public final StringSubject hasMessageThat() {
// We provide a more helpful error message if hasCauseThat() methods are chained too deep, as in
// assertThat(new Exception()).hasCauseThat().hasMessageThat()....
// This message also triggers for the simpler case of assertThat(null).hasMessageThat()....
if (actual == null) {
failForNullThrowable("Attempt to assert about the message of a null Throwable");
return ignoreCheck().that("");
}
StandardSubjectBuilder check = check("getMessage()");
if (actual instanceof ErrorWithFacts && ((ErrorWithFacts) actual).facts().size() > 1) {
check =
check.withMessage(
"(Note from Truth: When possible, instead of asserting on the full message, assert"
+ " about individual facts by using ExpectFailure.assertThat.)");
}
return check.that(actual.getMessage());
}
|
Returns a {@code StringSubject} to make assertions about the throwable's message.
|
hasMessageThat
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/ThrowableSubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/ThrowableSubject.java
|
Apache-2.0
|
@SuppressWarnings("MemberName") // The underscore is a weird but intentional choice.
public static StandardSubjectBuilder assert_() {
return ASSERT;
}
|
Begins a call chain with the fluent Truth API. If the check made by the chain fails, it will
throw {@link AssertionError}.
|
assert_
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Truth.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Truth.java
|
Apache-2.0
|
public static StandardSubjectBuilder assertWithMessage(@Nullable String messageToPrepend) {
return assert_().withMessage(messageToPrepend);
}
|
Begins an assertion that, if it fails, will prepend the given message to the failure message.
<p>This method is a shortcut for {@code assert_().withMessage(...)}.
<p>To set a message when using a custom subject, use {@code assertWithMessage(...).}{@link
StandardSubjectBuilder#about about(...)}, as discussed in <a
href="https://truth.dev/faq#java8">this FAQ entry</a>.
|
assertWithMessage
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Truth.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Truth.java
|
Apache-2.0
|
public static StandardSubjectBuilder assertWithMessage(String format, @Nullable Object... args) {
return assert_().withMessage(format, args);
}
|
Begins an assertion that, if it fails, will prepend the given message to the failure message.
<p><b>Note:</b> the arguments will be substituted into the format template using {@link
com.google.common.base.Strings#lenientFormat Strings.lenientFormat}. Note this only supports
the {@code %s} specifier.
<p>This method is a shortcut for {@code assert_().withMessage(...)}.
<p>To set a message when using a custom subject, use {@code assertWithMessage(...).}{@link
StandardSubjectBuilder#about about(...)}, as discussed in <a
href="https://truth.dev/faq#java8">this FAQ entry</a>.
@throws IllegalArgumentException if the number of placeholders in the format string does not
equal the number of given arguments
|
assertWithMessage
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Truth.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Truth.java
|
Apache-2.0
|
public static <S extends Subject, T> SimpleSubjectBuilder<S, T> assertAbout(
Subject.Factory<S, T> factory) {
return assert_().about(factory);
}
|
Given a factory for some {@code Subject} class, returns a builder whose {@code that(actual)}
method creates instances of that class.
|
assertAbout
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Truth.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Truth.java
|
Apache-2.0
|
public static <CustomSubjectBuilderT extends CustomSubjectBuilder>
CustomSubjectBuilderT assertAbout(
CustomSubjectBuilder.Factory<CustomSubjectBuilderT> factory) {
return assert_().about(factory);
}
|
A generic, advanced method of extension of Truth to new types, which is documented on {@link
CustomSubjectBuilder}. Extension creators should prefer {@link Subject.Factory} if possible.
|
assertAbout
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Truth.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Truth.java
|
Apache-2.0
|
public static <ComparableT extends Comparable<?>> ComparableSubject<ComparableT> assertThat(
@Nullable ComparableT actual) {
return assert_().that(actual);
}
|
Begins an assertion about a {@link Comparable}.
|
assertThat
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Truth.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Truth.java
|
Apache-2.0
|
public static BigDecimalSubject assertThat(@Nullable BigDecimal actual) {
return assert_().that(actual);
}
|
Begins an assertion about a {@link BigDecimal}.
|
assertThat
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Truth.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Truth.java
|
Apache-2.0
|
public static Subject assertThat(@Nullable Object actual) {
return assert_().that(actual);
}
|
Begins an assertion about an {@link Object}.
|
assertThat
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Truth.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Truth.java
|
Apache-2.0
|
@GwtIncompatible("ClassSubject.java")
@J2ktIncompatible
public static ClassSubject assertThat(@Nullable Class<?> actual) {
return assert_().that(actual);
}
|
Begins an assertion about a {@link Class}.
|
assertThat
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Truth.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Truth.java
|
Apache-2.0
|
public static ThrowableSubject assertThat(@Nullable Throwable actual) {
return assert_().that(actual);
}
|
Begins an assertion about a {@link Throwable}.
<p>Truth does not provide its own support for calling a method and automatically catching an
expected exception, only for asserting on the exception after it has been caught. To catch the
exception, we suggest {@link org.junit.Assert#assertThrows(Class,
org.junit.function.ThrowingRunnable) assertThrows} (JUnit), <a
href="https://kotlinlang.org/api/latest/kotlin.test/kotlin.test/assert-fails-with.html">{@code
assertFailsWith}</a> ({@code kotlin.test}), or similar functionality from your testing library
of choice.
<pre>
InvocationTargetException expected =
assertThrows(InvocationTargetException.class, () -> method.invoke(null));
assertThat(expected).hasCauseThat().isInstanceOf(IOException.class);
</pre>
|
assertThat
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Truth.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Truth.java
|
Apache-2.0
|
public static LongSubject assertThat(@Nullable Long actual) {
return assert_().that(actual);
}
|
Begins an assertion about a {@link Long}.
|
assertThat
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Truth.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Truth.java
|
Apache-2.0
|
public static DoubleSubject assertThat(@Nullable Double actual) {
return assert_().that(actual);
}
|
Begins an assertion about a {@link Double}.
|
assertThat
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Truth.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Truth.java
|
Apache-2.0
|
public static FloatSubject assertThat(@Nullable Float actual) {
return assert_().that(actual);
}
|
Begins an assertion about a {@link Float}.
|
assertThat
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Truth.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Truth.java
|
Apache-2.0
|
public static IntegerSubject assertThat(@Nullable Integer actual) {
return assert_().that(actual);
}
|
Begins an assertion about an {@link Integer}.
|
assertThat
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Truth.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Truth.java
|
Apache-2.0
|
public static BooleanSubject assertThat(@Nullable Boolean actual) {
return assert_().that(actual);
}
|
Begins an assertion about a {@link Boolean}.
|
assertThat
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Truth.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Truth.java
|
Apache-2.0
|
public static StringSubject assertThat(@Nullable String actual) {
return assert_().that(actual);
}
|
Begins an assertion about a {@link String}.
|
assertThat
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Truth.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Truth.java
|
Apache-2.0
|
public static IterableSubject assertThat(@Nullable Iterable<?> actual) {
return assert_().that(actual);
}
|
Begins an assertion about an {@link Iterable}.
|
assertThat
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Truth.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Truth.java
|
Apache-2.0
|
@SuppressWarnings("AvoidObjectArrays")
public static <T extends @Nullable Object> ObjectArraySubject<T> assertThat(
T @Nullable [] actual) {
return assert_().that(actual);
}
|
Begins an assertion about an {@link Object} array.
|
assertThat
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Truth.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Truth.java
|
Apache-2.0
|
public static PrimitiveBooleanArraySubject assertThat(boolean @Nullable [] actual) {
return assert_().that(actual);
}
|
Begins an assertion about a {@code boolean} array.
|
assertThat
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Truth.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Truth.java
|
Apache-2.0
|
public static PrimitiveShortArraySubject assertThat(short @Nullable [] actual) {
return assert_().that(actual);
}
|
Begins an assertion about a {@code short} array.
|
assertThat
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Truth.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Truth.java
|
Apache-2.0
|
public static PrimitiveIntArraySubject assertThat(int @Nullable [] actual) {
return assert_().that(actual);
}
|
Begins an assertion about an {@code int} array.
|
assertThat
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Truth.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Truth.java
|
Apache-2.0
|
public static PrimitiveLongArraySubject assertThat(long @Nullable [] actual) {
return assert_().that(actual);
}
|
Begins an assertion about a {@code long} array.
|
assertThat
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Truth.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Truth.java
|
Apache-2.0
|
public static PrimitiveByteArraySubject assertThat(byte @Nullable [] actual) {
return assert_().that(actual);
}
|
Begins an assertion about a {@code byte} array.
|
assertThat
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Truth.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Truth.java
|
Apache-2.0
|
public static PrimitiveCharArraySubject assertThat(char @Nullable [] actual) {
return assert_().that(actual);
}
|
Begins an assertion about a {@code char} array.
|
assertThat
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Truth.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Truth.java
|
Apache-2.0
|
public static PrimitiveFloatArraySubject assertThat(float @Nullable [] actual) {
return assert_().that(actual);
}
|
Begins an assertion about a {@code float} array.
|
assertThat
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Truth.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Truth.java
|
Apache-2.0
|
public static PrimitiveDoubleArraySubject assertThat(double @Nullable [] actual) {
return assert_().that(actual);
}
|
Begins an assertion about a {@code double} array.
|
assertThat
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Truth.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Truth.java
|
Apache-2.0
|
public static GuavaOptionalSubject assertThat(
com.google.common.base.@Nullable Optional<?> actual) {
return assert_().that(actual);
}
|
Begins an assertion about a Guava {@link com.google.common.base.Optional}.
|
assertThat
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Truth.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Truth.java
|
Apache-2.0
|
public static MapSubject assertThat(@Nullable Map<?, ?> actual) {
return assert_().that(actual);
}
|
Begins an assertion about a {@link Map}.
|
assertThat
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Truth.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Truth.java
|
Apache-2.0
|
public static MultimapSubject assertThat(@Nullable Multimap<?, ?> actual) {
return assert_().that(actual);
}
|
Begins an assertion about a {@link Multimap}.
|
assertThat
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Truth.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Truth.java
|
Apache-2.0
|
public static MultisetSubject assertThat(@Nullable Multiset<?> actual) {
return assert_().that(actual);
}
|
Begins an assertion about a {@link Multiset}.
|
assertThat
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Truth.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Truth.java
|
Apache-2.0
|
public static TableSubject assertThat(@Nullable Table<?, ?, ?> actual) {
return assert_().that(actual);
}
|
Begins an assertion about a {@link Table}.
|
assertThat
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Truth.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Truth.java
|
Apache-2.0
|
@SuppressWarnings("NullableOptional") // Truth always accepts nulls, no matter the type
public static OptionalSubject assertThat(@Nullable Optional<?> actual) {
return assert_().that(actual);
}
|
Begins an assertion about an {@link Optional}.
@since 1.3.0 (present in {@link Truth8} since before 1.0)
|
assertThat
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Truth.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Truth.java
|
Apache-2.0
|
public static OptionalIntSubject assertThat(@Nullable OptionalInt actual) {
return assert_().that(actual);
}
|
Begins an assertion about an {@link OptionalInt}.
@since 1.3.0 (present in {@link Truth8} since before 1.0)
|
assertThat
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Truth.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Truth.java
|
Apache-2.0
|
public static OptionalLongSubject assertThat(@Nullable OptionalLong actual) {
return assert_().that(actual);
}
|
Begins an assertion about an {@link OptionalLong}.
@since 1.4.0 (present in {@link Truth8} since before 1.0)
|
assertThat
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Truth.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Truth.java
|
Apache-2.0
|
public static OptionalDoubleSubject assertThat(@Nullable OptionalDouble actual) {
return assert_().that(actual);
}
|
Begins an assertion about an {@link OptionalDouble}.
@since 1.4.0 (present in {@link Truth8} since before 1.0)
|
assertThat
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Truth.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Truth.java
|
Apache-2.0
|
public static StreamSubject assertThat(@Nullable Stream<?> actual) {
return assert_().that(actual);
}
|
Begins an assertion about a {@link Stream}.
@since 1.4.0 (present in {@link Truth8} since before 1.0)
|
assertThat
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Truth.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Truth.java
|
Apache-2.0
|
public static IntStreamSubject assertThat(@Nullable IntStream actual) {
return assert_().that(actual);
}
|
Begins an assertion about an {@link IntStream}.
@since 1.4.0 (present in {@link Truth8} since before 1.0)
|
assertThat
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Truth.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Truth.java
|
Apache-2.0
|
public static LongStreamSubject assertThat(@Nullable LongStream actual) {
return assert_().that(actual);
}
|
Begins an assertion about a {@link LongStream}.
@since 1.4.0 (present in {@link Truth8} since before 1.0)
|
assertThat
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Truth.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Truth.java
|
Apache-2.0
|
@GwtIncompatible
@J2ObjCIncompatible
@J2ktIncompatible
public static PathSubject assertThat(@Nullable Path actual) {
return assert_().that(actual);
}
|
Begins an assertion about a {@link Path}.
@since 1.4.0 (present in {@link Truth8} since before 1.0)
|
assertThat
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/Truth.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/Truth.java
|
Apache-2.0
|
public static Factory<TruthFailureSubject, AssertionError> truthFailures() {
return TruthFailureSubject::new;
}
|
Factory for creating {@link TruthFailureSubject} instances. Most users will just use {@link
ExpectFailure#assertThat}.
|
truthFailures
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/TruthFailureSubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/TruthFailureSubject.java
|
Apache-2.0
|
public StringSubject factValue(String key) {
return doFactValue(key, null);
}
|
Returns a subject for the value with the given name.
<p>The value is always a string, the {@code String.valueOf} representation of the value passed
to {@link Fact#fact}.
<p>The value is never null:
<ul>
<li>In the case of {@linkplain Fact#simpleFact facts that have no value}, {@code factValue}
throws an exception. To test for such facts, use {@link #factKeys()}{@code
.contains(...)} or a similar method.
<li>In the case of facts that have a value that is rendered as "null" (such as those created
with {@code fact("key", null)}), {@code factValue} considers them have a string value,
the string "null."
</ul>
<p>If the failure under test contains more than one fact with the given key, this method will
fail the test. To assert about such a failure, use {@linkplain #factValue(String, int) the
other overload} of {@code factValue}.
|
factValue
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/TruthFailureSubject.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/TruthFailureSubject.java
|
Apache-2.0
|
public static StandardSubjectBuilder assume() {
return ASSUME;
}
|
Begins a call chain with the fluent Truth API. If the check made by the chain fails, it will
throw {@link AssumptionViolatedException}.
|
assume
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/TruthJUnit.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/TruthJUnit.java
|
Apache-2.0
|
static boolean isAndroid() {
return false;
}
|
Tests if current platform is Android which is always false.
|
isAndroid
|
java
|
google/truth
|
core/src/main/java/com/google/common/truth/super/com/google/common/truth/Platform.java
|
https://github.com/google/truth/blob/master/core/src/main/java/com/google/common/truth/super/com/google/common/truth/Platform.java
|
Apache-2.0
|
private static void addCompareException(Correspondence.ExceptionStore exceptions) {
try {
boolean unused = TestCorrespondences.WITHIN_10_OF.compare(null, 123);
} catch (RuntimeException e) {
exceptions.addCompareException(CorrespondenceExceptionStoreTest.class, e, null, 123);
}
}
|
Adds a somewhat realistic exception from {@link Correspondence#compare} to the given store.
|
addCompareException
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/CorrespondenceExceptionStoreTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/CorrespondenceExceptionStoreTest.java
|
Apache-2.0
|
private static void assertExpectedFacts(Iterable<Fact> facts, String expectedFirstKey) {
assertThat(facts).hasSize(2);
Fact first = Iterables.get(facts, 0);
Fact second = Iterables.get(facts, 1);
assertThat(first.key).isEqualTo(expectedFirstKey);
assertThat(first.value).isNull();
assertThat(second.key).isEqualTo("first exception");
assertThat(second.value)
.matches( // an initial statement of the method that threw and the exception type:
"compare\\(null, 123\\) threw "
+ "com.google.common.truth.TestCorrespondences\\$NullPointerExceptionFromWithin10Of"
// some whitespace:
+ "\\s+"
// the start of a stack trace, with the correct class:
+ "at com\\.google\\.common\\.truth\\.TestCorrespondences"
// the rest of the stack trace, which we don't validate (and may contain newlines):
+ "(.|\\n)*"
// the expected separator
+ "\\n---");
}
|
Asserts that the given iterable has two facts, the first with the given key and no value, the
second with a key of {@code "first exception"} and a value describing the exception added by
{@link #addCompareException}.
|
assertExpectedFacts
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/CorrespondenceExceptionStoreTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/CorrespondenceExceptionStoreTest.java
|
Apache-2.0
|
@Test
@SuppressWarnings("TruthSelfEquals")
public void expectTwoFailures() {
failToExpect.delegate.that(4).isNotEqualTo(4);
failToExpect.delegate.that("abc").contains("x");
}
|
Test that stack traces are included in the error message created by Expect.
|
expectTwoFailures
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/ExpectFailureWithStackTraceTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/ExpectFailureWithStackTraceTest.java
|
Apache-2.0
|
@Override
public void evaluate() throws Throwable {
base.evaluate();
testMethodComplete.countDown();
taskToAwait.get();
}
|
Tests (and effectively sample code) for the Expect verb (implemented as a rule)
@author David Saff
@author Christian Gruber ([email protected])
|
evaluate
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/ExpectTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/ExpectTest.java
|
Apache-2.0
|
static void assertFailureValueIndexed(AssertionError e, String key, int index, String value) {
assertThat(e).factValue(key, index).isEqualTo(value);
}
|
Convenience methods for {@link Subject} tests.
|
assertFailureValueIndexed
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/FailureAssertions.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/FailureAssertions.java
|
Apache-2.0
|
static TestInstance empty() {
return new TestInstance(ImmutableListMultimap.<String, String>of());
}
|
Generates a test instance with an empty bipartite graph.
|
empty
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/GraphMatchingTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/GraphMatchingTest.java
|
Apache-2.0
|
static TestInstance fullyConnected(int lhsSize, int rhsSize) {
ImmutableListMultimap.Builder<String, String> edges = ImmutableListMultimap.builder();
for (int lhs = 0; lhs < lhsSize; lhs++) {
for (int rhs = 0; rhs < rhsSize; rhs++) {
edges.put("L" + lhs, "R" + rhs);
}
}
return new TestInstance(edges.build());
}
|
Generates a test instance with a fully-connected bipartite graph where there are {@code
lhsSize} elements in one set of vertices (which we call the LHS) and {@code rhsSize} elements
in the other (the RHS).
|
fullyConnected
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/GraphMatchingTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/GraphMatchingTest.java
|
Apache-2.0
|
static TestInstance fromBits(int lhsSize, int rhsSize, BitSet bits) {
ImmutableListMultimap.Builder<String, String> edges = ImmutableListMultimap.builder();
for (int lhs = 0; lhs < lhsSize; lhs++) {
for (int rhs = 0; rhs < rhsSize; rhs++) {
if (bits.get(lhs * rhsSize + rhs)) {
edges.put("L" + lhs, "R" + rhs);
}
}
}
return new TestInstance(edges.build());
}
|
Generates a test instance with a bipartite graph where there are {@code lhsSize} elements in
one set of vertices (which we call the LHS) and {@code rhsSize} elements in the other (the
RHS) and whether or not each of the {@code lhsSize * rhsSize} possible edges is included or
not according to whether one of the first {@code lhsSize * rhsSize} bits of {@code bits} is
set or not.
|
fromBits
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/GraphMatchingTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/GraphMatchingTest.java
|
Apache-2.0
|
void testAgainstBruteForce() {
ImmutableBiMap<String, String> actual = maximumCardinalityBipartiteMatching(edges);
for (Map.Entry<String, String> entry : actual.entrySet()) {
assertWithMessage(
"The returned bimap <%s> was not a matching of the bipartite graph <%s>",
actual, edges)
.that(edges)
.containsEntry(entry.getKey(), entry.getValue());
}
ImmutableBiMap<String, String> expected = bruteForceMaximalMatching();
assertWithMessage(
"The returned matching for the bipartite graph <%s> was not the same size as "
+ "the brute-force maximal matching <%s>",
edges, expected)
.that(actual)
.hasSize(expected.size());
}
|
Finds the maximum bipartite matching using the method under test and asserts both that it is
actually a matching of this bipartite graph and that it has the same size as a maximum
bipartite matching found by a brute-force approach.
|
testAgainstBruteForce
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/GraphMatchingTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/GraphMatchingTest.java
|
Apache-2.0
|
void testAgainstKnownSize(int expectedSize) {
ImmutableBiMap<String, String> actual = maximumCardinalityBipartiteMatching(edges);
for (Map.Entry<String, String> entry : actual.entrySet()) {
assertWithMessage(
"The returned bimap <%s> was not a matching of the bipartite graph <%s>",
actual, edges)
.that(edges)
.containsEntry(entry.getKey(), entry.getValue());
}
assertWithMessage(
"The returned matching for the bipartite graph <%s> had the wrong size", edges)
.that(actual)
.hasSize(expectedSize);
}
|
Finds the maximum bipartite matching using the method under test and asserts both that it is
actually a matching of this bipartite graph and that it has the expected size.
|
testAgainstKnownSize
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/GraphMatchingTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/GraphMatchingTest.java
|
Apache-2.0
|
private ImmutableBiMap<String, String> bruteForceMaximalMatching() {
ImmutableBiMap<String, String> best = ImmutableBiMap.of();
Matching candidate = new Matching();
while (candidate.valid()) {
if (candidate.size() > best.size()) {
best = candidate.asBiMap();
}
candidate.advance();
}
return best;
}
|
Returns a maximal bipartite matching of the bipartite graph, performing a brute force
evaluation of every possible matching.
|
bruteForceMaximalMatching
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/GraphMatchingTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/GraphMatchingTest.java
|
Apache-2.0
|
boolean valid() {
// When advance() has advanced through all the non-empty maps, the final state is that
// selectedEdges is empty, so we use that state as a marker of the final invalid cursor.
return !selectedEdges.isEmpty();
}
|
Returns whether this cursor is valid. Returns true if it has been advanced past the end of
the sequence.
|
valid
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/GraphMatchingTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/GraphMatchingTest.java
|
Apache-2.0
|
ImmutableBiMap<String, String> asBiMap() {
Preconditions.checkState(valid());
return ImmutableBiMap.copyOf(selectedEdges);
}
|
Returns an immutable representation of the current state of the matching as a bimap giving
the edges used in the matching, where the keys identify the vertices in the first set and
the values identify the vertices in the second set. The bimap is guaranteed not to be
empty. Fails if this cursor is invalid.
|
asBiMap
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/GraphMatchingTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/GraphMatchingTest.java
|
Apache-2.0
|
int size() {
Preconditions.checkState(valid());
return selectedEdges.size();
}
|
Returns the size (i.e. the number of edges in) the current matching, which is guaranteed to
be positive (not zer). Fails if this cursor is invalid.
|
size
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/GraphMatchingTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/GraphMatchingTest.java
|
Apache-2.0
|
void advance() {
Preconditions.checkState(valid());
// We essentially do a depth-first traversal through the possible matchings.
// First we try to add an edge.
Edge lastEdge = edgeStack.getLast();
Edge nextEdge = new Edge(lastEdge);
nextEdge.advance();
if (nextEdge.valid()) {
edgeStack.addLast(nextEdge);
nextEdge.addToSelected();
return;
}
// We can't add an edge, so we try to advance the edge at the top of the stack. If we can't
// advance that edge, we remove it and attempt to advance the new top of stack instead.
while (valid()) {
lastEdge = edgeStack.getLast();
lastEdge.removeFromSelected();
lastEdge.advance();
if (lastEdge.valid()) {
lastEdge.addToSelected();
return;
} else {
edgeStack.removeLast();
}
}
// We have reached the end of the sequence, and edgeStack is empty.
}
|
Advances to the next matching in the sequence, or invalidates the cursor if this was the
last. Fails if this cursor is invalid.
|
advance
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/GraphMatchingTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/GraphMatchingTest.java
|
Apache-2.0
|
boolean valid() {
// When advance() has advanced through all the edges, the final state is that lhsIndex ==
// lhsVertices.size(), so we use that state as a marker of the final invalid cursor.
return lhsIndex < lhsVertices.size();
}
|
Returns whether this cursor is valid. Returns true if it has been advanced past the end
of the sequence.
|
valid
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/GraphMatchingTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/GraphMatchingTest.java
|
Apache-2.0
|
void addToSelected() {
Preconditions.checkState(valid());
Preconditions.checkState(!selectedEdges.containsKey(lhsVertex()));
Preconditions.checkState(!selectedEdges.containsValue(rhsVertex()));
selectedEdges.put(lhsVertex(), rhsVertex());
}
|
Adds the current edge to the matching. Fails if either of the vertices in the edge is
already in the matching. Fails if this cursor is invalid.
|
addToSelected
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/GraphMatchingTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/GraphMatchingTest.java
|
Apache-2.0
|
void removeFromSelected() {
Preconditions.checkState(valid());
Preconditions.checkState(selectedEdges.containsKey(lhsVertex()));
Preconditions.checkState(selectedEdges.get(lhsVertex()).equals(rhsVertex()));
selectedEdges.remove(lhsVertex());
}
|
Removes the current edge from the matching. Fails if this edge is not in the matching.
Fails if this cursor is invalid.
|
removeFromSelected
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/GraphMatchingTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/GraphMatchingTest.java
|
Apache-2.0
|
private static BitSet intBits(int intValue) {
BitSet bits = new BitSet();
for (int bitIndex = 0; bitIndex < Integer.SIZE; bitIndex++) {
bits.set(bitIndex, (intValue & (1L << bitIndex)) != 0);
}
return bits;
}
|
Returns a bitset corresponding to the binary representation of the given integer.
|
intBits
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/GraphMatchingTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/GraphMatchingTest.java
|
Apache-2.0
|
private static BitSet randomBits(int maxBits, double bitProbability, Random rng) {
BitSet bits = new BitSet();
for (int bitIndex = 0; bitIndex < maxBits; bitIndex++) {
bits.set(bitIndex, rng.nextDouble() < bitProbability);
}
return bits;
}
|
Returns a bitset of up to {@code maxBits} bits where each bit is set with a probability {@code
bitProbability} using the given RNG.
|
randomBits
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/GraphMatchingTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/GraphMatchingTest.java
|
Apache-2.0
|
public static void main(String[] args) {
try {
assertThat("a").isEqualTo("b");
throw new Error("assertion should have failed");
} catch (AssertionError expected) {
ImmutableList<Fact> facts = ((AssertionErrorWithFacts) expected).facts();
assertThat(facts.get(0).key).isEqualTo("expected");
assertThat(facts.get(0).value).isEqualTo("b");
assertThat(facts.get(1).key).isEqualTo("but was");
assertThat(facts.get(1).value).isEqualTo("a");
}
}
|
Truth-using binary to be run without JUnit on the classpath to verify that it still works.
|
main
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/NoJUnitTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/NoJUnitTest.java
|
Apache-2.0
|
public void testSimple() {
try {
assertThat(0).isEqualTo(1);
throw new Error();
} catch (AssertionError failure) {
assertThat(failure.getStackTrace()).hasLength(1);
}
}
|
JUnit3 tests for {@link StackTraceCleaner}.
<p>The "main" tests are in {@link StackTraceCleanerTest}.
|
testSimple
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/StackTraceCleanerJUnit3Test.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/StackTraceCleanerJUnit3Test.java
|
Apache-2.0
|
private static boolean stringParsesToInteger(
@Nullable String actual, @Nullable Integer expected) {
if (actual == null) {
return expected == null;
}
try {
// Older versions of Android reject leading plus signs, per the pre-Java-7 contract:
// https://docs.oracle.com/javase/6/docs/api/java/lang/Integer.html#decode(java.lang.String)
// https://docs.oracle.com/javase/7/docs/api/java/lang/Integer.html#decode(java.lang.String)
if (actual.startsWith("+")) {
actual = actual.substring(1);
}
return Integer.decode(actual).equals(expected);
} catch (NumberFormatException e) {
return false;
}
}
|
A correspondence between strings and integers which tests whether the string parses as the
integer. Parsing is as specified by {@link Integer#decode(String)}. It considers null to
correspond to null only.
|
stringParsesToInteger
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/TestCorrespondences.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/TestCorrespondences.java
|
Apache-2.0
|
@SuppressWarnings("Casing_StringEqualsIgnoreCase")
private static boolean equalsIgnoreCaseHalfNullSafe(String actual, String expected) {
if (actual == null && expected == null) {
return true;
}
// Oops! We don't handle the case where actual == null but expected != null.
return actual.equalsIgnoreCase(expected);
}
|
A correspondence between strings which tests for case-insensitive equality, with a broken
attempt at null-safety. The {@link Correspondence#compare} implementation returns true for
(null, null) and false for (non-null, null), but throws {@link NullPointerException} for (null,
non-null).
|
equalsIgnoreCaseHalfNullSafe
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/TestCorrespondences.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/TestCorrespondences.java
|
Apache-2.0
|
@Override
public String toString() {
return Joiner.on('/').join(hasId() ? getId() : "none", getScore());
}
|
Returns the string form of the record, which is the {@code id} value or the literal {@code
none} if none, the literal {@code /}, and the {@code score} value concatenated.
|
toString
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/TestCorrespondences.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/TestCorrespondences.java
|
Apache-2.0
|
static @Nullable MyRecord parse(String str) {
List<String> parts = Splitter.on('/').splitToList(str);
if (parts.size() != 2) {
return null;
}
Integer id = parts.get(0).equals("none") ? -1 : Ints.tryParse(parts.get(0));
Integer score = Ints.tryParse(parts.get(1));
if (id == null || score == null) {
return null;
}
return new MyRecord(id, score);
}
|
If the argument is the string form of a record, returns that record; otherwise returns {@code
null}.
|
parse
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/TestCorrespondences.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/TestCorrespondences.java
|
Apache-2.0
|
@Override
public void isEqualTo(@Nullable Object expected) {
// TODO(user): Do better here when MessageLite descriptors are available.
if (Objects.equals(actual, expected)) {
return;
}
if (actual == null || expected == null) {
super.isEqualTo(expected);
} else if (actual.getClass() != expected.getClass()) {
failWithoutActual(
fact(
"expected",
expected instanceof MessageLite
? getTrimmedToString((MessageLite) expected)
: expected),
fact("an instance of", expected.getClass().getName()),
fact("but was", getTrimmedToString(actual)),
fact("an instance of", actual.getClass().getName()));
} else {
/*
* TODO(cpovirk): If we someday let subjects override formatActualOrExpected(), change this
* class to do so, and make this code path always delegate to super.isEqualTo().
*/
String ourString = getTrimmedToString(actual);
String theirString = getTrimmedToString((MessageLite) expected);
if (!ourString.equals(theirString)) {
new LiteProtoAsStringSubject(metadata, ourString).isEqualTo(theirString); // fails
} else {
// This will include the Object.toString() headers.
super.isEqualTo(expected);
}
}
}
|
Checks whether the MessageLite is equivalent to the argument, using the standard equals()
implementation.
|
isEqualTo
|
java
|
google/truth
|
extensions/liteproto/src/main/java/com/google/common/truth/extensions/proto/LiteProtoSubject.java
|
https://github.com/google/truth/blob/master/extensions/liteproto/src/main/java/com/google/common/truth/extensions/proto/LiteProtoSubject.java
|
Apache-2.0
|
@Deprecated
public void isNotEqualTo(MessageLite.@Nullable Builder builder) {
isNotEqualTo((Object) builder);
}
|
@deprecated A Builder will never compare equal to a MessageLite instance. Use {@code build()},
or {@code buildPartial()} on the argument to get a MessageLite for comparison instead. Or,
if you are passing {@code null}, use {@link #isNotNull()}.
|
isNotEqualTo
|
java
|
google/truth
|
extensions/liteproto/src/main/java/com/google/common/truth/extensions/proto/LiteProtoSubject.java
|
https://github.com/google/truth/blob/master/extensions/liteproto/src/main/java/com/google/common/truth/extensions/proto/LiteProtoSubject.java
|
Apache-2.0
|
public void isEqualToDefaultInstance() {
if (actual == null) {
failWithoutActual(
simpleFact(
lenientFormat(
"Not true that <%s> is a default proto instance. It is null.",
actualCustomStringRepresentationForProtoPackageMembersToCall())));
} else if (!actual.equals(actual.getDefaultInstanceForType())) {
failWithoutActual(
simpleFact(
lenientFormat(
"Not true that <%s> is a default proto instance. It has set values.",
actualCustomStringRepresentationForProtoPackageMembersToCall())));
}
}
|
Checks whether the subject is a {@link MessageLite} with no fields set.
|
isEqualToDefaultInstance
|
java
|
google/truth
|
extensions/liteproto/src/main/java/com/google/common/truth/extensions/proto/LiteProtoSubject.java
|
https://github.com/google/truth/blob/master/extensions/liteproto/src/main/java/com/google/common/truth/extensions/proto/LiteProtoSubject.java
|
Apache-2.0
|
public void isNotEqualToDefaultInstance() {
if (actual != null && actual.equals(actual.getDefaultInstanceForType())) {
failWithoutActual(
simpleFact(
lenientFormat(
"Not true that (%s) <%s> is not a default proto instance. It has no set values.",
actual.getClass().getName(),
actualCustomStringRepresentationForProtoPackageMembersToCall())));
}
}
|
Checks whether the subject is not equivalent to a {@link MessageLite} with no fields set.
|
isNotEqualToDefaultInstance
|
java
|
google/truth
|
extensions/liteproto/src/main/java/com/google/common/truth/extensions/proto/LiteProtoSubject.java
|
https://github.com/google/truth/blob/master/extensions/liteproto/src/main/java/com/google/common/truth/extensions/proto/LiteProtoSubject.java
|
Apache-2.0
|
public void hasAllRequiredFields() {
if (!actual.isInitialized()) {
// MessageLite doesn't support reflection so this is the best we can do.
failWithoutActual(
simpleFact("expected to have all required fields set"),
fact("but was", actualCustomStringRepresentationForProtoPackageMembersToCall()),
simpleFact("(Lite runtime could not determine which fields were missing.)"));
}
}
|
Checks whether the subject has all required fields set. Cannot fail for a proto built with
{@code build()}, which itself fails if required fields aren't set.
|
hasAllRequiredFields
|
java
|
google/truth
|
extensions/liteproto/src/main/java/com/google/common/truth/extensions/proto/LiteProtoSubject.java
|
https://github.com/google/truth/blob/master/extensions/liteproto/src/main/java/com/google/common/truth/extensions/proto/LiteProtoSubject.java
|
Apache-2.0
|
static Optional<Message> unpack(
Message any, TypeRegistry typeRegistry, ExtensionRegistry extensionRegistry) {
Preconditions.checkArgument(
any.getDescriptorForType().equals(Any.getDescriptor()),
"Expected type google.protobuf.Any, but was: %s",
any.getDescriptorForType().getFullName());
String typeUrl = (String) any.getField(typeUrlFieldDescriptor());
ByteString value = (ByteString) any.getField(valueFieldDescriptor());
try {
Descriptor descriptor = typeRegistry.getDescriptorForTypeUrl(typeUrl);
if (descriptor == null) {
return Optional.absent();
}
Message defaultMessage = DynamicMessage.parseFrom(descriptor, value, extensionRegistry);
return Optional.of(defaultMessage);
} catch (InvalidProtocolBufferException e) {
return Optional.absent();
}
}
|
Unpack an `Any` proto using the given TypeRegistry and ExtensionRegistry.
|
unpack
|
java
|
google/truth
|
extensions/proto/src/main/java/com/google/common/truth/extensions/proto/AnyUtils.java
|
https://github.com/google/truth/blob/master/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/AnyUtils.java
|
Apache-2.0
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.