@Test public void useDefaultMockWebServer() { assertThat(new MockWebServerPlus().server()).isNotNull(); }
@Test public void enqueueSocketPolicy() throws IOException { server.enqueue(SocketPolicy.KEEP_OPEN); QueueDispatcher dispatcher = new QueueDispatcher(); server.setDispatcher(dispatcher); MockResponse mockResponse = dispatcher.peek(); assertThat(mockResponse.getSocketPolicy()).isEqualTo(SocketPolicy.KEEP_OPEN); }
@Test public void getRecordedRequest() throws IOException, InterruptedException { server.enqueue(new MockResponse()); execute(); RecordedRequest recordedRequest = server.takeRequest(); assertThat(recordedRequest).isNotNull(); }
@Test public void enqueueWithoutBody() throws Exception { server.enqueue(Fixtures.SIMPLE_NO_BODY); Response response = execute(); assertFixture(response).statusCode(200); }
private Response execute(String url) throws IOException { Request request = new Request.Builder() .url(server.url(url)) .get() .build(); return httpClient.newCall(request).execute(); }
@Test public void getMockServerInstance() { assertThat(server.server()).isEqualTo(mockWebServer); }
@Test public void enqueueWithoutHeaders() throws Exception { server.enqueue(Fixtures.SIMPLE_NO_HEADERS); Response response = execute(); assertFixture(response) .body(JSON_RESPONSE) .statusCode(200); }
private Response execute() throws IOException { return execute(server.url("/")); }
@Test public void interceptDispatch() throws InterruptedException, IOException { Dispatcher dispatcher = spy(new QueueDispatcher()); server.setDispatcher(dispatcher); server.enqueue(new MockResponse()); execute(); verify(dispatcher).dispatch(any(RecordedRequest.class)); }
@Test public void enqueueWithoutStatusCode() throws Exception { server.enqueue(Fixtures.SIMPLE_NO_STATUS_CODE); Response response = execute(); assertFixture(response) .body(JSON_RESPONSE) .statusCode(200); }
@Test public void generateValidUrl() { assertThat(server.url("")).isNotNull(); }
@Test public void enqueueSingleResponse() throws Exception { server.enqueue(Fixtures.SIMPLE); Response response = execute(); assertFixture(response) .body(JSON_RESPONSE) .statusCode(200) .header("Auth", "auth") .header("key", "value"); }
@Test public void enqueueMultipleResponse() throws Exception { server.enqueue(Fixtures.SIMPLE, Fixtures.SIMPLE); Response response = execute(); assertFixture(response) .body(JSON_RESPONSE) .statusCode(200) .header("Auth", "auth") .header("key", "value"); Response response2 = execute(); assertFixture(response2) .body(JSON_RESPONSE) .statusCode(200) .header("Auth", "auth") .header("key", "value"); }