Skip to content

Commit 0194a94

Browse files
committed
2.1 Added alternative Rx contract example
1 parent 41c22d9 commit 0194a94

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

tests/java/itrx/chapter1/RxContractExample.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,24 @@ public void example() {
2020

2121
// 0
2222
}
23+
24+
public void examplePrintCompletion() {
25+
Subject<Integer, Integer> values = ReplaySubject.create();
26+
values.subscribe(
27+
v -> System.out.println(v),
28+
e -> System.out.println(e),
29+
() -> System.out.println("Completed")
30+
);
31+
values.onNext(0);
32+
values.onNext(1);
33+
values.onCompleted();
34+
values.onNext(2);
35+
36+
// 0
37+
// 1
38+
}
2339

40+
2441
//
2542
// Test
2643
//
@@ -40,5 +57,21 @@ public void test() {
4057
tester.assertTerminalEvent();
4158
tester.assertNoErrors();
4259
}
60+
61+
@Test
62+
public void testPrintCompletion() {
63+
TestSubscriber<Integer> tester = new TestSubscriber<Integer>();
64+
65+
Subject<Integer, Integer> values = ReplaySubject.create();
66+
values.subscribe(tester);
67+
values.onNext(0);
68+
values.onNext(1);
69+
values.onCompleted();
70+
values.onNext(2);
71+
72+
tester.assertReceivedOnNext(Arrays.asList(0,1));
73+
tester.assertTerminalEvent();
74+
tester.assertNoErrors();
75+
}
4376

4477
}

0 commit comments

Comments
 (0)