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
@Test @SuppressWarnings("deprecation") // test of an unnecessary use of isEquivalentAccordingToCompareTo public void testNullActual() { expectFailure( whenTesting -> whenTesting.that((Integer) null).isEquivalentAccordingToCompareTo(6)); expectFailure(whenTesting -> whenTesting.that((Integer) null).isGreaterThan(6)); expectFailure(whenTesting -> whenTesting.that((Integer) null).isLessThan(6)); expectFailure(whenTesting -> whenTesting.that((Integer) null).isAtMost(6)); expectFailure(whenTesting -> whenTesting.that((Integer) null).isAtLeast(6)); }
Tests for Comparable Subjects. @author Kurt Alfred Kluever
testNullActual
java
google/truth
core/src/test/java/com/google/common/truth/ComparableSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/ComparableSubjectTest.java
Apache-2.0
@Test // test of a mistaken call and of unnecessary use of isEquivalentAccordingToCompareTo @SuppressWarnings({"deprecation", "IntegerComparison"}) public void testNullExpected() { expectFailure(whenTesting -> whenTesting.that(6).isEquivalentAccordingToCompareTo(null)); expectFailure(whenTesting -> whenTesting.that(6).isGreaterThan(null)); expectFailure(whenTesting -> whenTesting.that(6).isLessThan(null)); expectFailure(whenTesting -> whenTesting.that(6).isAtMost(null)); expectFailure(whenTesting -> whenTesting.that(6).isAtLeast(null)); expectFailure(whenTesting -> whenTesting.that(6).isIn((Range<Integer>) null)); expectFailure(whenTesting -> whenTesting.that(6).isNotIn((Range<Integer>) null)); }
Tests for Comparable Subjects. @author Kurt Alfred Kluever
testNullExpected
java
google/truth
core/src/test/java/com/google/common/truth/ComparableSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/ComparableSubjectTest.java
Apache-2.0
@Test public void isInRange() { Range<Integer> oneToFive = Range.closed(1, 5); assertThat(4).isIn(oneToFive); AssertionError e = expectFailure(whenTesting -> whenTesting.that(6).isIn(oneToFive)); assertThat(e).factValue("expected to be in range").isEqualTo(oneToFive.toString()); }
Tests for Comparable Subjects. @author Kurt Alfred Kluever
isInRange
java
google/truth
core/src/test/java/com/google/common/truth/ComparableSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/ComparableSubjectTest.java
Apache-2.0
@Test public void isNotInRange() { Range<Integer> oneToFive = Range.closed(1, 5); assertThat(6).isNotIn(oneToFive); AssertionError e = expectFailure(whenTesting -> whenTesting.that(4).isNotIn(oneToFive)); assertThat(e).factValue("expected not to be in range").isEqualTo(oneToFive.toString()); }
Tests for Comparable Subjects. @author Kurt Alfred Kluever
isNotInRange
java
google/truth
core/src/test/java/com/google/common/truth/ComparableSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/ComparableSubjectTest.java
Apache-2.0
@Test public void isEquivalentAccordingToCompareTo() { assertThat(new StringComparedByLength("abc")) .isEquivalentAccordingToCompareTo(new StringComparedByLength("xyz")); AssertionError e = expectFailure( whenTesting -> whenTesting .that(new StringComparedByLength("abc")) .isEquivalentAccordingToCompareTo(new StringComparedByLength("abcd"))); assertFailureValue(e, "expected value that sorts equal to", "abcd"); }
Tests for Comparable Subjects. @author Kurt Alfred Kluever
isEquivalentAccordingToCompareTo
java
google/truth
core/src/test/java/com/google/common/truth/ComparableSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/ComparableSubjectTest.java
Apache-2.0
@Override public int compareTo(StringComparedByLength other) { /* * Even though Integer.compare was added in Java 7, we use it even under old versions of * Android, as discussed in IterableSubjectTest. */ return Integer.compare(value.length(), other.value.length()); }
Tests for Comparable Subjects. @author Kurt Alfred Kluever
compareTo
java
google/truth
core/src/test/java/com/google/common/truth/ComparableSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/ComparableSubjectTest.java
Apache-2.0
@Override public String toString() { return value; }
Tests for Comparable Subjects. @author Kurt Alfred Kluever
toString
java
google/truth
core/src/test/java/com/google/common/truth/ComparableSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/ComparableSubjectTest.java
Apache-2.0
@Test public void isGreaterThan_failsEqual() { assertThat(5).isGreaterThan(4); AssertionError e = expectFailure(whenTesting -> whenTesting.that(4).isGreaterThan(4)); assertFailureValue(e, "expected to be greater than", "4"); }
Tests for Comparable Subjects. @author Kurt Alfred Kluever
isGreaterThan_failsEqual
java
google/truth
core/src/test/java/com/google/common/truth/ComparableSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/ComparableSubjectTest.java
Apache-2.0
@Test public void isGreaterThan_failsSmaller() { AssertionError e = expectFailure(whenTesting -> whenTesting.that(3).isGreaterThan(4)); assertFailureValue(e, "expected to be greater than", "4"); }
Tests for Comparable Subjects. @author Kurt Alfred Kluever
isGreaterThan_failsSmaller
java
google/truth
core/src/test/java/com/google/common/truth/ComparableSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/ComparableSubjectTest.java
Apache-2.0
@Test public void isLessThan_failsEqual() { assertThat(4).isLessThan(5); AssertionError e = expectFailure(whenTesting -> whenTesting.that(4).isLessThan(4)); assertFailureValue(e, "expected to be less than", "4"); }
Tests for Comparable Subjects. @author Kurt Alfred Kluever
isLessThan_failsEqual
java
google/truth
core/src/test/java/com/google/common/truth/ComparableSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/ComparableSubjectTest.java
Apache-2.0
@Test public void isLessThan_failsGreater() { AssertionError e = expectFailure(whenTesting -> whenTesting.that(4).isLessThan(3)); assertFailureValue(e, "expected to be less than", "3"); }
Tests for Comparable Subjects. @author Kurt Alfred Kluever
isLessThan_failsGreater
java
google/truth
core/src/test/java/com/google/common/truth/ComparableSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/ComparableSubjectTest.java
Apache-2.0
@Test public void isAtMost() { assertThat(5).isAtMost(5); assertThat(5).isAtMost(6); AssertionError e = expectFailure(whenTesting -> whenTesting.that(4).isAtMost(3)); assertFailureValue(e, "expected to be at most", "3"); }
Tests for Comparable Subjects. @author Kurt Alfred Kluever
isAtMost
java
google/truth
core/src/test/java/com/google/common/truth/ComparableSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/ComparableSubjectTest.java
Apache-2.0
@Test public void isAtLeast() { assertThat(4).isAtLeast(3); assertThat(4).isAtLeast(4); AssertionError e = expectFailure(whenTesting -> whenTesting.that(4).isAtLeast(5)); assertFailureValue(e, "expected to be at least", "5"); }
Tests for Comparable Subjects. @author Kurt Alfred Kluever
isAtLeast
java
google/truth
core/src/test/java/com/google/common/truth/ComparableSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/ComparableSubjectTest.java
Apache-2.0
@Test public void longs() { assertThat(5L).isGreaterThan(4L); assertThat(4L).isLessThan(5L); assertThat(4L).isAtMost(4L); assertThat(4L).isAtMost(5L); assertThat(4L).isAtLeast(4L); assertThat(4L).isAtLeast(3L); Range<Long> range = Range.closed(2L, 4L); assertThat(3L).isIn(range); assertThat(5L).isNotIn(range); }
Tests for Comparable Subjects. @author Kurt Alfred Kluever
longs
java
google/truth
core/src/test/java/com/google/common/truth/ComparableSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/ComparableSubjectTest.java
Apache-2.0
@Test public void strings() { assertThat("kak").isGreaterThan("gak"); assertThat("gak").isLessThan("kak"); assertThat("kak").isAtMost("kak"); assertThat("gak").isAtMost("kak"); assertThat("kak").isAtLeast("kak"); assertThat("kak").isAtLeast("gak"); Range<String> range = Range.closed("a", "c"); assertThat("b").isIn(range); assertThat("d").isNotIn(range); }
Tests for Comparable Subjects. @author Kurt Alfred Kluever
strings
java
google/truth
core/src/test/java/com/google/common/truth/ComparableSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/ComparableSubjectTest.java
Apache-2.0
@Test public void comparableType() { assertThat(new ComparableType(4)).isGreaterThan(new ComparableType(3)); assertThat(new ComparableType(3)).isLessThan(new ComparableType(4)); }
Tests for Comparable Subjects. @author Kurt Alfred Kluever
comparableType
java
google/truth
core/src/test/java/com/google/common/truth/ComparableSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/ComparableSubjectTest.java
Apache-2.0
@Test public void namedComparableType() { assertWithMessage("comparable").that(new ComparableType(2)).isLessThan(new ComparableType(3)); }
Tests for Comparable Subjects. @author Kurt Alfred Kluever
namedComparableType
java
google/truth
core/src/test/java/com/google/common/truth/ComparableSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/ComparableSubjectTest.java
Apache-2.0
@Override public int compareTo(ComparableType other) { return wrapped - other.wrapped; }
Tests for Comparable Subjects. @author Kurt Alfred Kluever
compareTo
java
google/truth
core/src/test/java/com/google/common/truth/ComparableSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/ComparableSubjectTest.java
Apache-2.0
@Test public void rawComparableType() { assertThat(new RawComparableType(3)).isLessThan(new RawComparableType(4)); }
Tests for Comparable Subjects. @author Kurt Alfred Kluever
rawComparableType
java
google/truth
core/src/test/java/com/google/common/truth/ComparableSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/ComparableSubjectTest.java
Apache-2.0
@Override public int compareTo(Object other) { return wrapped - ((RawComparableType) other).wrapped; }
Tests for Comparable Subjects. @author Kurt Alfred Kluever
compareTo
java
google/truth
core/src/test/java/com/google/common/truth/ComparableSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/ComparableSubjectTest.java
Apache-2.0
@Override public String toString() { return Integer.toString(wrapped); }
Tests for Comparable Subjects. @author Kurt Alfred Kluever
toString
java
google/truth
core/src/test/java/com/google/common/truth/ComparableSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/ComparableSubjectTest.java
Apache-2.0
@Test public void hasCompareException_empty() { Correspondence.ExceptionStore exceptions = Correspondence.ExceptionStore.forIterable(); assertThat(exceptions.hasCompareException()).isFalse(); }
Tests for {@link Correspondence.ExceptionStore}. <p>These should not be run under j2cl, because the descriptions don't include the expected stack traces there. @author Pete Gillin
hasCompareException_empty
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 public void hasCompareException_hasCompareException() { Correspondence.ExceptionStore exceptions = Correspondence.ExceptionStore.forIterable(); addCompareException(exceptions); assertThat(exceptions.hasCompareException()).isTrue(); }
Tests for {@link Correspondence.ExceptionStore}. <p>These should not be run under j2cl, because the descriptions don't include the expected stack traces there. @author Pete Gillin
hasCompareException_hasCompareException
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 public void describeAsMainCause_empty() { Correspondence.ExceptionStore exceptions = Correspondence.ExceptionStore.forIterable(); assertThrows(IllegalStateException.class, () -> exceptions.describeAsMainCause()); }
Tests for {@link Correspondence.ExceptionStore}. <p>These should not be run under j2cl, because the descriptions don't include the expected stack traces there. @author Pete Gillin
describeAsMainCause_empty
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 public void describeAsMainCause_notEmpty() { Correspondence.ExceptionStore exceptions = Correspondence.ExceptionStore.forIterable(); addCompareException(exceptions); assertExpectedFacts( exceptions.describeAsMainCause(), "one or more exceptions were thrown while comparing elements"); }
Tests for {@link Correspondence.ExceptionStore}. <p>These should not be run under j2cl, because the descriptions don't include the expected stack traces there. @author Pete Gillin
describeAsMainCause_notEmpty
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 public void describeAsAdditionalInfo_empty() { Correspondence.ExceptionStore exceptions = Correspondence.ExceptionStore.forIterable(); assertThat(exceptions.describeAsAdditionalInfo()).isEmpty(); }
Tests for {@link Correspondence.ExceptionStore}. <p>These should not be run under j2cl, because the descriptions don't include the expected stack traces there. @author Pete Gillin
describeAsAdditionalInfo_empty
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 public void describeAsAdditionalInfo_notEmpty() { Correspondence.ExceptionStore exceptions = Correspondence.ExceptionStore.forIterable(); addCompareException(exceptions); assertExpectedFacts( exceptions.describeAsAdditionalInfo(), "additionally, one or more exceptions were thrown while comparing elements"); }
Tests for {@link Correspondence.ExceptionStore}. <p>These should not be run under j2cl, because the descriptions don't include the expected stack traces there. @author Pete Gillin
describeAsAdditionalInfo_notEmpty
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 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("deprecation") // testing deprecated method public void testEquals_throws() { assertThrows(UnsupportedOperationException.class, () -> INSTANCE.equals(new Object())); }
Tests for {@link Correspondence}. @author Pete Gillin
testEquals_throws
java
google/truth
core/src/test/java/com/google/common/truth/CorrespondenceTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/CorrespondenceTest.java
Apache-2.0
@Test @SuppressWarnings("deprecation") // testing deprecated method public void testHashCode_throws() { assertThrows(UnsupportedOperationException.class, () -> INSTANCE.hashCode()); }
Tests for {@link Correspondence}. @author Pete Gillin
testHashCode_throws
java
google/truth
core/src/test/java/com/google/common/truth/CorrespondenceTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/CorrespondenceTest.java
Apache-2.0
@Test public void testFrom_compare() { assertThat(STRING_PREFIX_EQUALITY.compare("foot", "foo")).isTrue(); assertThat(STRING_PREFIX_EQUALITY.compare("foot", "foot")).isTrue(); assertThat(STRING_PREFIX_EQUALITY.compare("foo", "foot")).isFalse(); }
Tests for {@link Correspondence}. @author Pete Gillin
testFrom_compare
java
google/truth
core/src/test/java/com/google/common/truth/CorrespondenceTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/CorrespondenceTest.java
Apache-2.0
@Test public void testFrom_formatDiff() { assertThat(STRING_PREFIX_EQUALITY.formatDiff("foo", "foot")).isNull(); }
Tests for {@link Correspondence}. @author Pete Gillin
testFrom_formatDiff
java
google/truth
core/src/test/java/com/google/common/truth/CorrespondenceTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/CorrespondenceTest.java
Apache-2.0
@Test public void testFrom_toString() { assertThat(STRING_PREFIX_EQUALITY.toString()).isEqualTo("starts with"); }
Tests for {@link Correspondence}. @author Pete Gillin
testFrom_toString
java
google/truth
core/src/test/java/com/google/common/truth/CorrespondenceTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/CorrespondenceTest.java
Apache-2.0
@Test public void testFrom_isEquality() { assertThat(STRING_PREFIX_EQUALITY.isEquality()).isFalse(); }
Tests for {@link Correspondence}. @author Pete Gillin
testFrom_isEquality
java
google/truth
core/src/test/java/com/google/common/truth/CorrespondenceTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/CorrespondenceTest.java
Apache-2.0
@Test public void testFrom_viaIterableSubjectContainsExactly_success() { assertThat(ImmutableList.of("foot", "barn")) .comparingElementsUsing(STRING_PREFIX_EQUALITY) .containsExactly("foo", "bar"); }
Tests for {@link Correspondence}. @author Pete Gillin
testFrom_viaIterableSubjectContainsExactly_success
java
google/truth
core/src/test/java/com/google/common/truth/CorrespondenceTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/CorrespondenceTest.java
Apache-2.0
@Test public void testFrom_viaIterableSubjectContainsExactly_failure() { AssertionError e = expectFailure( whenTesting -> whenTesting .that(ImmutableList.of("foot", "barn", "gallon")) .comparingElementsUsing(STRING_PREFIX_EQUALITY) .containsExactly("foo", "bar")); assertFailureKeys(e, "unexpected (1)", "---", "expected", "testing whether", "but was"); assertFailureValue(e, "unexpected (1)", "gallon"); assertFailureValue(e, "testing whether", "actual element starts with expected element"); }
Tests for {@link Correspondence}. @author Pete Gillin
testFrom_viaIterableSubjectContainsExactly_failure
java
google/truth
core/src/test/java/com/google/common/truth/CorrespondenceTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/CorrespondenceTest.java
Apache-2.0
@Test public void testFrom_viaIterableSubjectContainsExactly_null() { AssertionError e = expectFailure( whenTesting -> whenTesting .that(asList("foot", "barn", null)) .comparingElementsUsing(STRING_PREFIX_EQUALITY) .containsExactly("foo", "bar")); assertFailureKeys( e, "unexpected (1)", "---", "expected", "testing whether", "but was", "additionally, one or more exceptions were thrown while comparing elements", "first exception"); assertFailureValue(e, "unexpected (1)", "null"); assertThat(e) .factValue("first exception") .startsWith("compare(null, foo) threw java.lang.NullPointerException"); }
Tests for {@link Correspondence}. @author Pete Gillin
testFrom_viaIterableSubjectContainsExactly_null
java
google/truth
core/src/test/java/com/google/common/truth/CorrespondenceTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/CorrespondenceTest.java
Apache-2.0
@Test public void testTransforming_actual_compare() { assertThat(LENGTHS.compare("foo", 3)).isTrue(); assertThat(LENGTHS.compare("foot", 4)).isTrue(); assertThat(LENGTHS.compare("foo", 4)).isFalse(); }
Tests for {@link Correspondence}. @author Pete Gillin
testTransforming_actual_compare
java
google/truth
core/src/test/java/com/google/common/truth/CorrespondenceTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/CorrespondenceTest.java
Apache-2.0
@Test public void testTransforming_actual_compare_nullTransformedValues() { assertThat(HYPHEN_INDEXES.compare("mailing-list", null)).isFalse(); assertThat(HYPHEN_INDEXES.compare("forum", 7)).isFalse(); assertThat(HYPHEN_INDEXES.compare("forum", null)).isTrue(); }
Tests for {@link Correspondence}. @author Pete Gillin
testTransforming_actual_compare_nullTransformedValues
java
google/truth
core/src/test/java/com/google/common/truth/CorrespondenceTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/CorrespondenceTest.java
Apache-2.0
@Test public void testTransforming_actual_compare_nullActualValue() { assertThrows(NullPointerException.class, () -> HYPHEN_INDEXES.compare(null, 7)); }
Tests for {@link Correspondence}. @author Pete Gillin
testTransforming_actual_compare_nullActualValue
java
google/truth
core/src/test/java/com/google/common/truth/CorrespondenceTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/CorrespondenceTest.java
Apache-2.0
@Test public void testTransforming_actual_formatDiff() { assertThat(LENGTHS.formatDiff("foo", 4)).isNull(); }
Tests for {@link Correspondence}. @author Pete Gillin
testTransforming_actual_formatDiff
java
google/truth
core/src/test/java/com/google/common/truth/CorrespondenceTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/CorrespondenceTest.java
Apache-2.0
@Test public void testTransforming_actual_toString() { assertThat(LENGTHS.toString()).isEqualTo("has a length of"); }
Tests for {@link Correspondence}. @author Pete Gillin
testTransforming_actual_toString
java
google/truth
core/src/test/java/com/google/common/truth/CorrespondenceTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/CorrespondenceTest.java
Apache-2.0
@Test public void testTransforming_actual_isEquality() { assertThat(LENGTHS.isEquality()).isFalse(); }
Tests for {@link Correspondence}. @author Pete Gillin
testTransforming_actual_isEquality
java
google/truth
core/src/test/java/com/google/common/truth/CorrespondenceTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/CorrespondenceTest.java
Apache-2.0
@Test public void testTransforming_actual_viaIterableSubjectContainsExactly_success() { assertThat(ImmutableList.of("feet", "barns", "gallons")) .comparingElementsUsing(LENGTHS) .containsExactly(4, 5, 7) .inOrder(); }
Tests for {@link Correspondence}. @author Pete Gillin
testTransforming_actual_viaIterableSubjectContainsExactly_success
java
google/truth
core/src/test/java/com/google/common/truth/CorrespondenceTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/CorrespondenceTest.java
Apache-2.0
@Test public void testTransforming_actual_viaIterableSubjectContainsExactly_failure() { AssertionError e = expectFailure( whenTesting -> whenTesting .that(ImmutableList.of("feet", "barns", "gallons")) .comparingElementsUsing(LENGTHS) .containsExactly(4, 5)); assertFailureKeys(e, "unexpected (1)", "---", "expected", "testing whether", "but was"); assertFailureValue(e, "unexpected (1)", "gallons"); assertFailureValue(e, "testing whether", "actual element has a length of expected element"); }
Tests for {@link Correspondence}. @author Pete Gillin
testTransforming_actual_viaIterableSubjectContainsExactly_failure
java
google/truth
core/src/test/java/com/google/common/truth/CorrespondenceTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/CorrespondenceTest.java
Apache-2.0
@Test public void testTransforming_actual_viaIterableSubjectContainsExactly_nullActual() { AssertionError e = expectFailure( whenTesting -> whenTesting .that(asList("feet", "barns", null)) .comparingElementsUsing(LENGTHS) .containsExactly(4, 5)); assertFailureKeys( e, "unexpected (1)", "---", "expected", "testing whether", "but was", "additionally, one or more exceptions were thrown while comparing elements", "first exception"); assertFailureValue(e, "unexpected (1)", "null"); assertThat(e) .factValue("first exception") .startsWith("compare(null, 4) threw java.lang.NullPointerException"); }
Tests for {@link Correspondence}. @author Pete Gillin
testTransforming_actual_viaIterableSubjectContainsExactly_nullActual
java
google/truth
core/src/test/java/com/google/common/truth/CorrespondenceTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/CorrespondenceTest.java
Apache-2.0
@Test public void testTransforming_actual_viaIterableSubjectContainsExactly_nullTransformed() { // "mailing-list" and "chat-room" have hyphens at index 7 and 4 respectively. // "forum" contains no hyphen so the Function in HYPHEN_INDEXES transforms it to null. assertThat(ImmutableList.of("mailing-list", "chat-room", "forum")) .comparingElementsUsing(HYPHEN_INDEXES) .containsExactly(7, 4, null) .inOrder(); }
Tests for {@link Correspondence}. @author Pete Gillin
testTransforming_actual_viaIterableSubjectContainsExactly_nullTransformed
java
google/truth
core/src/test/java/com/google/common/truth/CorrespondenceTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/CorrespondenceTest.java
Apache-2.0
@Test public void testTransforming_both_compare() { assertThat(HYPHENS_MATCH_COLONS.compare("mailing-list", "abcdefg:hij")).isTrue(); assertThat(HYPHENS_MATCH_COLONS.compare("chat-room", "abcd:efghij")).isTrue(); assertThat(HYPHENS_MATCH_COLONS.compare("chat-room", "abcdefg:hij")).isFalse(); }
Tests for {@link Correspondence}. @author Pete Gillin
testTransforming_both_compare
java
google/truth
core/src/test/java/com/google/common/truth/CorrespondenceTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/CorrespondenceTest.java
Apache-2.0
@Test public void testTransforming_both_compare_nullTransformedValue() { assertThat(HYPHENS_MATCH_COLONS.compare("mailing-list", "abcdefg-hij")).isFalse(); assertThat(HYPHENS_MATCH_COLONS.compare("forum", "abcde:fghij")).isFalse(); assertThat(HYPHENS_MATCH_COLONS.compare("forum", "abcde-fghij")).isTrue(); }
Tests for {@link Correspondence}. @author Pete Gillin
testTransforming_both_compare_nullTransformedValue
java
google/truth
core/src/test/java/com/google/common/truth/CorrespondenceTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/CorrespondenceTest.java
Apache-2.0
@Test public void testTransforming_both_compare_nullInputValues() { assertThrows( NullPointerException.class, () -> HYPHENS_MATCH_COLONS.compare(null, "abcde:fghij")); assertThrows( NullPointerException.class, () -> HYPHENS_MATCH_COLONS.compare("mailing-list", null)); }
Tests for {@link Correspondence}. @author Pete Gillin
testTransforming_both_compare_nullInputValues
java
google/truth
core/src/test/java/com/google/common/truth/CorrespondenceTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/CorrespondenceTest.java
Apache-2.0
@Test public void testTransforming_both_formatDiff() { assertThat(HYPHENS_MATCH_COLONS.formatDiff("chat-room", "abcdefg:hij")).isNull(); }
Tests for {@link Correspondence}. @author Pete Gillin
testTransforming_both_formatDiff
java
google/truth
core/src/test/java/com/google/common/truth/CorrespondenceTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/CorrespondenceTest.java
Apache-2.0
@Test public void testTransforming_both_toString() { assertThat(HYPHENS_MATCH_COLONS.toString()) .isEqualTo("has a hyphen at the same index as the colon in"); }
Tests for {@link Correspondence}. @author Pete Gillin
testTransforming_both_toString
java
google/truth
core/src/test/java/com/google/common/truth/CorrespondenceTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/CorrespondenceTest.java
Apache-2.0
@Test public void testTransforming_both_isEquality() { assertThat(HYPHENS_MATCH_COLONS.isEquality()).isFalse(); }
Tests for {@link Correspondence}. @author Pete Gillin
testTransforming_both_isEquality
java
google/truth
core/src/test/java/com/google/common/truth/CorrespondenceTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/CorrespondenceTest.java
Apache-2.0
@Test public void testTransforming_both_viaIterableSubjectContainsExactly_success() { assertThat(ImmutableList.of("mailing-list", "chat-room", "web-app")) .comparingElementsUsing(HYPHENS_MATCH_COLONS) .containsExactly("abcdefg:hij", "abcd:efghij", "abc:defghij") .inOrder(); }
Tests for {@link Correspondence}. @author Pete Gillin
testTransforming_both_viaIterableSubjectContainsExactly_success
java
google/truth
core/src/test/java/com/google/common/truth/CorrespondenceTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/CorrespondenceTest.java
Apache-2.0
@Test public void testTransforming_both_viaIterableSubjectContainsExactly_failure() { AssertionError e = expectFailure( whenTesting -> whenTesting .that(ImmutableList.of("mailing-list", "chat-room", "web-app")) .comparingElementsUsing(HYPHENS_MATCH_COLONS) .containsExactly("abcdefg:hij", "abcd:efghij")); assertFailureKeys(e, "unexpected (1)", "---", "expected", "testing whether", "but was"); assertFailureValue(e, "unexpected (1)", "web-app"); assertFailureValue( e, "testing whether", "actual element has a hyphen at the same index as the colon in expected element"); }
Tests for {@link Correspondence}. @author Pete Gillin
testTransforming_both_viaIterableSubjectContainsExactly_failure
java
google/truth
core/src/test/java/com/google/common/truth/CorrespondenceTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/CorrespondenceTest.java
Apache-2.0
@Test public void testTransforming_both_viaIterableSubjectContainsExactly_nullActual() { AssertionError e = expectFailure( whenTesting -> whenTesting .that(asList("mailing-list", "chat-room", null)) .comparingElementsUsing(HYPHENS_MATCH_COLONS) .containsExactly("abcdefg:hij", "abcd:efghij")); assertFailureKeys( e, "unexpected (1)", "---", "expected", "testing whether", "but was", "additionally, one or more exceptions were thrown while comparing elements", "first exception"); assertFailureValue(e, "unexpected (1)", "null"); assertThat(e) .factValue("first exception") .startsWith("compare(null, abcdefg:hij) threw java.lang.NullPointerException"); }
Tests for {@link Correspondence}. @author Pete Gillin
testTransforming_both_viaIterableSubjectContainsExactly_nullActual
java
google/truth
core/src/test/java/com/google/common/truth/CorrespondenceTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/CorrespondenceTest.java
Apache-2.0
@Test public void testTransforming_both_viaIterableSubjectContainsExactly_nullExpected() { AssertionError e = expectFailure( whenTesting -> whenTesting .that(ImmutableList.of("mailing-list", "chat-room")) .comparingElementsUsing(HYPHENS_MATCH_COLONS) .containsExactly("abcdefg:hij", "abcd:efghij", null)); assertFailureKeys( e, "missing (1)", "---", "expected", "testing whether", "but was", "additionally, one or more exceptions were thrown while comparing elements", "first exception"); assertFailureValue(e, "missing (1)", "null"); assertThat(e) .factValue("first exception") .startsWith("compare(mailing-list, null) threw java.lang.NullPointerException"); }
Tests for {@link Correspondence}. @author Pete Gillin
testTransforming_both_viaIterableSubjectContainsExactly_nullExpected
java
google/truth
core/src/test/java/com/google/common/truth/CorrespondenceTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/CorrespondenceTest.java
Apache-2.0
@Test public void testTransforming_both_viaIterableSubjectContainsExactly_nullTransformed() { // The actual element "forum" contains no hyphen, and the expected element "abcde-fghij" // contains no colon, so they both transform to null, and so they correspond. assertThat(ImmutableList.of("mailing-list", "chat-room", "forum")) .comparingElementsUsing(HYPHENS_MATCH_COLONS) .containsExactly("abcdefg:hij", "abcd:efghij", "abcde-fghij") .inOrder(); }
Tests for {@link Correspondence}. @author Pete Gillin
testTransforming_both_viaIterableSubjectContainsExactly_nullTransformed
java
google/truth
core/src/test/java/com/google/common/truth/CorrespondenceTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/CorrespondenceTest.java
Apache-2.0
@Test public void testTolerance_compare_doubles() { assertThat(tolerance(0.0).compare(2.0, 2.0)).isTrue(); assertThat(tolerance(0.00001).compare(2.0, 2.0)).isTrue(); assertThat(tolerance(1000.0).compare(2.0, 2.0)).isTrue(); assertThat(tolerance(1.00001).compare(2.0, 3.0)).isTrue(); assertThat(tolerance(1000.0).compare(2.0, 1003.0)).isFalse(); assertThat(tolerance(1000.0).compare(2.0, Double.POSITIVE_INFINITY)).isFalse(); assertThat(tolerance(1000.0).compare(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY)) .isFalse(); assertThat(tolerance(1000.0).compare(2.0, Double.NaN)).isFalse(); assertThat(tolerance(1000.0).compare(Double.NaN, Double.NaN)).isFalse(); assertThat(tolerance(0.0).compare(-0.0, 0.0)).isTrue(); }
Tests for {@link Correspondence}. @author Pete Gillin
testTolerance_compare_doubles
java
google/truth
core/src/test/java/com/google/common/truth/CorrespondenceTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/CorrespondenceTest.java
Apache-2.0
@Test public void testTolerance_compare_floats() { assertThat(tolerance(0.0).compare(2.0f, 2.0f)).isTrue(); assertThat(tolerance(0.00001).compare(2.0f, 2.0f)).isTrue(); assertThat(tolerance(1000.0).compare(2.0f, 2.0f)).isTrue(); assertThat(tolerance(1.00001).compare(2.0f, 3.0f)).isTrue(); assertThat(tolerance(1000.0).compare(2.0f, 1003.0f)).isFalse(); assertThat(tolerance(1000.0).compare(2.0f, Float.POSITIVE_INFINITY)).isFalse(); assertThat(tolerance(1000.0).compare(Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY)) .isFalse(); assertThat(tolerance(1000.0).compare(2.0f, Float.NaN)).isFalse(); assertThat(tolerance(1000.0).compare(Float.NaN, Float.NaN)).isFalse(); assertThat(tolerance(0.0).compare(-0.0f, 0.0f)).isTrue(); }
Tests for {@link Correspondence}. @author Pete Gillin
testTolerance_compare_floats
java
google/truth
core/src/test/java/com/google/common/truth/CorrespondenceTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/CorrespondenceTest.java
Apache-2.0
@Test public void testTolerance_compare_doublesVsInts() { assertThat(tolerance(0.0).compare(2.0, 2)).isTrue(); assertThat(tolerance(0.00001).compare(2.0, 2)).isTrue(); assertThat(tolerance(1000.0).compare(2.0, 2)).isTrue(); assertThat(tolerance(1.00001).compare(2.0, 3)).isTrue(); assertThat(tolerance(1000.0).compare(2.0, 1003)).isFalse(); }
Tests for {@link Correspondence}. @author Pete Gillin
testTolerance_compare_doublesVsInts
java
google/truth
core/src/test/java/com/google/common/truth/CorrespondenceTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/CorrespondenceTest.java
Apache-2.0
@Test public void testTolerance_compare_negativeTolerance() { IllegalArgumentException expected = assertThrows(IllegalArgumentException.class, () -> tolerance(-0.05).compare(1.0, 2.0)); assertThat(expected).hasMessageThat().isEqualTo("tolerance (-0.05) cannot be negative"); }
Tests for {@link Correspondence}. @author Pete Gillin
testTolerance_compare_negativeTolerance
java
google/truth
core/src/test/java/com/google/common/truth/CorrespondenceTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/CorrespondenceTest.java
Apache-2.0
@Test public void testTolerance_compare_null() { assertThrows(NullPointerException.class, () -> tolerance(0.05).compare(1.0, null)); assertThrows(NullPointerException.class, () -> tolerance(0.05).compare(null, 2.0)); }
Tests for {@link Correspondence}. @author Pete Gillin
testTolerance_compare_null
java
google/truth
core/src/test/java/com/google/common/truth/CorrespondenceTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/CorrespondenceTest.java
Apache-2.0
@Test public void testTolerance_formatDiff() { assertThat(tolerance(0.01).formatDiff(1.0, 2.0)).isNull(); }
Tests for {@link Correspondence}. @author Pete Gillin
testTolerance_formatDiff
java
google/truth
core/src/test/java/com/google/common/truth/CorrespondenceTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/CorrespondenceTest.java
Apache-2.0
@Test public void testTolerance_toString() { assertThat(tolerance(0.01).toString()).isEqualTo("is a finite number within 0.01 of"); }
Tests for {@link Correspondence}. @author Pete Gillin
testTolerance_toString
java
google/truth
core/src/test/java/com/google/common/truth/CorrespondenceTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/CorrespondenceTest.java
Apache-2.0
@Test public void testTolerance_isEquality() { assertThat(tolerance(0.01).isEquality()).isFalse(); // This is close to equality, but not close enough (it calls numbers of different types equal): assertThat(tolerance(0.0).isEquality()).isFalse(); }
Tests for {@link Correspondence}. @author Pete Gillin
testTolerance_isEquality
java
google/truth
core/src/test/java/com/google/common/truth/CorrespondenceTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/CorrespondenceTest.java
Apache-2.0
@Test public void testTolerance_viaIterableSubjectContains_success() { assertThat(ImmutableList.of(1.02, 2.04, 3.08)) .comparingElementsUsing(tolerance(0.05)) .contains(2.0); }
Tests for {@link Correspondence}. @author Pete Gillin
testTolerance_viaIterableSubjectContains_success
java
google/truth
core/src/test/java/com/google/common/truth/CorrespondenceTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/CorrespondenceTest.java
Apache-2.0
@Test public void testTolerance_viaIterableSubjectContains_failure() { AssertionError e = expectFailure( whenTesting -> whenTesting .that(ImmutableList.of(1.02, 2.04, 3.08)) .comparingElementsUsing(tolerance(0.05)) .contains(3.01)); assertFailureKeys(e, "expected to contain", "testing whether", "but was"); assertFailureValue(e, "expected to contain", "3.01"); assertFailureValue( e, "testing whether", "actual element is a finite number within 0.05 of expected element"); assertFailureValue(e, "but was", "[1.02, 2.04, 3.08]"); }
Tests for {@link Correspondence}. @author Pete Gillin
testTolerance_viaIterableSubjectContains_failure
java
google/truth
core/src/test/java/com/google/common/truth/CorrespondenceTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/CorrespondenceTest.java
Apache-2.0
@Test public void testEquality_compare() { assertThat(equality().compare("foo", "foo")).isTrue(); assertThat(equality().compare("foo", "bar")).isFalse(); assertThat(equality().compare(123, 123)).isTrue(); assertThat(equality().compare(123, 123L)).isFalse(); assertThat(equality().compare(null, null)).isTrue(); assertThat(equality().compare(null, "bar")).isFalse(); }
Tests for {@link Correspondence}. @author Pete Gillin
testEquality_compare
java
google/truth
core/src/test/java/com/google/common/truth/CorrespondenceTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/CorrespondenceTest.java
Apache-2.0
@Test public void testEquality_formatDiff() { assertThat(equality().formatDiff("foo", "bar")).isNull(); }
Tests for {@link Correspondence}. @author Pete Gillin
testEquality_formatDiff
java
google/truth
core/src/test/java/com/google/common/truth/CorrespondenceTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/CorrespondenceTest.java
Apache-2.0
@Test public void testEquality_toString() { assertThat(equality().toString()).isEqualTo("is equal to"); // meta! }
Tests for {@link Correspondence}. @author Pete Gillin
testEquality_toString
java
google/truth
core/src/test/java/com/google/common/truth/CorrespondenceTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/CorrespondenceTest.java
Apache-2.0
@Test public void testEquality_isEquality() { assertThat(equality().isEquality()).isTrue(); }
Tests for {@link Correspondence}. @author Pete Gillin
testEquality_isEquality
java
google/truth
core/src/test/java/com/google/common/truth/CorrespondenceTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/CorrespondenceTest.java
Apache-2.0
@Test public void testEquality_viaIterableSubjectContains_success() { assertThat(ImmutableList.of(1.0, 2.0, 3.0)).comparingElementsUsing(equality()).contains(2.0); }
Tests for {@link Correspondence}. @author Pete Gillin
testEquality_viaIterableSubjectContains_success
java
google/truth
core/src/test/java/com/google/common/truth/CorrespondenceTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/CorrespondenceTest.java
Apache-2.0
@Test public void testEquality_viaIterableSubjectContains_failure() { AssertionError e = expectFailure( whenTesting -> whenTesting .that(ImmutableList.of(1.01, 2.02, 3.03)) .comparingElementsUsing(equality()) .contains(2.0)); // N.B. No "testing whether" fact: assertFailureKeys(e, "expected to contain", "but was"); }
Tests for {@link Correspondence}. @author Pete Gillin
testEquality_viaIterableSubjectContains_failure
java
google/truth
core/src/test/java/com/google/common/truth/CorrespondenceTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/CorrespondenceTest.java
Apache-2.0
@Test public void testFormattingDiffsUsing_compare() { // The compare behaviour should be the same as the wrapped correspondence. assertThat(LENGTHS_WITH_DIFF.compare("foo", 3)).isTrue(); assertThat(LENGTHS_WITH_DIFF.compare("foot", 4)).isTrue(); assertThat(LENGTHS_WITH_DIFF.compare("foo", 4)).isFalse(); }
Tests for {@link Correspondence}. @author Pete Gillin
testFormattingDiffsUsing_compare
java
google/truth
core/src/test/java/com/google/common/truth/CorrespondenceTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/CorrespondenceTest.java
Apache-2.0
@Test public void testFormattingDiffsUsing_formatDiff() { assertThat(LENGTHS_WITH_DIFF.formatDiff("foo", 4)).isEqualTo("-1"); assertThat(LENGTHS_WITH_DIFF.formatDiff("foot", 3)).isEqualTo("1"); }
Tests for {@link Correspondence}. @author Pete Gillin
testFormattingDiffsUsing_formatDiff
java
google/truth
core/src/test/java/com/google/common/truth/CorrespondenceTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/CorrespondenceTest.java
Apache-2.0
@Test public void testFormattingDiffsUsing_toString() { // The toString behaviour should be the same as the wrapped correspondence. assertThat(LENGTHS_WITH_DIFF.toString()).isEqualTo("has a length of"); }
Tests for {@link Correspondence}. @author Pete Gillin
testFormattingDiffsUsing_toString
java
google/truth
core/src/test/java/com/google/common/truth/CorrespondenceTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/CorrespondenceTest.java
Apache-2.0
@Test public void testFormattingDiffsUsing_isEquality() { // The isEquality behaviour should be the same as the wrapped correspondence. assertThat(LENGTHS_WITH_DIFF.isEquality()).isFalse(); Correspondence<Integer, Integer> equalityWithDiffFormatter = Correspondence.<Integer>equality().formattingDiffsUsing(INT_DIFF_FORMATTER); assertThat(equalityWithDiffFormatter.isEquality()).isTrue(); }
Tests for {@link Correspondence}. @author Pete Gillin
testFormattingDiffsUsing_isEquality
java
google/truth
core/src/test/java/com/google/common/truth/CorrespondenceTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/CorrespondenceTest.java
Apache-2.0
@Test public void testFormattingDiffsUsing_viaIterableSubjectContainsExactly_failure() { AssertionError e = expectFailure( whenTesting -> whenTesting .that(ImmutableList.of("feet", "gallons")) .comparingElementsUsing(LENGTHS_WITH_DIFF) .containsExactly(4, 5)); assertFailureKeys( e, "missing (1)", "unexpected (1)", "#1", "diff", "---", "expected", "testing whether", "but was"); assertFailureValue(e, "missing (1)", "5"); assertFailureValue(e, "#1", "gallons"); assertFailureValue(e, "diff", "2"); }
Tests for {@link Correspondence}. @author Pete Gillin
testFormattingDiffsUsing_viaIterableSubjectContainsExactly_failure
java
google/truth
core/src/test/java/com/google/common/truth/CorrespondenceTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/CorrespondenceTest.java
Apache-2.0
@Test public void testFormattingDiffsUsing_viaIterableSubjectContainsExactly_nullActual() { AssertionError e = expectFailure( whenTesting -> whenTesting .that(asList("feet", null)) .comparingElementsUsing(LENGTHS_WITH_DIFF) .containsExactly(4, 5)); assertFailureKeys( e, "missing (1)", "unexpected (1)", "---", "expected", "testing whether", "but was", "additionally, one or more exceptions were thrown while comparing elements", "first exception", "additionally, one or more exceptions were thrown while formatting diffs", "first exception"); assertFailureValue(e, "missing (1)", "5"); assertFailureValue(e, "unexpected (1)", "[null]"); assertThat(e) .factValue("first exception", 0) .startsWith("compare(null, 4) threw java.lang.NullPointerException"); assertThat(e) .factValue("first exception", 1) .startsWith("formatDiff(null, 5) threw java.lang.NullPointerException"); }
Tests for {@link Correspondence}. @author Pete Gillin
testFormattingDiffsUsing_viaIterableSubjectContainsExactly_nullActual
java
google/truth
core/src/test/java/com/google/common/truth/CorrespondenceTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/CorrespondenceTest.java
Apache-2.0
@Test public void assertWithMessageThat() { AssertionError e = expectFailure( whenTesting -> whenTesting.withMessage("This is a custom message").that(false).isTrue()); assertThat(e).hasMessageThat().startsWith("This is a custom message\n"); }
Tests (and effectively sample code) for custom error message for checks. @author Christian Gruber ([email protected])
assertWithMessageThat
java
google/truth
core/src/test/java/com/google/common/truth/CustomFailureMessageTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/CustomFailureMessageTest.java
Apache-2.0
@Test public void countPlaceholders() { assertThat(LazyMessage.countPlaceholders("")).isEqualTo(0); assertThat(LazyMessage.countPlaceholders("%s")).isEqualTo(1); assertThat(LazyMessage.countPlaceholders("%s%s")).isEqualTo(2); assertThat(LazyMessage.countPlaceholders("%s%%s")).isEqualTo(2); assertThat(LazyMessage.countPlaceholders("hello")).isEqualTo(0); assertThat(LazyMessage.countPlaceholders("%shello")).isEqualTo(1); assertThat(LazyMessage.countPlaceholders("hello%s")).isEqualTo(1); assertThat(LazyMessage.countPlaceholders("hel%slo")).isEqualTo(1); assertThat(LazyMessage.countPlaceholders("hel%%slo")).isEqualTo(1); assertThat(LazyMessage.countPlaceholders("hel%s%slo")).isEqualTo(2); assertThat(LazyMessage.countPlaceholders("%shel%s%slo")).isEqualTo(3); assertThat(LazyMessage.countPlaceholders("hel%s%slo%s")).isEqualTo(3); }
Tests (and effectively sample code) for custom error message for checks. @author Christian Gruber ([email protected])
countPlaceholders
java
google/truth
core/src/test/java/com/google/common/truth/CustomFailureMessageTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/CustomFailureMessageTest.java
Apache-2.0
@Test public void assertWithMessageThat_withPlaceholders() { AssertionError e = expectFailure( whenTesting -> whenTesting .withMessage("This is a %s %s", "custom", "message") .that(false) .isTrue()); assertThat(e).hasMessageThat().startsWith("This is a custom message\n"); }
Tests (and effectively sample code) for custom error message for checks. @author Christian Gruber ([email protected])
assertWithMessageThat_withPlaceholders
java
google/truth
core/src/test/java/com/google/common/truth/CustomFailureMessageTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/CustomFailureMessageTest.java
Apache-2.0
@Test public void extraPlaceholderThrowsIae() { assertThrows( IllegalArgumentException.class, () -> assert_().withMessage("This is a %s %s", "custom").that(true).isTrue()); }
Tests (and effectively sample code) for custom error message for checks. @author Christian Gruber ([email protected])
extraPlaceholderThrowsIae
java
google/truth
core/src/test/java/com/google/common/truth/CustomFailureMessageTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/CustomFailureMessageTest.java
Apache-2.0
@Test public void missingPlaceholderThrowsIae() { assertThrows( IllegalArgumentException.class, () -> assert_().withMessage("This is a %s", "custom", "message").that(true).isTrue()); }
Tests (and effectively sample code) for custom error message for checks. @author Christian Gruber ([email protected])
missingPlaceholderThrowsIae
java
google/truth
core/src/test/java/com/google/common/truth/CustomFailureMessageTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/CustomFailureMessageTest.java
Apache-2.0
@Test public void noPlaceholdersWithArgsThrowsIae() { assertThrows( IllegalArgumentException.class, () -> assert_().withMessage("This is a custom message", "bad arg").that(true).isTrue()); }
Tests (and effectively sample code) for custom error message for checks. @author Christian Gruber ([email protected])
noPlaceholdersWithArgsThrowsIae
java
google/truth
core/src/test/java/com/google/common/truth/CustomFailureMessageTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/CustomFailureMessageTest.java
Apache-2.0
@Test public void placeholdersArentEagerlyEvaluated() { Object toStringThrows = new Object() { @Override public String toString() { throw new RuntimeException("Don't call me!"); } }; assertWithMessage("Evaluating this will blow up: %s", toStringThrows).that(true).isTrue(); assert_().withMessage("Evaluating this will blow up: %s", toStringThrows).that(true).isTrue(); }
Tests (and effectively sample code) for custom error message for checks. @author Christian Gruber ([email protected])
placeholdersArentEagerlyEvaluated
java
google/truth
core/src/test/java/com/google/common/truth/CustomFailureMessageTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/CustomFailureMessageTest.java
Apache-2.0
@Override public String toString() { throw new RuntimeException("Don't call me!"); }
Tests (and effectively sample code) for custom error message for checks. @author Christian Gruber ([email protected])
toString
java
google/truth
core/src/test/java/com/google/common/truth/CustomFailureMessageTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/CustomFailureMessageTest.java
Apache-2.0
@Test @GwtIncompatible("Math.nextAfter") public void testDoubleConstants_matchNextAfter() { assertThat(Math.nextAfter(Double.MIN_VALUE, 1.0)).isEqualTo(OVER_MIN); assertThat(Math.nextAfter(1.23, POSITIVE_INFINITY)).isEqualTo(OVER_GOLDEN); assertThat(Math.nextAfter(Double.MAX_VALUE, 0.0)).isEqualTo(NEARLY_MAX); assertThat(Math.nextAfter(-1.0 * Double.MAX_VALUE, 0.0)).isEqualTo(NEGATIVE_NEARLY_MAX); assertThat(Math.nextAfter(-1.0 * Double.MIN_VALUE, -1.0)).isEqualTo(UNDER_NEGATIVE_MIN); }
Tests for Double Subjects. @author Kurt Alfred Kluever
testDoubleConstants_matchNextAfter
java
google/truth
core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
Apache-2.0
@Test public void testJ2clCornerCaseZero() { // GWT considers -0.0 to be equal to 0.0. But we've added a special workaround inside Truth. assertThatIsEqualToFails(-0.0, 0.0); }
Tests for Double Subjects. @author Kurt Alfred Kluever
testJ2clCornerCaseZero
java
google/truth
core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
Apache-2.0
@Test @GwtIncompatible("GWT behavior difference") public void j2clCornerCaseDoubleVsFloat() { // Under GWT, 1.23f.toString() is different than 1.23d.toString(), so the message omits types. // TODO(b/35377736): Consider making Truth add the types manually. AssertionError e = expectFailure(whenTesting -> whenTesting.that(1.23).isEqualTo(1.23f)); assertFailureKeys(e, "expected", "an instance of", "but was", "an instance of"); }
Tests for Double Subjects. @author Kurt Alfred Kluever
j2clCornerCaseDoubleVsFloat
java
google/truth
core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
Apache-2.0
@Test public void isWithinOf() { assertThat(2.0).isWithin(0.0).of(2.0); assertThat(2.0).isWithin(0.00001).of(2.0); assertThat(2.0).isWithin(1000.0).of(2.0); assertThat(2.0).isWithin(1.00001).of(3.0); assertThatIsWithinFails(2.0, 0.99999, 3.0); assertThatIsWithinFails(2.0, 1000.0, 1003.0); assertThatIsWithinFailsForNonFiniteExpected(2.0, 1000.0, POSITIVE_INFINITY); assertThatIsWithinFailsForNonFiniteExpected(2.0, 1000.0, NaN); assertThatIsWithinFailsForNonFiniteActual(NEGATIVE_INFINITY, 1000.0, 2.0); assertThatIsWithinFailsForNonFiniteActual(NaN, 1000.0, 2.0); }
Tests for Double Subjects. @author Kurt Alfred Kluever
isWithinOf
java
google/truth
core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
Apache-2.0
private static void assertThatIsWithinFails(double actual, double tolerance, double expected) { AssertionError failure = expectFailure(whenTesting -> whenTesting.that(actual).isWithin(tolerance).of(expected)); assertThat(failure) .factKeys() .containsExactly("expected", "but was", "outside tolerance") .inOrder(); assertThat(failure).factValue("expected").isEqualTo(formatNumericValue(expected)); assertThat(failure).factValue("but was").isEqualTo(formatNumericValue(actual)); assertThat(failure).factValue("outside tolerance").isEqualTo(formatNumericValue(tolerance)); }
Tests for Double Subjects. @author Kurt Alfred Kluever
assertThatIsWithinFails
java
google/truth
core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
Apache-2.0
private static void assertThatIsWithinFailsForNonFiniteExpected( double actual, double tolerance, double expected) { AssertionError failure = expectFailure(whenTesting -> whenTesting.that(actual).isWithin(tolerance).of(expected)); assertThat(failure) .factKeys() .containsExactly( "could not perform approximate-equality check because expected value is not finite", "expected", "was", "tolerance") .inOrder(); assertThat(failure).factValue("expected").isEqualTo(formatNumericValue(expected)); assertThat(failure).factValue("was").isEqualTo(formatNumericValue(actual)); assertThat(failure).factValue("tolerance").isEqualTo(formatNumericValue(tolerance)); }
Tests for Double Subjects. @author Kurt Alfred Kluever
assertThatIsWithinFailsForNonFiniteExpected
java
google/truth
core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
Apache-2.0
private static void assertThatIsWithinFailsForNonFiniteActual( double actual, double tolerance, double expected) { AssertionError failure = expectFailure(whenTesting -> whenTesting.that(actual).isWithin(tolerance).of(expected)); assertThat(failure) .factKeys() .containsExactly("expected a finite value near", "but was", "tolerance") .inOrder(); assertThat(failure) .factValue("expected a finite value near") .isEqualTo(formatNumericValue(expected)); assertThat(failure).factValue("but was").isEqualTo(formatNumericValue(actual)); assertThat(failure).factValue("tolerance").isEqualTo(formatNumericValue(tolerance)); }
Tests for Double Subjects. @author Kurt Alfred Kluever
assertThatIsWithinFailsForNonFiniteActual
java
google/truth
core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
Apache-2.0
@Test public void isNotWithinOf() { assertThatIsNotWithinFails(2.0, 0.0, 2.0); assertThatIsNotWithinFails(2.0, 0.00001, 2.0); assertThatIsNotWithinFails(2.0, 1000.0, 2.0); assertThatIsNotWithinFails(2.0, 1.00001, 3.0); assertThat(2.0).isNotWithin(0.99999).of(3.0); assertThat(2.0).isNotWithin(1000.0).of(1003.0); assertThatIsNotWithinFailsForNonFiniteExpected(2.0, 0.0, POSITIVE_INFINITY); assertThatIsNotWithinFailsForNonFiniteExpected(2.0, 0.0, NaN); assertThatIsNotWithinFailsForNonFiniteActual(NEGATIVE_INFINITY, 1000.0, 2.0); assertThatIsNotWithinFailsForNonFiniteActual(NaN, 1000.0, 2.0); }
Tests for Double Subjects. @author Kurt Alfred Kluever
isNotWithinOf
java
google/truth
core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
Apache-2.0
private static void assertThatIsNotWithinFails(double actual, double tolerance, double expected) { AssertionError failure = expectFailure(whenTesting -> whenTesting.that(actual).isNotWithin(tolerance).of(expected)); assertThat(failure).factValue("expected not to be").isEqualTo(formatNumericValue(expected)); assertThat(failure).factValue("within tolerance").isEqualTo(formatNumericValue(tolerance)); }
Tests for Double Subjects. @author Kurt Alfred Kluever
assertThatIsNotWithinFails
java
google/truth
core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
Apache-2.0
private static void assertThatIsNotWithinFailsForNonFiniteExpected( double actual, double tolerance, double expected) { AssertionError failure = expectFailure(whenTesting -> whenTesting.that(actual).isNotWithin(tolerance).of(expected)); assertThat(failure) .factKeys() .containsExactly( "could not perform approximate-equality check because expected value is not finite", "expected not to be", "was", "tolerance"); assertThat(failure).factValue("expected not to be").isEqualTo(formatNumericValue(expected)); assertThat(failure).factValue("was").isEqualTo(formatNumericValue(actual)); assertThat(failure).factValue("tolerance").isEqualTo(formatNumericValue(tolerance)); }
Tests for Double Subjects. @author Kurt Alfred Kluever
assertThatIsNotWithinFailsForNonFiniteExpected
java
google/truth
core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
Apache-2.0
private static void assertThatIsNotWithinFailsForNonFiniteActual( double actual, double tolerance, double expected) { AssertionError failure = expectFailure(whenTesting -> whenTesting.that(actual).isNotWithin(tolerance).of(expected)); assertThat(failure) .factValue("expected a finite value that is not near") .isEqualTo(formatNumericValue(expected)); assertThat(failure).factValue("tolerance").isEqualTo(formatNumericValue(tolerance)); }
Tests for Double Subjects. @author Kurt Alfred Kluever
assertThatIsNotWithinFailsForNonFiniteActual
java
google/truth
core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
Apache-2.0