import org.junit.jupiter.api.DisplayName;
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.mockito.ArgumentCaptor;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.verify;
.expectComplete()
.verify();
}
+
+ /**
+ * Only the behavior on the common errors, as defined in {@link
+ * WebClientResponseException#create(int, String, org.springframework.http.HttpHeaders, byte[], java.nio.charset.Charset, org.springframework.http.HttpRequest)
+ * WebClientResponseException.create()} is tested.
+ */
+ @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)
+ {
+ Mono<String> mono = Mono.error(WebClientResponseException.create(status, "", null, null, null));
+ when(service.getRemoteText("foo")).thenReturn(mono);
+
+ String result = controller.fetch(model, "foo");
+
+ assertThat(result).isEqualTo("home");
+ ArgumentCaptor<Mono<String>> captor = ArgumentCaptor.forClass(Mono.class);
+ verify(model).addAttribute(eq("text"), captor.capture());
+ StepVerifier
+ .create(captor.getValue())
+ .expectNextMatches(message -> message.startsWith(Integer.toString(status)))
+ .expectComplete()
+ .verify();
+ }
}