Skip to content

Commit 8ceb70f

Browse files
committed
Verify assertValueAt with negative index
1 parent 978ff26 commit 8ceb70f

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

src/test/java/io/reactivex/rxjava3/observers/TestObserverTest.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -962,6 +962,21 @@ public void assertValueAtInvalidIndex() {
962962
});
963963
}
964964

965+
@Test
966+
public void assertValueAtInvalidIndexNegative() {
967+
assertThrowsWithMessage("Index -2 is out of range [0, 2) (latch = 0, values = 2, errors = 0, completions = 1)", AssertionError.class, () -> {
968+
TestObserver<Integer> to = new TestObserver<>();
969+
970+
Observable.just(1, 2).subscribe(to);
971+
972+
to.assertValueAt(-2, new Predicate<Integer>() {
973+
@Override public boolean test(final Integer o) throws Exception {
974+
return o == 1;
975+
}
976+
});
977+
});
978+
}
979+
965980
@Test
966981
public void assertValueAtIndexEmpty() {
967982
assertThrowsWithMessage("No values (latch = 0, values = 0, errors = 0, completions = 1)", AssertionError.class, () -> {
@@ -1004,6 +1019,17 @@ public void assertValueAtIndexInvalidIndex() {
10041019
});
10051020
}
10061021

1022+
@Test
1023+
public void assertValueAtIndexInvalidIndexNegative() {
1024+
assertThrowsWithMessage("Index -2 is out of range [0, 2) (latch = 0, values = 2, errors = 0, completions = 1)", AssertionError.class, () -> {
1025+
TestObserver<String> to = new TestObserver<>();
1026+
1027+
Observable.just("a", "b").subscribe(to);
1028+
1029+
to.assertValueAt(-2, "c");
1030+
});
1031+
}
1032+
10071033
@Test
10081034
public void withTag() {
10091035
try {

src/test/java/io/reactivex/rxjava3/subscribers/TestSubscriberTest.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1484,6 +1484,43 @@ public void assertValueAtInvalidIndex() {
14841484
});
14851485
}
14861486

1487+
@Test
1488+
public void assertValueAtIndexInvalidIndex() {
1489+
assertThrowsWithMessage("Index 2 is out of range [0, 2) (latch = 0, values = 2, errors = 0, completions = 1)", AssertionError.class, () -> {
1490+
TestSubscriber<Integer> ts = new TestSubscriber<>();
1491+
1492+
Flowable.just(1, 2).subscribe(ts);
1493+
1494+
ts.assertValueAt(2, 3);
1495+
});
1496+
}
1497+
1498+
@Test
1499+
public void assertValueAtIndexInvalidIndexNegative() {
1500+
assertThrowsWithMessage("Index -2 is out of range [0, 2) (latch = 0, values = 2, errors = 0, completions = 1)", AssertionError.class, () -> {
1501+
TestSubscriber<Integer> ts = new TestSubscriber<>();
1502+
1503+
Flowable.just(1, 2).subscribe(ts);
1504+
1505+
ts.assertValueAt(-2, 3);
1506+
});
1507+
}
1508+
1509+
@Test
1510+
public void assertValueAtInvalidIndexNegative() {
1511+
assertThrowsWithMessage("Index -2 is out of range [0, 2) (latch = 0, values = 2, errors = 0, completions = 1)", AssertionError.class, () -> {
1512+
TestSubscriber<Integer> ts = new TestSubscriber<>();
1513+
1514+
Flowable.just(1, 2).subscribe(ts);
1515+
1516+
ts.assertValueAt(-2, new Predicate<Integer>() {
1517+
@Override public boolean test(final Integer o) throws Exception {
1518+
return o == 1;
1519+
}
1520+
});
1521+
});
1522+
}
1523+
14871524
@Test
14881525
public void requestMore() {
14891526
Flowable.range(1, 5)

0 commit comments

Comments
 (0)