Skip to content

Commit

Permalink
Migrate most usages of Truth8.assertThat to equivalent usages of `T…
Browse files Browse the repository at this point in the history
…ruth.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 #746.

PiperOrigin-RevId: 603151738
  • Loading branch information
cpovirk authored and Google Java Core Libraries committed Jan 31, 2024
1 parent 0999369 commit b02a658
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
Expand All @@ -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) {
}
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
Loading

0 comments on commit b02a658

Please # to comment.