4040import org .junit .jupiter .api .BeforeEach ;
4141import org .junit .jupiter .api .Test ;
4242import org .junit .jupiter .api .extension .ExtendWith ;
43+ import org .mockito .ArgumentCaptor ;
4344import org .mockito .InOrder ;
4445import org .mockito .Mock ;
4546import org .mockito .junit .jupiter .MockitoExtension ;
@@ -181,7 +182,7 @@ void verifySendingRequest_whenThereIsAGenericHttpError() {
181182
182183 httpRequestService .run ();
183184
184- verify ( callback ). onRequestFailed ( new HttpErrorException ( 500 , "Error message" ) );
185+ verifyRequestFailedCallback ( 500 );
185186 verifyNoInteractions (executor );
186187 }
187188
@@ -195,7 +196,7 @@ void verifySendingRequest_whenThereIsATooManyRequestsError() {
195196
196197 httpRequestService .run ();
197198
198- verify ( callback ). onRequestFailed ( new HttpErrorException ( 429 , "Error message" ) );
199+ verifyRequestFailedCallback ( 429 );
199200 verify (executor ).setPeriodicDelay (periodicRetryDelay );
200201 verify (periodicRetryDelay , never ()).suggestDelay (any ());
201202 }
@@ -211,7 +212,7 @@ void verifySendingRequest_whenThereIsATooManyRequestsError_withSuggestedDelay()
211212
212213 httpRequestService .run ();
213214
214- verify ( callback ). onRequestFailed ( new HttpErrorException ( 429 , "Error message" ) );
215+ verifyRequestFailedCallback ( 429 );
215216 verify (executor ).setPeriodicDelay (periodicRetryDelay );
216217 verify (periodicRetryDelay ).suggestDelay (Duration .ofSeconds (5 ));
217218 }
@@ -267,7 +268,7 @@ void verifySendingRequest_whenThereIsAServiceUnavailableError() {
267268
268269 httpRequestService .run ();
269270
270- verify ( callback ). onRequestFailed ( new HttpErrorException ( 503 , "Error message" ) );
271+ verifyRequestFailedCallback ( 503 );
271272 verify (executor ).setPeriodicDelay (periodicRetryDelay );
272273 verify (periodicRetryDelay , never ()).suggestDelay (any ());
273274 }
@@ -283,11 +284,18 @@ void verifySendingRequest_whenThereIsAServiceUnavailableError_withSuggestedDelay
283284
284285 httpRequestService .run ();
285286
286- verify ( callback ). onRequestFailed ( new HttpErrorException ( 503 , "Error message" ) );
287+ verifyRequestFailedCallback ( 503 );
287288 verify (executor ).setPeriodicDelay (periodicRetryDelay );
288289 verify (periodicRetryDelay ).suggestDelay (Duration .ofSeconds (2 ));
289290 }
290291
292+ private void verifyRequestFailedCallback (int errorCode ) {
293+ ArgumentCaptor <HttpErrorException > captor = ArgumentCaptor .forClass (HttpErrorException .class );
294+ verify (callback ).onRequestFailed (captor .capture ());
295+ assertThat (captor .getValue ().getErrorCode ()).isEqualTo (errorCode );
296+ assertThat (captor .getValue ().getMessage ()).isEqualTo ("Error message" );
297+ }
298+
291299 @ Test
292300 void verifySendingRequest_duringRegularMode () {
293301 httpRequestService .sendRequest ();
0 commit comments