Override, deprecate, and `@DoNotCall` both `StreamSubject.isEqualTo()` and `isNotEqualTo()`, as `Stream`s do not have well-defined equality behavior.
RELNOTES=n/a
PiperOrigin-RevId: 474797194
diff --git a/extensions/java8/src/main/java/com/google/common/truth/StreamSubject.java b/extensions/java8/src/main/java/com/google/common/truth/StreamSubject.java
index 4957686..6f62a0f 100644
--- a/extensions/java8/src/main/java/com/google/common/truth/StreamSubject.java
+++ b/extensions/java8/src/main/java/com/google/common/truth/StreamSubject.java
@@ -18,6 +18,7 @@
import static java.util.stream.Collectors.toCollection;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
+import com.google.errorprone.annotations.DoNotCall;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
@@ -223,7 +224,35 @@
check().that(actualList).isInOrder(comparator);
}
- // TODO(user): Do we want to override + deprecate isEqualTo/isNotEqualTo?
+ /**
+ * @deprecated {@code streamA.isEqualTo(streamB)} always fails, except when passed the exact same
+ * stream reference
+ */
+ @Override
+ @DoNotCall(
+ "StreamSubject.isEqualTo() is not supported because Streams do not have well-defined"
+ + " equality semantics")
+ @Deprecated
+ public void isEqualTo(@Nullable Object expected) {
+ throw new UnsupportedOperationException(
+ "StreamSubject.isEqualTo() is not supported because Streams do not have well-defined"
+ + " equality semantics");
+ }
+
+ /**
+ * @deprecated {@code streamA.isNotEqualTo(streamB)} always passes, except when passed the exact
+ * same stream reference
+ */
+ @Override
+ @DoNotCall(
+ "StreamSubject.isNotEqualTo() is not supported because Streams do not have well-defined"
+ + " equality semantics")
+ @Deprecated
+ public void isNotEqualTo(@Nullable Object unexpected) {
+ throw new UnsupportedOperationException(
+ "StreamSubject.isNotEqualTo() is not supported because Streams do not have well-defined"
+ + " equality semantics");
+ }
// TODO(user): Do we want to support comparingElementsUsing() on StreamSubject?
}
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 b685e71..09a767f 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
@@ -20,9 +20,9 @@
import static com.google.common.truth.StreamSubject.streams;
import static com.google.common.truth.Truth8.assertThat;
import static java.util.Arrays.asList;
+import static org.junit.Assert.assertThrows;
import static org.junit.Assert.fail;
-import java.util.List;
import java.util.stream.Stream;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -36,17 +36,19 @@
@RunWith(JUnit4.class)
public final class StreamSubjectTest {
+ @SuppressWarnings("DoNotCall")
@Test
public void testIsEqualTo() throws Exception {
Stream<String> stream = Stream.of("hello");
- assertThat(stream).isEqualTo(stream);
+ assertThrows(UnsupportedOperationException.class, () -> assertThat(stream).isEqualTo(stream));
}
+ @SuppressWarnings("DoNotCall")
@Test
- public void testIsEqualToList() throws Exception {
+ public void testIsNotEqualTo() throws Exception {
Stream<String> stream = Stream.of("hello");
- List<String> list = asList("hello");
- AssertionError unused = expectFailure(whenTesting -> whenTesting.that(stream).isEqualTo(list));
+ assertThrows(
+ UnsupportedOperationException.class, () -> assertThat(stream).isNotEqualTo(stream));
}
@Test