diff --git a/src/main/java/io/reactivex/observers/BaseTestConsumer.java b/src/main/java/io/reactivex/observers/BaseTestConsumer.java
index 373339f020..69d227d91d 100644
--- a/src/main/java/io/reactivex/observers/BaseTestConsumer.java
+++ b/src/main/java/io/reactivex/observers/BaseTestConsumer.java
@@ -565,9 +565,14 @@ public final U assertValuesOnly(T... values) {
}
/**
- * Assert that the TestObserver/TestSubscriber received only the specified values in any order.
- *
This helps asserting when the order of the values is not guaranteed, i.e., when merging
+ * Assert that the TestObserver/TestSubscriber received only items that are in the specified
+ * collection as well, irrespective of the order they were received.
+ *
+ * This helps asserting when the order of the values is not guaranteed, i.e., when merging
* asynchronous streams.
+ *
+ * To ensure that only the expected items have been received, no more and no less, in any order,
+ * apply {@link #assertValueCount(int)} with {@code expected.size()}.
*
* @param expected the collection of values expected in any order
* @return this
diff --git a/src/test/java/io/reactivex/observers/TestObserverTest.java b/src/test/java/io/reactivex/observers/TestObserverTest.java
index efe9798bae..27f4f7442c 100644
--- a/src/test/java/io/reactivex/observers/TestObserverTest.java
+++ b/src/test/java/io/reactivex/observers/TestObserverTest.java
@@ -1626,4 +1626,38 @@ public void assertValueSequenceOnlyThrowsWhenErrored() {
// expected
}
}
+
+ @Test
+ public void assertValueSetWiderSet() {
+ Set set = new HashSet(Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7));
+
+ Observable.just(4, 5, 1, 3, 2)
+ .test()
+ .assertValueSet(set);
+ }
+
+ @Test
+ public void assertValueSetExact() {
+ Set set = new HashSet(Arrays.asList(1, 2, 3, 4, 5));
+
+ Observable.just(4, 5, 1, 3, 2)
+ .test()
+ .assertValueSet(set)
+ .assertValueCount(set.size());
+ }
+
+ @Test
+ public void assertValueSetMissing() {
+ Set set = new HashSet(Arrays.asList(0, 1, 2, 4, 5, 6, 7));
+
+ try {
+ Observable.range(1, 5)
+ .test()
+ .assertValueSet(set);
+
+ throw new RuntimeException("Should have failed");
+ } catch (AssertionError ex) {
+ assertTrue(ex.getMessage(), ex.getMessage().contains("Value not in the expected collection: " + 3));
+ }
+ }
}
diff --git a/src/test/java/io/reactivex/subscribers/TestSubscriberTest.java b/src/test/java/io/reactivex/subscribers/TestSubscriberTest.java
index bd2748371f..d4358f4bb8 100644
--- a/src/test/java/io/reactivex/subscribers/TestSubscriberTest.java
+++ b/src/test/java/io/reactivex/subscribers/TestSubscriberTest.java
@@ -2186,4 +2186,38 @@ public void awaitCount0() {
TestSubscriber ts = TestSubscriber.create();
ts.awaitCount(0, TestWaitStrategy.SLEEP_1MS, 0);
}
+
+ @Test
+ public void assertValueSetWiderSet() {
+ Set set = new HashSet(Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7));
+
+ Flowable.just(4, 5, 1, 3, 2)
+ .test()
+ .assertValueSet(set);
+ }
+
+ @Test
+ public void assertValueSetExact() {
+ Set set = new HashSet(Arrays.asList(1, 2, 3, 4, 5));
+
+ Flowable.just(4, 5, 1, 3, 2)
+ .test()
+ .assertValueSet(set)
+ .assertValueCount(set.size());
+ }
+
+ @Test
+ public void assertValueSetMissing() {
+ Set set = new HashSet(Arrays.asList(0, 1, 2, 4, 5, 6, 7));
+
+ try {
+ Flowable.range(1, 5)
+ .test()
+ .assertValueSet(set);
+
+ throw new RuntimeException("Should have failed");
+ } catch (AssertionError ex) {
+ assertTrue(ex.getMessage(), ex.getMessage().contains("Value not in the expected collection: " + 3));
+ }
+ }
}