Skip to content

Commit

Permalink
Verify assertValueAt with negative index
Browse files Browse the repository at this point in the history
  • Loading branch information
akarnokd committed Dec 6, 2020
1 parent 978ff26 commit 8ceb70f
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/test/java/io/reactivex/rxjava3/observers/TestObserverTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -962,6 +962,21 @@ public void assertValueAtInvalidIndex() {
});
}

@Test
public void assertValueAtInvalidIndexNegative() {
assertThrowsWithMessage("Index -2 is out of range [0, 2) (latch = 0, values = 2, errors = 0, completions = 1)", AssertionError.class, () -> {
TestObserver<Integer> to = new TestObserver<>();

Observable.just(1, 2).subscribe(to);

to.assertValueAt(-2, new Predicate<Integer>() {
@Override public boolean test(final Integer o) throws Exception {
return o == 1;
}
});
});
}

@Test
public void assertValueAtIndexEmpty() {
assertThrowsWithMessage("No values (latch = 0, values = 0, errors = 0, completions = 1)", AssertionError.class, () -> {
Expand Down Expand Up @@ -1004,6 +1019,17 @@ public void assertValueAtIndexInvalidIndex() {
});
}

@Test
public void assertValueAtIndexInvalidIndexNegative() {
assertThrowsWithMessage("Index -2 is out of range [0, 2) (latch = 0, values = 2, errors = 0, completions = 1)", AssertionError.class, () -> {
TestObserver<String> to = new TestObserver<>();

Observable.just("a", "b").subscribe(to);

to.assertValueAt(-2, "c");
});
}

@Test
public void withTag() {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1484,6 +1484,43 @@ public void assertValueAtInvalidIndex() {
});
}

@Test
public void assertValueAtIndexInvalidIndex() {
assertThrowsWithMessage("Index 2 is out of range [0, 2) (latch = 0, values = 2, errors = 0, completions = 1)", AssertionError.class, () -> {
TestSubscriber<Integer> ts = new TestSubscriber<>();

Flowable.just(1, 2).subscribe(ts);

ts.assertValueAt(2, 3);
});
}

@Test
public void assertValueAtIndexInvalidIndexNegative() {
assertThrowsWithMessage("Index -2 is out of range [0, 2) (latch = 0, values = 2, errors = 0, completions = 1)", AssertionError.class, () -> {
TestSubscriber<Integer> ts = new TestSubscriber<>();

Flowable.just(1, 2).subscribe(ts);

ts.assertValueAt(-2, 3);
});
}

@Test
public void assertValueAtInvalidIndexNegative() {
assertThrowsWithMessage("Index -2 is out of range [0, 2) (latch = 0, values = 2, errors = 0, completions = 1)", AssertionError.class, () -> {
TestSubscriber<Integer> ts = new TestSubscriber<>();

Flowable.just(1, 2).subscribe(ts);

ts.assertValueAt(-2, new Predicate<Integer>() {
@Override public boolean test(final Integer o) throws Exception {
return o == 1;
}
});
});
}

@Test
public void requestMore() {
Flowable.range(1, 5)
Expand Down

0 comments on commit 8ceb70f

Please sign in to comment.