### Question:
Fetcher { void postAccount( final MultiValueMap<String, HttpEntity<?>> formData, final MultiValueMap<String, String> cookies ) throws InterruptedException { final ClientResponse clientResponse = post(ACCOUNT_PATH, formData, cookies); final HttpStatus statusCode = clientResponse.statusCode(); MonoUtils.unwrap(clientResponse.bodyToMono(String.class), TIMEOUT); if (!statusCode.is3xxRedirection()) { throw new RuntimeException( String.format("Illegal status code received. :: statusCode=%s", clientResponse.rawStatusCode())); } } Fetcher(
        final WebClient.Builder webClientBuilder
    );   }### Answer:
@Test @SneakyThrows public void postAccountTest() { final MockResponse mockResponse = new MockResponse() .setResponseCode(HttpStatus.SEE_OTHER.value()); mockWebServer.enqueue(mockResponse); final MultiValueMap<String, HttpEntity<?>> formData = new LinkedMultiValueMap<>(); formData.set("foo", new HttpEntity<>("1")); final MultiValueMap<String, String> cookies = new LinkedMultiValueMap<>(); cookies.set("bar", "2"); fetcher.postAccount(formData, cookies); final RecordedRequest recordedRequest = mockWebServer.takeRequest(); assertEquals(1, mockWebServer.getRequestCount()); assertEquals(HttpMethod.POST.name(), recordedRequest.getMethod()); assertEquals(Fetcher.ACCOUNT_PATH, recordedRequest.getPath()); assertEquals("bar=2", recordedRequest.getHeader(HttpHeaders.COOKIE)); final ContentType contentType = ContentType.parse(recordedRequest.getHeader(HttpHeaders.CONTENT_TYPE)); final String boundary = contentType.getParameter("boundary"); assertNotNull(boundary); final String body = recordedRequest.getBody().readUtf8(); System.out.println(body); final var multipartStream = new MultipartStream( new ByteArrayInputStream(body.getBytes(StandardCharsets.UTF_8)), boundary.getBytes(StandardCharsets.UTF_8), 4096, null); final String headerText = multipartStream.readHeaders(); final var fileUpload = new FileUpload() { public FileItemHeaders getParsedHeaders(String headerPart) { return super.getParsedHeaders(headerPart); } }; final var headers = fileUpload.getParsedHeaders(headerText); assertEquals("form-data; name=\"foo\"", headers.getHeader("Content-Disposition")); final var outputStream = new ByteArrayOutputStream(); multipartStream.readBodyData(outputStream); assertEquals("1", outputStream.toString(StandardCharsets.UTF_8)); }
@Test @SneakyThrows public void postAccountTest_illegalStatus() { expectedException.expect(RuntimeException.class); expectedException.expectMessage("Illegal status code received. :: statusCode=200"); final MockResponse mockResponse = new MockResponse() .setResponseCode(HttpStatus.OK.value()); mockWebServer.enqueue(mockResponse); final MultiValueMap<String, HttpEntity<?>> formData = new LinkedMultiValueMap<>(); formData.set("foo", new HttpEntity<>("1")); final MultiValueMap<String, String> cookies = new LinkedMultiValueMap<>(); cookies.set("bar", "2"); fetcher.postAccount(formData, cookies); }