From b02a6583a9c9e6db9cf3725f542743ec0faf055f Mon Sep 17 00:00:00 2001 From: cpovirk Date: Wed, 31 Jan 2024 13:58:28 -0800 Subject: [PATCH] Migrate most usages of `Truth8.assertThat` to equivalent usages of `Truth.assertThat`, and qualify others. By "qualify," I mean that, instead of static importing `Truth8.assertThat`, we write "`Truth8.assertThat(...)`" at the call site. This is normally the opposite of what we recommend. However, it's a necessary step in our migration: We are copying all the `Truth8` methods to `Truth`, and we can't do that if any files static import both `Truth.assertThat` and `Truth8.assertThat` (because it produces a compile error about ambiguous overloads). To unblock that, we're moving callers away from the static import. We will update static analysis to stop suggesting the import. A later step will migrate these callers to the new `Truth.assertThat` methods, which we will static import. The `Truth8` methods will be hidden in the future. All callers will use `Truth`. This continues our work on https://github.com/google/truth/issues/746. PiperOrigin-RevId: 603151738 --- .../common/truth/IntStreamSubjectTest.java | 61 +++++++++---------- .../common/truth/LongStreamSubjectTest.java | 61 +++++++++---------- .../common/truth/StreamSubjectTest.java | 2 +- 3 files changed, 61 insertions(+), 63 deletions(-) diff --git a/extensions/java8/src/test/java/com/google/common/truth/IntStreamSubjectTest.java b/extensions/java8/src/test/java/com/google/common/truth/IntStreamSubjectTest.java index 9fc8ee41d..dc6bb5b45 100644 --- a/extensions/java8/src/test/java/com/google/common/truth/IntStreamSubjectTest.java +++ b/extensions/java8/src/test/java/com/google/common/truth/IntStreamSubjectTest.java @@ -18,7 +18,6 @@ import static com.google.common.truth.FailureAssertions.assertFailureKeys; import static com.google.common.truth.FailureAssertions.assertFailureValue; import static com.google.common.truth.IntStreamSubject.intStreams; -import static com.google.common.truth.Truth8.assertThat; import static java.util.Arrays.asList; import static org.junit.Assert.fail; @@ -39,7 +38,7 @@ public final class IntStreamSubjectTest { @Test public void testIsEqualTo() throws Exception { IntStream stream = IntStream.of(42); - assertThat(stream).isEqualTo(stream); + Truth8.assertThat(stream).isEqualTo(stream); } @Test @@ -53,7 +52,7 @@ public void testIsEqualToList() throws Exception { public void testNullStream_fails() throws Exception { IntStream nullStream = null; try { - assertThat(nullStream).isEmpty(); + Truth8.assertThat(nullStream).isEmpty(); fail(); } catch (NullPointerException expected) { } @@ -62,18 +61,18 @@ public void testNullStream_fails() throws Exception { @Test public void testNullStreamIsNull() throws Exception { IntStream nullStream = null; - assertThat(nullStream).isNull(); + Truth8.assertThat(nullStream).isNull(); } @Test public void testIsSameInstanceAs() throws Exception { IntStream stream = IntStream.of(1); - assertThat(stream).isSameInstanceAs(stream); + Truth8.assertThat(stream).isSameInstanceAs(stream); } @Test public void testIsEmpty() throws Exception { - assertThat(IntStream.of()).isEmpty(); + Truth8.assertThat(IntStream.of()).isEmpty(); } @Test @@ -84,7 +83,7 @@ public void testIsEmpty_fails() throws Exception { @Test public void testIsNotEmpty() throws Exception { - assertThat(IntStream.of(42)).isNotEmpty(); + Truth8.assertThat(IntStream.of(42)).isNotEmpty(); } @Test @@ -95,7 +94,7 @@ public void testIsNotEmpty_fails() throws Exception { @Test public void testHasSize() throws Exception { - assertThat(IntStream.of(42)).hasSize(1); + Truth8.assertThat(IntStream.of(42)).hasSize(1); } @Test @@ -106,7 +105,7 @@ public void testHasSize_fails() throws Exception { @Test public void testContainsNoDuplicates() throws Exception { - assertThat(IntStream.of(42)).containsNoDuplicates(); + Truth8.assertThat(IntStream.of(42)).containsNoDuplicates(); } @Test @@ -117,7 +116,7 @@ public void testContainsNoDuplicates_fails() throws Exception { @Test public void testContains() throws Exception { - assertThat(IntStream.of(42)).contains(42); + Truth8.assertThat(IntStream.of(42)).contains(42); } @Test @@ -128,7 +127,7 @@ public void testContains_fails() throws Exception { @Test public void testContainsAnyOf() throws Exception { - assertThat(IntStream.of(42)).containsAnyOf(42, 43); + Truth8.assertThat(IntStream.of(42)).containsAnyOf(42, 43); } @Test @@ -139,7 +138,7 @@ public void testContainsAnyOf_fails() throws Exception { @Test public void testContainsAnyIn() throws Exception { - assertThat(IntStream.of(42)).containsAnyIn(asList(42, 43)); + Truth8.assertThat(IntStream.of(42)).containsAnyIn(asList(42, 43)); } @Test @@ -151,7 +150,7 @@ public void testContainsAnyIn_fails() throws Exception { @Test public void testDoesNotContain() throws Exception { - assertThat(IntStream.of(42)).doesNotContain(43); + Truth8.assertThat(IntStream.of(42)).doesNotContain(43); } @Test @@ -162,7 +161,7 @@ public void testDoesNotContain_fails() throws Exception { @Test public void testContainsNoneOf() throws Exception { - assertThat(IntStream.of(42)).containsNoneOf(43, 44); + Truth8.assertThat(IntStream.of(42)).containsNoneOf(43, 44); } @Test @@ -173,7 +172,7 @@ public void testContainsNoneOf_fails() throws Exception { @Test public void testContainsNoneIn() throws Exception { - assertThat(IntStream.of(42)).containsNoneIn(asList(43, 44)); + Truth8.assertThat(IntStream.of(42)).containsNoneIn(asList(43, 44)); } @Test @@ -185,7 +184,7 @@ public void testContainsNoneIn_fails() throws Exception { @Test public void testContainsAtLeast() throws Exception { - assertThat(IntStream.of(42, 43)).containsAtLeast(42, 43); + Truth8.assertThat(IntStream.of(42, 43)).containsAtLeast(42, 43); } @Test @@ -197,7 +196,7 @@ public void testContainsAtLeast_fails() throws Exception { @Test public void testContainsAtLeast_inOrder() throws Exception { - assertThat(IntStream.of(42, 43)).containsAtLeast(42, 43).inOrder(); + Truth8.assertThat(IntStream.of(42, 43)).containsAtLeast(42, 43).inOrder(); } @Test @@ -216,7 +215,7 @@ public void testContainsAtLeast_inOrder_fails() throws Exception { @Test public void testContainsAtLeastElementsIn() throws Exception { - assertThat(IntStream.of(42, 43)).containsAtLeastElementsIn(asList(42, 43)); + Truth8.assertThat(IntStream.of(42, 43)).containsAtLeastElementsIn(asList(42, 43)); } @Test @@ -231,7 +230,7 @@ public void testContainsAtLeastElementsIn_fails() throws Exception { @Test public void testContainsAtLeastElementsIn_inOrder() throws Exception { - assertThat(IntStream.of(42, 43)).containsAtLeastElementsIn(asList(42, 43)).inOrder(); + Truth8.assertThat(IntStream.of(42, 43)).containsAtLeastElementsIn(asList(42, 43)).inOrder(); } @Test @@ -253,7 +252,7 @@ public void testContainsAtLeastElementsIn_inOrder_fails() throws Exception { @Test public void testContainsExactly() throws Exception { - assertThat(IntStream.of(42, 43)).containsExactly(42, 43); + Truth8.assertThat(IntStream.of(42, 43)).containsExactly(42, 43); } @Test @@ -266,7 +265,7 @@ public void testContainsExactly_fails() throws Exception { @Test public void testContainsExactly_inOrder() throws Exception { - assertThat(IntStream.of(42, 43)).containsExactly(42, 43).inOrder(); + Truth8.assertThat(IntStream.of(42, 43)).containsExactly(42, 43).inOrder(); } @Test @@ -281,8 +280,8 @@ public void testContainsExactly_inOrder_fails() throws Exception { @Test public void testContainsExactlyElementsIn() throws Exception { - assertThat(IntStream.of(42, 43)).containsExactlyElementsIn(asList(42, 43)); - assertThat(IntStream.of(42, 43)).containsExactlyElementsIn(asList(43, 42)); + Truth8.assertThat(IntStream.of(42, 43)).containsExactlyElementsIn(asList(42, 43)); + Truth8.assertThat(IntStream.of(42, 43)).containsExactlyElementsIn(asList(43, 42)); } @Test @@ -297,7 +296,7 @@ public void testContainsExactlyElementsIn_fails() throws Exception { @Test public void testContainsExactlyElementsIn_inOrder() throws Exception { - assertThat(IntStream.of(42, 43)).containsExactlyElementsIn(asList(42, 43)).inOrder(); + Truth8.assertThat(IntStream.of(42, 43)).containsExactlyElementsIn(asList(42, 43)).inOrder(); } @Test @@ -315,14 +314,14 @@ public void testContainsExactlyElementsIn_inOrder_fails() throws Exception { @Test public void testContainsExactlyElementsIn_inOrder_intStream() throws Exception { - assertThat(IntStream.of(1, 2, 3, 4)).containsExactly(1, 2, 3, 4).inOrder(); + Truth8.assertThat(IntStream.of(1, 2, 3, 4)).containsExactly(1, 2, 3, 4).inOrder(); } @Test public void testIsInOrder() { - assertThat(IntStream.of()).isInOrder(); - assertThat(IntStream.of(1)).isInOrder(); - assertThat(IntStream.of(1, 1, 2, 3, 3, 3, 4)).isInOrder(); + Truth8.assertThat(IntStream.of()).isInOrder(); + Truth8.assertThat(IntStream.of(1)).isInOrder(); + Truth8.assertThat(IntStream.of(1, 1, 2, 3, 3, 3, 4)).isInOrder(); } @Test @@ -333,9 +332,9 @@ public void testIsInOrder_fails() { @Test public void testIsInStrictOrder() { - assertThat(IntStream.of()).isInStrictOrder(); - assertThat(IntStream.of(1)).isInStrictOrder(); - assertThat(IntStream.of(1, 2, 3, 4)).isInStrictOrder(); + Truth8.assertThat(IntStream.of()).isInStrictOrder(); + Truth8.assertThat(IntStream.of(1)).isInStrictOrder(); + Truth8.assertThat(IntStream.of(1, 2, 3, 4)).isInStrictOrder(); } @Test diff --git a/extensions/java8/src/test/java/com/google/common/truth/LongStreamSubjectTest.java b/extensions/java8/src/test/java/com/google/common/truth/LongStreamSubjectTest.java index 52c36ea0b..bb2ce980b 100644 --- a/extensions/java8/src/test/java/com/google/common/truth/LongStreamSubjectTest.java +++ b/extensions/java8/src/test/java/com/google/common/truth/LongStreamSubjectTest.java @@ -18,7 +18,6 @@ import static com.google.common.truth.FailureAssertions.assertFailureKeys; import static com.google.common.truth.FailureAssertions.assertFailureValue; import static com.google.common.truth.LongStreamSubject.longStreams; -import static com.google.common.truth.Truth8.assertThat; import static java.util.Arrays.asList; import static org.junit.Assert.fail; @@ -39,7 +38,7 @@ public final class LongStreamSubjectTest { @Test public void testIsEqualTo() throws Exception { LongStream stream = LongStream.of(42); - assertThat(stream).isEqualTo(stream); + Truth8.assertThat(stream).isEqualTo(stream); } @Test @@ -53,7 +52,7 @@ public void testIsEqualToList() throws Exception { public void testNullStream_fails() throws Exception { LongStream nullStream = null; try { - assertThat(nullStream).isEmpty(); + Truth8.assertThat(nullStream).isEmpty(); fail(); } catch (NullPointerException expected) { } @@ -62,18 +61,18 @@ public void testNullStream_fails() throws Exception { @Test public void testNullStreamIsNull() throws Exception { LongStream nullStream = null; - assertThat(nullStream).isNull(); + Truth8.assertThat(nullStream).isNull(); } @Test public void testIsSameInstanceAs() throws Exception { LongStream stream = LongStream.of(1); - assertThat(stream).isSameInstanceAs(stream); + Truth8.assertThat(stream).isSameInstanceAs(stream); } @Test public void testIsEmpty() throws Exception { - assertThat(LongStream.of()).isEmpty(); + Truth8.assertThat(LongStream.of()).isEmpty(); } @Test @@ -84,7 +83,7 @@ public void testIsEmpty_fails() throws Exception { @Test public void testIsNotEmpty() throws Exception { - assertThat(LongStream.of(42)).isNotEmpty(); + Truth8.assertThat(LongStream.of(42)).isNotEmpty(); } @Test @@ -95,7 +94,7 @@ public void testIsNotEmpty_fails() throws Exception { @Test public void testHasSize() throws Exception { - assertThat(LongStream.of(42)).hasSize(1); + Truth8.assertThat(LongStream.of(42)).hasSize(1); } @Test @@ -106,7 +105,7 @@ public void testHasSize_fails() throws Exception { @Test public void testContainsNoDuplicates() throws Exception { - assertThat(LongStream.of(42)).containsNoDuplicates(); + Truth8.assertThat(LongStream.of(42)).containsNoDuplicates(); } @Test @@ -118,7 +117,7 @@ public void testContainsNoDuplicates_fails() throws Exception { @Test public void testContains() throws Exception { - assertThat(LongStream.of(42)).contains(42); + Truth8.assertThat(LongStream.of(42)).contains(42); } @Test @@ -129,7 +128,7 @@ public void testContains_fails() throws Exception { @Test public void testContainsAnyOf() throws Exception { - assertThat(LongStream.of(42)).containsAnyOf(42, 43); + Truth8.assertThat(LongStream.of(42)).containsAnyOf(42, 43); } @Test @@ -140,7 +139,7 @@ public void testContainsAnyOf_fails() throws Exception { @Test public void testContainsAnyIn() throws Exception { - assertThat(LongStream.of(42)).containsAnyIn(asList(42L, 43L)); + Truth8.assertThat(LongStream.of(42)).containsAnyIn(asList(42L, 43L)); } @Test @@ -152,7 +151,7 @@ public void testContainsAnyIn_fails() throws Exception { @Test public void testDoesNotContain() throws Exception { - assertThat(LongStream.of(42)).doesNotContain(43); + Truth8.assertThat(LongStream.of(42)).doesNotContain(43); } @Test @@ -163,7 +162,7 @@ public void testDoesNotContain_fails() throws Exception { @Test public void testContainsNoneOf() throws Exception { - assertThat(LongStream.of(42)).containsNoneOf(43, 44); + Truth8.assertThat(LongStream.of(42)).containsNoneOf(43, 44); } @Test @@ -174,7 +173,7 @@ public void testContainsNoneOf_fails() throws Exception { @Test public void testContainsNoneIn() throws Exception { - assertThat(LongStream.of(42)).containsNoneIn(asList(43, 44)); + Truth8.assertThat(LongStream.of(42)).containsNoneIn(asList(43, 44)); } @Test @@ -186,7 +185,7 @@ public void testContainsNoneIn_fails() throws Exception { @Test public void testContainsAtLeast() throws Exception { - assertThat(LongStream.of(42, 43)).containsAtLeast(42, 43); + Truth8.assertThat(LongStream.of(42, 43)).containsAtLeast(42, 43); } @Test @@ -198,7 +197,7 @@ public void testContainsAtLeast_fails() throws Exception { @Test public void testContainsAtLeast_inOrder() throws Exception { - assertThat(LongStream.of(42, 43)).containsAtLeast(42, 43).inOrder(); + Truth8.assertThat(LongStream.of(42, 43)).containsAtLeast(42, 43).inOrder(); } @Test @@ -217,7 +216,7 @@ public void testContainsAtLeast_inOrder_fails() throws Exception { @Test public void testContainsAtLeastElementsIn() throws Exception { - assertThat(LongStream.of(42, 43)).containsAtLeastElementsIn(asList(42L, 43L)); + Truth8.assertThat(LongStream.of(42, 43)).containsAtLeastElementsIn(asList(42L, 43L)); } @Test @@ -242,7 +241,7 @@ public void testContainsAtLeastElementsIn_wrongType_fails() throws Exception { @Test public void testContainsAtLeastElementsIn_inOrder() throws Exception { - assertThat(LongStream.of(42, 43)).containsAtLeastElementsIn(asList(42L, 43L)).inOrder(); + Truth8.assertThat(LongStream.of(42, 43)).containsAtLeastElementsIn(asList(42L, 43L)).inOrder(); } @Test @@ -275,7 +274,7 @@ public void testContainsAtLeastElementsIn_inOrder_wrongType_fails() throws Excep @Test public void testContainsExactly() throws Exception { - assertThat(LongStream.of(42, 43)).containsExactly(42, 43); + Truth8.assertThat(LongStream.of(42, 43)).containsExactly(42, 43); } @Test @@ -288,7 +287,7 @@ public void testContainsExactly_fails() throws Exception { @Test public void testContainsExactly_inOrder() throws Exception { - assertThat(LongStream.of(42, 43)).containsExactly(42, 43).inOrder(); + Truth8.assertThat(LongStream.of(42, 43)).containsExactly(42, 43).inOrder(); } @Test @@ -303,8 +302,8 @@ public void testContainsExactly_inOrder_fails() throws Exception { @Test public void testContainsExactlyElementsIn() throws Exception { - assertThat(LongStream.of(42, 43)).containsExactlyElementsIn(asList(42L, 43L)); - assertThat(LongStream.of(42, 43)).containsExactlyElementsIn(asList(43L, 42L)); + Truth8.assertThat(LongStream.of(42, 43)).containsExactlyElementsIn(asList(42L, 43L)); + Truth8.assertThat(LongStream.of(42, 43)).containsExactlyElementsIn(asList(43L, 42L)); } @Test @@ -327,7 +326,7 @@ public void testContainsExactlyElementsIn_wrongType_fails() throws Exception { @Test public void testContainsExactlyElementsIn_inOrder() throws Exception { - assertThat(LongStream.of(42, 43)).containsExactlyElementsIn(asList(42L, 43L)).inOrder(); + Truth8.assertThat(LongStream.of(42, 43)).containsExactlyElementsIn(asList(42L, 43L)).inOrder(); } @Test @@ -356,14 +355,14 @@ public void testContainsExactlyElementsIn_inOrder_wrongType_fails() throws Excep @Test public void testContainsExactlyElementsIn_inOrder_LongStream() throws Exception { - assertThat(LongStream.of(1, 2, 3, 4)).containsExactly(1, 2, 3, 4).inOrder(); + Truth8.assertThat(LongStream.of(1, 2, 3, 4)).containsExactly(1, 2, 3, 4).inOrder(); } @Test public void testIsInOrder() { - assertThat(LongStream.of()).isInOrder(); - assertThat(LongStream.of(1)).isInOrder(); - assertThat(LongStream.of(1, 1, 2, 3, 3, 3, 4)).isInOrder(); + Truth8.assertThat(LongStream.of()).isInOrder(); + Truth8.assertThat(LongStream.of(1)).isInOrder(); + Truth8.assertThat(LongStream.of(1, 1, 2, 3, 3, 3, 4)).isInOrder(); } @Test @@ -374,9 +373,9 @@ public void testIsInOrder_fails() { @Test public void testIsInStrictOrder() { - assertThat(LongStream.of()).isInStrictOrder(); - assertThat(LongStream.of(1)).isInStrictOrder(); - assertThat(LongStream.of(1, 2, 3, 4)).isInStrictOrder(); + Truth8.assertThat(LongStream.of()).isInStrictOrder(); + Truth8.assertThat(LongStream.of(1)).isInStrictOrder(); + Truth8.assertThat(LongStream.of(1, 2, 3, 4)).isInStrictOrder(); } @Test diff --git a/extensions/java8/src/test/java/com/google/common/truth/StreamSubjectTest.java b/extensions/java8/src/test/java/com/google/common/truth/StreamSubjectTest.java index 3960f18b4..520e68d30 100644 --- a/extensions/java8/src/test/java/com/google/common/truth/StreamSubjectTest.java +++ b/extensions/java8/src/test/java/com/google/common/truth/StreamSubjectTest.java @@ -19,7 +19,7 @@ import static com.google.common.truth.FailureAssertions.assertFailureKeys; import static com.google.common.truth.FailureAssertions.assertFailureValue; import static com.google.common.truth.StreamSubject.streams; -import static com.google.common.truth.Truth8.assertThat; +import static com.google.common.truth.Truth.assertThat; import static java.util.Arrays.asList; import static org.junit.Assert.fail;