@@ -135,8 +135,7 @@ static void afterAll() {
135135 @ Test
136136 @ DisplayName ("Successful authentication" )
137137 void successfulAuthentication () {
138- Microservices caller = newCaller ();
139- try {
138+ try (Microservices caller = newCaller ()) {
140139 SecuredService securedService = caller .call ().api (SecuredService .class );
141140
142141 StepVerifier .create (securedService .helloWithRequest ("Bob" ))
@@ -150,16 +149,13 @@ void successfulAuthentication() {
150149 StepVerifier .create (securedService .helloWithRequestAndPrincipal ("Bob" ))
151150 .assertNext (response -> assertEquals ("Hello, Bob and Alice" , response ))
152151 .verifyComplete ();
153- } finally {
154- caller .shutdown ().block (TIMEOUT );
155152 }
156153 }
157154
158155 @ Test
159156 @ DisplayName ("Authentication failed if authenticator not provided" )
160157 void failedAuthenticationWhenAuthenticatorNotProvided () {
161- Microservices caller = newCaller ();
162- try {
158+ try (Microservices caller = newCaller ()) {
163159 AnotherSecuredService securedService = caller .call ().api (AnotherSecuredService .class );
164160
165161 Consumer <Throwable > verifyError =
@@ -179,16 +175,13 @@ void failedAuthenticationWhenAuthenticatorNotProvided() {
179175 StepVerifier .create (securedService .helloWithRequestAndPrincipal ("Bob" ))
180176 .expectErrorSatisfies (verifyError )
181177 .verify ();
182- } finally {
183- caller .shutdown ().block (TIMEOUT );
184178 }
185179 }
186180
187181 @ Test
188182 @ DisplayName ("Authentication failed with empty credentials" )
189183 void failedAuthenticationWithEmptyCredentials () {
190- Microservices caller = newEmptyCredentialsCaller ();
191- try {
184+ try (Microservices caller = newEmptyCredentialsCaller ()) {
192185 SecuredService securedService = caller .call ().api (SecuredService .class );
193186
194187 Consumer <Throwable > verifyError =
@@ -208,16 +201,13 @@ void failedAuthenticationWithEmptyCredentials() {
208201 StepVerifier .create (securedService .helloWithRequestAndPrincipal ("Bob" ))
209202 .expectErrorSatisfies (verifyError )
210203 .verify ();
211- } finally {
212- caller .shutdown ().block (TIMEOUT );
213204 }
214205 }
215206
216207 @ Test
217208 @ DisplayName ("Authentication failed with invalid credentials" )
218209 void failedAuthenticationWithInvalidCredentials () {
219- Microservices caller = newInvalidCredentialsCaller ();
220- try {
210+ try (Microservices caller = newInvalidCredentialsCaller ()) {
221211 SecuredService securedService = caller .call ().api (SecuredService .class );
222212
223213 Consumer <Throwable > verifyError =
@@ -237,32 +227,26 @@ void failedAuthenticationWithInvalidCredentials() {
237227 StepVerifier .create (securedService .helloWithRequestAndPrincipal ("Bob" ))
238228 .expectErrorSatisfies (verifyError )
239229 .verify ();
240- } finally {
241- caller .shutdown ().block (TIMEOUT );
242230 }
243231 }
244232
245233 @ Test
246234 @ DisplayName ("Successful authentication of partially secured service" )
247235 void successfulAuthenticationOnPartiallySecuredService () {
248- Microservices caller = newCaller ();
249- try {
236+ try (Microservices caller = newCaller ()) {
250237 StepVerifier .create (caller .call ().api (PartiallySecuredService .class ).securedMethod ("Alice" ))
251238 .assertNext (response -> assertEquals ("Hello, Alice" , response ))
252239 .verifyComplete ();
253240 StepVerifier .create (caller .call ().api (PartiallySecuredService .class ).publicMethod ("Alice" ))
254241 .assertNext (response -> assertEquals ("Hello, Alice" , response ))
255242 .verifyComplete ();
256- } finally {
257- caller .shutdown ().block (TIMEOUT );
258243 }
259244 }
260245
261246 @ Test
262247 @ DisplayName ("Successful call public method of partially secured service without authentication" )
263248 void successfulCallOfPublicMethodWithoutAuthentication () {
264- Microservices caller = newCaller ();
265- try {
249+ try (Microservices caller = newCaller ()) {
266250 StepVerifier .create (caller .call ().api (PartiallySecuredService .class ).publicMethod ("Alice" ))
267251 .assertNext (response -> assertEquals ("Hello, Alice" , response ))
268252 .verifyComplete ();
@@ -275,8 +259,6 @@ void successfulCallOfPublicMethodWithoutAuthentication() {
275259
276260 StepVerifier .create (caller .call ().api (PartiallySecuredService .class ).securedMethod ("Alice" ))
277261 .verifyErrorSatisfies (verifyError );
278- } finally {
279- caller .shutdown ().block (TIMEOUT );
280262 }
281263 }
282264
0 commit comments