@Test public void unwrapNestedJsonAdapter() throws Exception { server.enqueue(new MockResponse().setBody("{\n" + " \"one\": {\n" + " \"two\": {\n" + " \"item\": {\n" + " \"foo\": \"this\"\n" + " },\n" + " \"item2\": {\n" + " \"bar\": 1234\n" + " },\n" + " \"foobar\": 567\n" + " }\n" + " }\n" + "}")); Response<Nested> response = service.unwrapNested().execute(); assertThat(response.body().foobar).isEqualTo(567); assertThat(response.body().foo).isEqualTo("this"); assertThat(response.body().bar).isEqualTo(1234); }
@Test public void wrapPostBody() throws Exception { server.enqueue(new MockResponse()); Call<ResponseBody> call = service.wrappedPost("one"); call.execute(); RecordedRequest recorded = server.takeRequest(); assertThat(recorded.getBody() .readUtf8()) .isEqualTo("{\"1\":{\"2\":\"one\"}}"); }
@Test public void unwrapJsonAdapter() throws Exception { assertResponse(service.unwrap(), "{\n" + " \"one\": {\n" + " \"two\": \"works!\"\n" + " }\n" + "}", "works!"); }
@Test public void firstElementJsonAdapter() throws Exception { assertResponse(service.firstElement(), "[\n" + " \"expected\",\n" + " \"ignored\"\n" + "]", "expected"); }
@Test public void unwrapFirstElement() throws Exception { assertResponse(service.unwrapFirstElement(), "{\n" + " \"one\": {\n" + " \"two\": [\n" + " \"first\"\n" + " ]\n" + " }\n" + "}", "first"); }
@Test public void elementAtJsonAdapter() throws Exception { assertResponse(service.elementAt(), "[\n" + " \"one\",\n" + " \"two\",\n" + " \"three\"\n" + "]", "three"); }