use of com.apollographql.apollo.api.ResponseField in project apollo-android by apollographql.
the class ResponseReaderTest method readCustomWithDecodedNullValue.
@Test
public void readCustomWithDecodedNullValue() throws Exception {
Map<String, Object> recordSet = new HashMap<>();
recordSet.put("responseName", "http:://");
RealResponseReader<Map<String, Object>> responseReader = responseReader(recordSet);
ResponseField field = ResponseField.forCustomType("responseName", "fieldName", null, false, URL_CUSTOM_TYPE, NO_CONDITIONS);
try {
responseReader.readCustomType((ResponseField.CustomTypeField) field);
fail("expected NullPointerException");
} catch (NullPointerException e) {
// expected
}
field = ResponseField.forCustomType("responseName", "fieldName", null, true, URL_CUSTOM_TYPE, NO_CONDITIONS);
Truth.assertThat(responseReader.readCustomType((ResponseField.CustomTypeField) field)).isNull();
}
use of com.apollographql.apollo.api.ResponseField in project apollo-android by apollographql.
the class ResponseReaderTest method readBooleanList.
@Test
public void readBooleanList() throws Exception {
ResponseField successField = ResponseField.forList("successFieldResponseName", "successFieldName", null, false, NO_CONDITIONS);
ResponseField classCastExceptionField = ResponseField.forList("classCastExceptionFieldResponseName", "classCastExceptionFieldName", null, false, NO_CONDITIONS);
final Map<String, Object> recordSet = new HashMap<>();
recordSet.put("successFieldResponseName", asList(true, false, true));
recordSet.put("successFieldName", asList(false, false));
recordSet.put("classCastExceptionFieldResponseName", "anything");
RealResponseReader<Map<String, Object>> responseReader = responseReader(recordSet);
assertThat(responseReader.readList(successField, new ResponseReader.ListReader() {
@Override
public Object read(ResponseReader.ListItemReader reader) {
return reader.readBoolean();
}
})).isEqualTo(asList(true, false, true));
try {
responseReader.readList(classCastExceptionField, new ResponseReader.ListReader() {
@Override
public Object read(ResponseReader.ListItemReader reader) {
return null;
}
});
fail("expected ClassCastException");
} catch (ClassCastException expected) {
// expected
}
}
use of com.apollographql.apollo.api.ResponseField in project apollo-android by apollographql.
the class ResponseReaderTest method readBoolean.
@Test
public void readBoolean() throws Exception {
ResponseField successField = ResponseField.forBoolean("successFieldResponseName", "successFieldName", null, false, NO_CONDITIONS);
ResponseField classCastExceptionField = ResponseField.forBoolean("classCastExceptionFieldResponseName", "classCastExceptionFieldName", null, false, NO_CONDITIONS);
Map<String, Object> recordSet = new HashMap<>();
recordSet.put("successFieldResponseName", true);
recordSet.put("successFieldName", false);
recordSet.put("classCastExceptionFieldResponseName", "anything");
RealResponseReader<Map<String, Object>> responseReader = responseReader(recordSet);
assertThat(responseReader.readBoolean(successField)).isTrue();
try {
responseReader.readBoolean(classCastExceptionField);
fail("expected ClassCastException");
} catch (ClassCastException expected) {
// expected
}
}
use of com.apollographql.apollo.api.ResponseField in project apollo-android by apollographql.
the class ResponseReaderTest method readLong.
@Test
public void readLong() throws Exception {
ResponseField successField = ResponseField.forLong("successFieldResponseName", "successFieldName", null, false, NO_CONDITIONS);
ResponseField classCastExceptionField = ResponseField.forLong("classCastExceptionFieldResponseName", "classCastExceptionFieldName", null, false, NO_CONDITIONS);
Map<String, Object> recordSet = new HashMap<>();
recordSet.put("successFieldResponseName", BigDecimal.valueOf(1));
recordSet.put("successFieldName", BigDecimal.valueOf(2));
recordSet.put("classCastExceptionFieldResponseName", "anything");
RealResponseReader<Map<String, Object>> responseReader = responseReader(recordSet);
assertThat(responseReader.readLong(successField)).isEqualTo(1);
try {
responseReader.readLong(classCastExceptionField);
fail("expected ClassCastException");
} catch (ClassCastException expected) {
// expected
}
}
use of com.apollographql.apollo.api.ResponseField in project apollo-android by apollographql.
the class ResponseReaderTest method readStringList.
@Test
public void readStringList() throws Exception {
ResponseField successField = ResponseField.forList("successFieldResponseName", "successFieldName", null, false, NO_CONDITIONS);
ResponseField classCastExceptionField = ResponseField.forList("classCastExceptionFieldResponseName", "classCastExceptionFieldName", null, false, NO_CONDITIONS);
final Map<String, Object> recordSet = new HashMap<>();
recordSet.put("successFieldResponseName", asList("value1", "value2", "value3"));
recordSet.put("successFieldName", asList("value4", "value5"));
recordSet.put("classCastExceptionFieldResponseName", "anything");
RealResponseReader<Map<String, Object>> responseReader = responseReader(recordSet);
assertThat(responseReader.readList(successField, new ResponseReader.ListReader() {
@Override
public Object read(ResponseReader.ListItemReader reader) {
return reader.readString();
}
})).isEqualTo(asList("value1", "value2", "value3"));
try {
responseReader.readList(classCastExceptionField, new ResponseReader.ListReader() {
@Override
public Object read(ResponseReader.ListItemReader reader) {
return null;
}
});
fail("expected ClassCastException");
} catch (ClassCastException expected) {
// expected
}
}
Aggregations