This repository has been archived by the owner on Jan 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 122
/
Test_2_6.java
67 lines (55 loc) · 2.07 KB
/
Test_2_6.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package com.getset;
import org.junit.Test;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
import reactor.test.publisher.PublisherProbe;
import reactor.test.publisher.TestPublisher;
import java.time.Duration;
public class Test_2_6 {
private Flux<String> appendBoomError(Flux<String> origin) {
return origin.concatWith(Mono.error(new RuntimeException("boom")));
}
@Test
public void testWithStepVerifier() {
Flux<String> source = Flux.just("foo", "bar");
StepVerifier.create(
appendBoomError(source))
.expectNext("foo")
.expectNext("bar")
.expectErrorMessage("boom")
.verify();
}
@Test
public void testVirtualTime() {
StepVerifier.withVirtualTime(() -> Mono.delay(Duration.ofDays(1)))
.expectSubscription() // 1
.expectNoEvent(Duration.ofDays(1)) // 2
.expectNext(0L)
.verifyComplete();
}
private Mono<String> executeCommand(String command) {
return Mono.just(command + " DONE");
}
private Mono<Void> processOrFallback(Mono<String> commandSource, Mono<Void> doWhenEmpty) {
return commandSource
.flatMap(command -> executeCommand(command).then())
.switchIfEmpty(doWhenEmpty);
}
@Test
public void testWithPublisherProbe() {
PublisherProbe<Void> probe = PublisherProbe.empty();
StepVerifier.create(processOrFallback(Mono.empty(), probe.mono()))
.verifyComplete();
probe.assertWasSubscribed();
probe.assertWasRequested();
probe.assertWasNotCancelled();
}
@Test
public void testWithTestPublisher() {
TestPublisher<Integer> testPublisher = TestPublisher.<Integer>create().emit(1, 2, 3);
StepVerifier.create(testPublisher.flux().map(i -> i * i))
.expectNext(1, 4, 9)
.expectComplete();
}
}