Search in sources :

Example 6 with UnmodifiableMapBuilder

use of com.apollographql.apollo.api.internal.UnmodifiableMapBuilder in project apollo-android by apollographql.

the class ResponseReaderTest method read_object_list_with_nulls.

@Test
public void read_object_list_with_nulls() throws Exception {
    final ResponseField listField = ResponseField.forList("list", "list", null, false, NO_CONDITIONS);
    final ResponseField indexField = ResponseField.forList("index", "index", null, false, NO_CONDITIONS);
    final List responseObjects = asList(new Object(), new Object(), new Object());
    final Map<String, Object> recordSet = new HashMap<>();
    recordSet.put("list", asList(null, new UnmodifiableMapBuilder<String, Object>(1).put("index", "0").build(), new UnmodifiableMapBuilder<String, Object>(1).put("index", "1").build(), null, new UnmodifiableMapBuilder<String, Object>(1).put("index", "2").build(), null));
    RealResponseReader<Map<String, Object>> responseReader = responseReader(recordSet);
    assertThat(responseReader.readList(listField, new ResponseReader.ListReader() {

        @Override
        public Object read(ResponseReader.ListItemReader reader) {
            return reader.readObject(new ResponseReader.ObjectReader<Object>() {

                @Override
                public Object read(ResponseReader reader) {
                    return responseObjects.get(Integer.parseInt(reader.readString(indexField)));
                }
            });
        }
    })).isEqualTo(responseObjects);
}
Also used : HashMap(java.util.HashMap) UnmodifiableMapBuilder(com.apollographql.apollo.api.internal.UnmodifiableMapBuilder) ResponseField(com.apollographql.apollo.api.ResponseField) Arrays.asList(java.util.Arrays.asList) List(java.util.List) ResponseReader(com.apollographql.apollo.api.ResponseReader) RealResponseReader(com.apollographql.apollo.internal.response.RealResponseReader) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Aggregations

ResponseField (com.apollographql.apollo.api.ResponseField)6 UnmodifiableMapBuilder (com.apollographql.apollo.api.internal.UnmodifiableMapBuilder)6 Test (org.junit.Test)6 Operation (com.apollographql.apollo.api.Operation)5 HashMap (java.util.HashMap)4 ResponseReader (com.apollographql.apollo.api.ResponseReader)1 RealResponseReader (com.apollographql.apollo.internal.response.RealResponseReader)1 Arrays.asList (java.util.Arrays.asList)1 List (java.util.List)1 Map (java.util.Map)1