### Question:
Fetcher { GetLoginResponse getLogin() throws InterruptedException { final ClientResponse clientResponse = get(LOGIN_PATH, null); final String body = MonoUtils.unwrap(clientResponse.bodyToMono(String.class), TIMEOUT); if (StringUtils.isEmpty(body)) { throw new RuntimeException("An empty body received."); } return GetLoginResponse.builder() .body(body) .cookies(CookieUtils.normalize(clientResponse.cookies())) .build(); } Fetcher(
        final WebClient.Builder webClientBuilder
    );   }### Answer:
@Test public void getLoginTest() throws InterruptedException { final MockResponse mockResponse = new MockResponse() .setBody("body") .setHeader(HttpHeaders.SET_COOKIE, "name=value"); mockWebServer.enqueue(mockResponse); final MultiValueMap<String, String> expectedCookies = new LinkedMultiValueMap<>(); expectedCookies.set("name", "value"); final Fetcher.GetLoginResponse getLoginResponse = fetcher.getLogin(); assertEquals("body", getLoginResponse.getBody()); assertEquals(expectedCookies, getLoginResponse.getCookies()); final RecordedRequest recordedRequest = mockWebServer.takeRequest(1L, TimeUnit.SECONDS); assertEquals(1, mockWebServer.getRequestCount()); assertEquals(HttpMethod.GET.name(), recordedRequest.getMethod()); assertEquals(Fetcher.LOGIN_PATH, recordedRequest.getPath()); assertEquals(USER_AGENT, recordedRequest.getHeader(HttpHeaders.USER_AGENT)); }
@Test public void getLoginTest_emptyBody() throws InterruptedException { expectedException.expect(RuntimeException.class); expectedException.expectMessage("An empty body received."); final MockResponse mockResponse = new MockResponse() .setBody(StringUtils.EMPTY); mockWebServer.enqueue(mockResponse); fetcher.getLogin(); }
@Test public void getLoginTest_notFound() throws InterruptedException { expectedException.expect(RuntimeException.class); expectedException.expectMessage("Illegal status code :: statusCode=404"); final MockResponse mockResponse = new MockResponse() .setResponseCode(HttpStatus.NOT_FOUND.value()) .setBody("body"); mockWebServer.enqueue(mockResponse); fetcher.getLogin(); }