8000 Step 4: Transformations · blackbeltcoder/reactive-spring@f0416c0 · GitHub
[go: up one dir, main page]

Skip to content

Commit f0416c0

Browse files
committed
Step 4: Transformations
1 parent d6cbccd commit f0416c0

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* Copyright 2017 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package workshop;
17+
18+
import reactor.core.publisher.Flux;
19+
import reactor.core.publisher.Mono;
20+
import reactor.test.StepVerifier;
21+
22+
import org.junit.Test;
23+
24+
/**
25+
* Testing reactive transformations.
26+
*
27+
* @author Mark Paluch
28+
*/
29+
public class Step4Transformations {
30+
31+
@Test
32+
public void monoShouldMapValueToUpperCaseHelloWorld() {
33+
34+
Mono<String> mono = Mono.just("Heisenberg");
35+
36+
// TODO: Replace this line to transform the emitted element to uppercase
37+
// mono = …
38+
39+
StepVerifier.create(mono).expectNext("HEISENBERG").verifyComplete();
40+
}
41+
42+
@Test
43+
public void fluxShouldMapValueToUpperCaseHelloWorld() {
44+
45+
Flux<String> flux = Flux.just("Mike", "Gustavo");
46+
47+
// TODO: Replace this line to transform the emitted element to uppercase
48+
// flux = …
49+
50+
StepVerifier.create(flux).expectNext("MIKE", "GUSTAVO").verifyComplete();
51+
}
52+
53+
@Test
54+
public void monoShouldEmitIndividualCharactersAsString() {
55+
56+
Mono<String> mono = Mono.just("Schraderbräu");
57+
58+
// TODO: Replace this line to emit each character as single element
59+
Flux<String> flux = Flux.empty();
60+
61+
StepVerifier.create(flux).expectNext("S", "c", "h", "r", "a", "d", "e", "r", "b", "r", "ä", "u").verifyComplete();
62+
}
63+
64+
@Test
65+
public void fluxShouldConcatTwoMonos() {
66+
67+
Mono<String> hello = Mono.just("Breaking");
68+
Mono<String> world = Mono.just("Bad");
69+
70+
// TODO: Replace this line to compose a stream from the two Monos
71+
Flux<String> flux = Flux.empty();
72+
73+
StepVerifier.create(flux).expectNext("Breaking", "Bad").verifyComplete();
74+
}
75+
}

0 commit comments

Comments
 (0)
0