import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
-import org.junit.jupiter.params.provider.ValueSource;
+import org.junit.jupiter.params.provider.EnumSource;
import org.mockito.ArgumentCaptor;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import org.springframework.boot.test.mock.mockito.MockBean;
+import org.springframework.http.HttpStatus;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.ui.Model;
import org.springframework.web.reactive.function.client.WebClientResponseException;
*/
@DisplayName("Other error while fetching data from remote-server")
@ParameterizedTest(name = "{arguments} ==> HTTP-status={0}")
- @ValueSource(ints = { 400, 401, 403, 405, 406, 409, 410, 415, 422, 429, 500, 501, 502, 503, 504 })
- void testOtherError(int status)
+ @EnumSource(value = HttpStatus.class, names = {
+ "BAD_REQUEST",
+ "UNAUTHORIZED",
+ "FORBIDDEN",
+ "METHOD_NOT_ALLOWED",
+ "NOT_ACCEPTABLE",
+ "CONFLICT",
+ "GONE",
+ "UNSUPPORTED_MEDIA_TYPE",
+ "TOO_MANY_REQUESTS",
+ "UNPROCESSABLE_ENTITY",
+ "INTERNAL_SERVER_ERROR",
+ "NOT_IMPLEMENTED",
+ "BAD_GATEWAY",
+ "SERVICE_UNAVAILABLE",
+ "GATEWAY_TIMEOUT"
+ })
+ void testOtherError(HttpStatus status)
{
- Mono<String> mono = Mono.error(WebClientResponseException.create(status, "", null, null, null));
+ Mono<String> mono = Mono.error(WebClientResponseException.create(status.value(), "", null, null, null));
when(service.getRemoteText("foo")).thenReturn(mono);
String result = controller.fetch(model, "foo");
verify(model).addAttribute(eq("text"), captor.capture());
StepVerifier
.create(captor.getValue())
- .expectNextMatches(message -> message.startsWith(Integer.toString(status)))
+ .expectNextMatches(message -> message.startsWith(Integer.toString(status.value())))
.expectComplete()
.verify();
}