@@ -62,47 +62,46 @@ public class ReactiveMongoOperationsSessionRepositoryTest {
62
62
private MongoOperations blockingMongoOperations ;
63
63
64
64
@ Before
65
- public void setUp () throws Exception {
65
+ public void setUp () {
66
66
67
67
this .repository = new ReactiveMongoOperationsSessionRepository (this .mongoOperations );
68
68
this .repository .setMongoSessionConverter (this .converter );
69
69
}
70
70
71
71
@ Test
72
- public void shouldCreateSession () throws Exception {
72
+ public void shouldCreateSession () {
73
73
74
- // when
75
- Mono <MongoSession > session = this .repository .createSession ();
76
-
77
- // then
78
- StepVerifier .create (session )
74
+ this .repository .createSession ()
75
+ .as (StepVerifier ::create )
79
76
.expectNextMatches (mongoSession -> {
80
77
assertThat (mongoSession .getId ()).isNotEmpty ();
81
78
assertThat (mongoSession .getMaxInactiveInterval ().getSeconds ())
82
79
.isEqualTo (ReactiveMongoOperationsSessionRepository .DEFAULT_INACTIVE_INTERVAL );
83
80
return true ;
84
- });
81
+ })
82
+ .verifyComplete ();
85
83
}
86
84
87
85
@ Test
88
- public void shouldCreateSessionWhenMaxInactiveIntervalNotDefined () throws Exception {
86
+ public void shouldCreateSessionWhenMaxInactiveIntervalNotDefined () {
89
87
90
88
// when
91
89
this .repository .setMaxInactiveIntervalInSeconds (null );
92
- Mono <MongoSession > session = this .repository .createSession ();
93
90
94
91
// then
95
- StepVerifier .create (session )
92
+ this .repository .createSession ()
93
+ .as (StepVerifier ::create )
96
94
.expectNextMatches (mongoSession -> {
97
95
assertThat (mongoSession .getId ()).isNotEmpty ();
98
96
assertThat (mongoSession .getMaxInactiveInterval ().getSeconds ())
99
97
.isEqualTo (ReactiveMongoOperationsSessionRepository .DEFAULT_INACTIVE_INTERVAL );
100
98
return true ;
101
- });
99
+ })
100
+ .verifyComplete ();
102
101
}
103
102
104
103
@ Test
105
- public void shouldSaveSession () throws Exception {
104
+ public void shouldSaveSession () {
106
105
107
106
// given
108
107
MongoSession session = new MongoSession ();
@@ -115,16 +114,15 @@ public void shouldSaveSession() throws Exception {
115
114
given (this .mongoOperations .save (dbSession , "sessions" )).willReturn (Mono .just (dbSession ));
116
115
117
116
// when
118
- StepVerifier .create (this .repository .save (session ))
119
- .expectNextMatches (aVoid -> {
120
- // then
121
- verify (this .mongoOperations ).save (dbSession , ReactiveMongoOperationsSessionRepository .DEFAULT_COLLECTION_NAME );
122
- return true ;
123
- });
117
+ this .repository .save (session )
118
+ .as (StepVerifier ::create )
119
+ .verifyComplete ();
120
+
121
+ verify (this .mongoOperations ).save (dbSession , ReactiveMongoOperationsSessionRepository .DEFAULT_COLLECTION_NAME );
124
122
}
125
123
126
124
@ Test
127
- public void shouldGetSession () throws Exception {
125
+ public void shouldGetSession () {
128
126
129
127
// given
130
128
String sessionId = UUID .randomUUID ().toString ();
@@ -139,16 +137,14 @@ public void shouldGetSession() throws Exception {
139
137
TypeDescriptor .valueOf (MongoSession .class ))).willReturn (session );
140
138
141
139
// when
142
- StepVerifier .create (this .repository .findById (sessionId ))
143
- .expectNextMatches (retrievedSession -> {
144
- // then
145
- assertThat (retrievedSession ).isEqualTo (session );
146
- return true ;
147
- });
140
+ this .repository .findById (sessionId )
141
+ .as (StepVerifier ::create )
142
+ .expectNext (session )
143
+ .verifyComplete ();
148
144
}
149
145
150
146
@ Test
151
- public void shouldHandleExpiredSession () throws Exception {
147
+ public void shouldHandleExpiredSession () {
152
148
153
149
// given
154
150
String sessionId = UUID .randomUUID ().toString ();
@@ -157,43 +153,50 @@ public void shouldHandleExpiredSession() throws Exception {
157
153
given (this .mongoOperations .findById (sessionId , Document .class ,
158
154
ReactiveMongoOperationsSessionRepository .DEFAULT_COLLECTION_NAME )).willReturn (Mono .just (sessionDocument ));
159
155
156
+ given (this .mongoOperations .remove (sessionDocument , ReactiveMongoOperationsSessionRepository .DEFAULT_COLLECTION_NAME ))
157
+ .willReturn (Mono .just (DeleteResult .acknowledged (1 )));
158
+
160
159
MongoSession session = mock (MongoSession .class );
161
160
162
161
given (session .isExpired ()).willReturn (true );
163
162
given (this .converter .convert (sessionDocument , TypeDescriptor .valueOf (Document .class ),
164
163
TypeDescriptor .valueOf (MongoSession .class ))).willReturn (session );
165
164
166
165
// when
167
- StepVerifier .create (this .repository .findById (sessionId ))
168
- .expectNextMatches (mongoSession -> {
169
- // then
170
- verify (this .mongoOperations ).remove (any (Document .class ),
171
- eq (ReactiveMongoOperationsSessionRepository .DEFAULT_COLLECTION_NAME ));
172
- return true ;
173
- });
166
+ this .repository .findById (sessionId )
167
+ .as (StepVerifier ::create )
168
+ .verifyComplete ();
174
169
170
+ // then
171
+ verify (this .mongoOperations ).remove (any (Document .class ),
172
+ eq (ReactiveMongoOperationsSessionRepository .DEFAULT_COLLECTION_NAME ));
175
173
}
176
174
177
175
@ Test
178
- public void shouldDeleteSession () throws Exception {
176
+ public void shouldDeleteSession () {
179
177
180
178
// given
181
179
String sessionId = UUID .randomUUID ().toString ();
182
-
183
180
Document sessionDocument = new Document ();
184
181
185
- given (this .mongoOperations .findById (eq (sessionId ), eq (Document .class ),
186
- eq (ReactiveMongoOperationsSessionRepository .DEFAULT_COLLECTION_NAME ))).willReturn (Mono .just (sessionDocument ));
187
- given (this .mongoOperations .remove ((Mono <? extends Object >) any (), eq ("sessions" ))).willReturn (Mono .just (DeleteResult .acknowledged (1 )));
182
+ given (this .mongoOperations .findById (sessionId , Document .class ,
183
+ ReactiveMongoOperationsSessionRepository .DEFAULT_COLLECTION_NAME )).willReturn (Mono .just (sessionDocument ));
184
+
185
+ given (this .mongoOperations .remove (sessionDocument , "sessions" ))
186
+ .willReturn (Mono .just (DeleteResult .acknowledged (1 )));
187
+
188
+ MongoSession session = mock (MongoSession .class );
189
+
190
+ given (this .converter .convert (sessionDocument , TypeDescriptor .valueOf (Document .class ),
191
+ TypeDescriptor .valueOf (MongoSession .class ))).willReturn (session );
188
192
189
193
// when
190
- StepVerifier .create (this .repository .deleteById (sessionId ))
191
- .expectNextMatches (aVoid -> {
192
- // then
193
- verify (this .mongoOperations ).remove (any (Document .class ),
194
- eq (ReactiveMongoOperationsSessionRepository .DEFAULT_COLLECTION_NAME ));
195
- return true ;
196
- });
194
+ this .repository .deleteById (sessionId )
195
+ .as (StepVerifier ::create )
196
+ .verifyComplete ();
197
+
198
+ verify (this .mongoOperations ).remove (any (Document .class ),
199
+ eq (ReactiveMongoOperationsSessionRepository .DEFAULT_COLLECTION_NAME ));
197
200
}
198
201
199
202
@ Test
0 commit comments