15
15
*/
16
16
package com .greglturnquist .learningspringboot ;
17
17
18
+ import static org .assertj .core .api .Assertions .tuple ;
19
+ import static org .assertj .core .api .BDDAssertions .then ;
20
+ import static org .mockito .BDDMockito .*;
21
+
22
+ import java .io .File ;
23
+ import java .io .IOException ;
24
+ import java .nio .file .Files ;
25
+ import java .nio .file .Paths ;
26
+ import java .util .ArrayList ;
27
+
18
28
import org .junit .Before ;
19
29
import org .junit .Test ;
20
30
import org .junit .runner .RunWith ;
31
+ import reactor .core .publisher .Flux ;
32
+ import reactor .core .publisher .Mono ;
33
+ import reactor .test .StepVerifier ;
34
+
21
35
import org .springframework .beans .factory .annotation .Autowired ;
22
36
import org .springframework .boot .test .context .SpringBootTest ;
23
37
import org .springframework .boot .test .mock .mockito .MockBean ;
27
41
import org .springframework .test .context .junit4 .SpringRunner ;
28
42
import org .springframework .util .FileSystemUtils ;
29
43
import org .springframework .web .multipart .MultipartFile ;
30
- import reactor .core .publisher .Flux ;
31
- import reactor .core .publisher .Mono ;
32
- import java .io .File ;
33
- import java .io .IOException ;
34
- import java .nio .file .Files ;
35
- import java .nio .file .Paths ;
36
-
37
- import static org .assertj .core .api .Assertions .tuple ;
38
- import static org .assertj .core .api .BDDAssertions .then ;
39
- import static org .mockito .BDDMockito .*;
40
44
41
45
/**
42
46
* @author Greg Turnquist
@@ -77,13 +81,19 @@ public void findAllShouldJustReturnTheFlux() {
77
81
78
82
// then
79
83
then (images ).isNotNull ();
80
- then (images .collectList ().block ())
81
- .hasSize (2 )
82
- .extracting (Image ::getId , Image ::getName )
83
- .contains (
84
- tuple ("1" , "alpha.jpg" ),
85
- tuple ("2" , "bravo.jpg" )
86
- );
84
+
85
+ StepVerifier .create (images )
86
+ .recordWith (ArrayList ::new )
87
+ .expectNextCount (2 )
88
+ .consumeRecordedWith (results -> {
89
+ then (results )
90
+ .extracting (Image ::getId , Image ::getName )
91
+ .contains (
92
+ tuple ("1" , "alpha.jpg" ),
93
+ tuple ("2" , "bravo.jpg" )
94
+ );
95
+ })
96
+ .verifyComplete ();
87
97
}
88
98
89
99
@ Test
@@ -93,10 +103,15 @@ public void findOneShouldReturnNotYetFetchedUrl() {
93
103
94
104
// then
95
105
then (image ).isNotNull ();
96
- Resource resource = image .block ();
97
- then (resource .getDescription ()).isEqualTo ("URL [file:upload-dir/alpha.jpg]" );
98
- then (resource .exists ()).isFalse ();
99
- then (resource .getClass ()).isEqualTo (UrlResource .class );
106
+
107
+ StepVerifier .create (image )
108
+ .expectNextMatches (resource -> {
109
+ then (resource .getDescription ()).isEqualTo ("URL [file:upload-dir/alpha.jpg]" );
110
+ then (resource .exists ()).isFalse ();
111
+ then (resource .getClass ()).isEqualTo (UrlResource .class );
112
+ return true ;
113
+ })
114
+ .verifyComplete ();
100
115
}
101
116
102
117
@ Test
@@ -114,7 +129,8 @@ public void createImageShouldWork() {
114
129
Mono <Void > done = imageService .createImage (Flux .just (file1 , file2 ));
115
130
116
131
// then
117
- then (done .block ()).isNull ();
132
+ StepVerifier .create (done )
133
+ .verifyComplete ();
118
134
}
119
135
120
136
@ Test
@@ -129,7 +145,8 @@ public void deleteImageShouldWork() {
129
145
Mono <Void > done = imageService .deleteImage (imageName );
130
146
131
147
// then
132
- then (done .block ()).isNull ();
148
+ StepVerifier .create (done )
149
+ .verifyComplete ();
133
150
}
134
151
135
152
}
0 commit comments