Skip to content

Commit

Permalink
3.x: Fix Junit 4.13 deprecated API use (ReactiveX#6813)
Browse files Browse the repository at this point in the history
  • Loading branch information
akarnokd authored Jan 7, 2020
1 parent a864594 commit 45c0b06
Show file tree
Hide file tree
Showing 4 changed files with 377 additions and 411 deletions.
196 changes: 93 additions & 103 deletions src/test/java/io/reactivex/rxjava3/observers/TestObserverTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@
import java.util.*;
import java.util.concurrent.TimeUnit;

import org.junit.*;
import org.junit.rules.ExpectedException;
import org.junit.Test;
import org.mockito.InOrder;
import org.reactivestreams.Subscriber;

import io.reactivex.rxjava3.core.*;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.core.Observer;
import io.reactivex.rxjava3.disposables.*;
import io.reactivex.rxjava3.disposables.Disposable;
import io.reactivex.rxjava3.exceptions.TestException;
import io.reactivex.rxjava3.functions.Predicate;
import io.reactivex.rxjava3.internal.functions.Functions;
Expand All @@ -40,9 +39,6 @@

public class TestObserverTest extends RxJavaTest {

@Rule
public ExpectedException thrown = ExpectedException.none();

@Test
public void assertTestObserver() {
Flowable<Integer> oi = Flowable.fromIterable(Arrays.asList(1, 2));
Expand All @@ -56,50 +52,44 @@ public void assertTestObserver() {

@Test
public void assertNotMatchCount() {
Flowable<Integer> oi = Flowable.fromIterable(Arrays.asList(1, 2));
TestSubscriber<Integer> subscriber = new TestSubscriber<>();
oi.subscribe(subscriber);

thrown.expect(AssertionError.class);
// FIXME different message format
// thrown.expectMessage("Number of items does not match. Provided: 1 Actual: 2");

subscriber.assertValue(1);
subscriber.assertValueCount(2);
subscriber.assertComplete().assertNoErrors();
assertThrows(AssertionError.class, () -> {
Flowable<Integer> oi = Flowable.fromIterable(Arrays.asList(1, 2));
TestSubscriber<Integer> subscriber = new TestSubscriber<>();
oi.subscribe(subscriber);

subscriber.assertValue(1);
subscriber.assertValueCount(2);
subscriber.assertComplete().assertNoErrors();
});
}

@Test
public void assertNotMatchValue() {
Flowable<Integer> oi = Flowable.fromIterable(Arrays.asList(1, 2));
TestSubscriber<Integer> subscriber = new TestSubscriber<>();
oi.subscribe(subscriber);

thrown.expect(AssertionError.class);
// FIXME different message format
// thrown.expectMessage("Value at index: 1 expected to be [3] (Integer) but was: [2] (Integer)");

subscriber.assertValues(1, 3);
subscriber.assertValueCount(2);
subscriber.assertComplete().assertNoErrors();
assertThrows(AssertionError.class, () -> {
Flowable<Integer> oi = Flowable.fromIterable(Arrays.asList(1, 2));
TestSubscriber<Integer> subscriber = new TestSubscriber<>();
oi.subscribe(subscriber);

subscriber.assertValues(1, 3);
subscriber.assertValueCount(2);
subscriber.assertComplete().assertNoErrors();
});
}

@Test
public void assertTerminalEventNotReceived() {
PublishProcessor<Integer> p = PublishProcessor.create();
TestSubscriber<Integer> subscriber = new TestSubscriber<>();
p.subscribe(subscriber);

p.onNext(1);
p.onNext(2);
assertThrows(AssertionError.class, () -> {
PublishProcessor<Integer> p = PublishProcessor.create();
TestSubscriber<Integer> subscriber = new TestSubscriber<>();
p.subscribe(subscriber);

thrown.expect(AssertionError.class);
// FIXME different message format
// thrown.expectMessage("No terminal events received.");
p.onNext(1);
p.onNext(2);

subscriber.assertValues(1, 2);
subscriber.assertValueCount(2);
subscriber.assertComplete().assertNoErrors();
subscriber.assertValues(1, 2);
subscriber.assertValueCount(2);
subscriber.assertComplete().assertNoErrors();
});
}

@Test
Expand Down Expand Up @@ -853,16 +843,16 @@ public void errorMeansDisposed() {

@Test
public void assertValuePredicateEmpty() {
TestObserver<Object> to = new TestObserver<>();
assertThrows("No values", AssertionError.class, () -> {
TestObserver<Object> to = new TestObserver<>();

Observable.empty().subscribe(to);
Observable.empty().subscribe(to);

thrown.expect(AssertionError.class);
thrown.expectMessage("No values");
to.assertValue(new Predicate<Object>() {
@Override public boolean test(final Object o) throws Exception {
return false;
}
to.assertValue(new Predicate<Object>() {
@Override public boolean test(final Object o) throws Exception {
return false;
}
});
});
}

Expand All @@ -881,46 +871,46 @@ public void assertValuePredicateMatch() {

@Test
public void assertValuePredicateNoMatch() {
TestObserver<Integer> to = new TestObserver<>();
assertThrows("Value not present", AssertionError.class, () -> {
TestObserver<Integer> to = new TestObserver<>();

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

thrown.expect(AssertionError.class);
thrown.expectMessage("Value not present");
to.assertValue(new Predicate<Integer>() {
@Override public boolean test(final Integer o) throws Exception {
return o != 1;
}
to.assertValue(new Predicate<Integer>() {
@Override public boolean test(final Integer o) throws Exception {
return o != 1;
}
});
});
}

@Test
public void assertValuePredicateMatchButMore() {
TestObserver<Integer> to = new TestObserver<>();
assertThrows("Value present but other values as well", AssertionError.class, () -> {
TestObserver<Integer> to = new TestObserver<>();

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

thrown.expect(AssertionError.class);
thrown.expectMessage("Value present but other values as well");
to.assertValue(new Predicate<Integer>() {
@Override public boolean test(final Integer o) throws Exception {
return o == 1;
}
to.assertValue(new Predicate<Integer>() {
@Override public boolean test(final Integer o) throws Exception {
return o == 1;
}
});
});
}

@Test
public void assertValueAtPredicateEmpty() {
TestObserver<Object> to = new TestObserver<>();
assertThrows("No values", AssertionError.class, () -> {
TestObserver<Object> to = new TestObserver<>();

Observable.empty().subscribe(to);
Observable.empty().subscribe(to);

thrown.expect(AssertionError.class);
thrown.expectMessage("No values");
to.assertValueAt(0, new Predicate<Object>() {
@Override public boolean test(final Object o) throws Exception {
return false;
}
to.assertValueAt(0, new Predicate<Object>() {
@Override public boolean test(final Object o) throws Exception {
return false;
}
});
});
}

Expand All @@ -939,43 +929,43 @@ public void assertValueAtPredicateMatch() {

@Test
public void assertValueAtPredicateNoMatch() {
TestObserver<Integer> to = new TestObserver<>();
assertThrows("Value not present", AssertionError.class, () -> {
TestObserver<Integer> to = new TestObserver<>();

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

thrown.expect(AssertionError.class);
thrown.expectMessage("Value not present");
to.assertValueAt(2, new Predicate<Integer>() {
@Override public boolean test(final Integer o) throws Exception {
return o != 3;
}
to.assertValueAt(2, new Predicate<Integer>() {
@Override public boolean test(final Integer o) throws Exception {
return o != 3;
}
});
});
}

@Test
public void assertValueAtInvalidIndex() {
TestObserver<Integer> to = new TestObserver<>();
assertThrows("Invalid index: 2 (latch = 0, values = 2, errors = 0, completions = 1)", AssertionError.class, () -> {
TestObserver<Integer> to = new TestObserver<>();

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

thrown.expect(AssertionError.class);
thrown.expectMessage("Invalid index: 2 (latch = 0, values = 2, errors = 0, completions = 1)");
to.assertValueAt(2, new Predicate<Integer>() {
@Override public boolean test(final Integer o) throws Exception {
return o == 1;
}
to.assertValueAt(2, new Predicate<Integer>() {
@Override public boolean test(final Integer o) throws Exception {
return o == 1;
}
});
});
}

@Test
public void assertValueAtIndexEmpty() {
TestObserver<Object> to = new TestObserver<>();
assertThrows("No values", AssertionError.class, () -> {
TestObserver<Object> to = new TestObserver<>();

Observable.empty().subscribe(to);
Observable.empty().subscribe(to);

thrown.expect(AssertionError.class);
thrown.expectMessage("No values");
to.assertValueAt(0, "a");
to.assertValueAt(0, "a");
});
}

@Test
Expand All @@ -989,24 +979,24 @@ public void assertValueAtIndexMatch() {

@Test
public void assertValueAtIndexNoMatch() {
TestObserver<String> to = new TestObserver<>();
assertThrows("expected: b (class: String) but was: c (class: String) (latch = 0, values = 3, errors = 0, completions = 1)", AssertionError.class, () -> {
TestObserver<String> to = new TestObserver<>();

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

thrown.expect(AssertionError.class);
thrown.expectMessage("expected: b (class: String) but was: c (class: String) (latch = 0, values = 3, errors = 0, completions = 1)");
to.assertValueAt(2, "b");
to.assertValueAt(2, "b");
});
}

@Test
public void assertValueAtIndexInvalidIndex() {
TestObserver<String> to = new TestObserver<>();
assertThrows("Invalid index: 2 (latch = 0, values = 2, errors = 0, completions = 1)", AssertionError.class, () -> {
TestObserver<String> to = new TestObserver<>();

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

thrown.expect(AssertionError.class);
thrown.expectMessage("Invalid index: 2 (latch = 0, values = 2, errors = 0, completions = 1)");
to.assertValueAt(2, "c");
to.assertValueAt(2, "c");
});
}

@Test
Expand Down
Loading

0 comments on commit 45c0b06

Please sign in to comment.