use of in.bugzy.data.remote.model.Error in project bugzy by cpunq.
the class NetworkBoundTaskTest method failureFromFogbugz.
@Test
public void failureFromFogbugz() {
Error k = new Error("fook", null, "11");
String content = "{\"errors\"=[" + mGson.toJson(k) + "]}";
ResponseBody body = ResponseBody.create(MediaType.parse("application/json"), content);
createCall = (aVoid) -> Calls.response(Response.error(500, body));
Observer<Resource<Foo>> observer = Mockito.mock(Observer.class);
mNetworkBoundTask.asLiveData().observeForever(observer);
// Execute the task
appExecutors.networkIO().execute(mNetworkBoundTask);
verify(observer).onChanged(Resource.loading(null));
verify(observer).onChanged(Resource.error("fook", null));
}
use of in.bugzy.data.remote.model.Error in project bugzy by cpunq.
the class ApiResponseTest method fogBugzError.
@Test
public void fogBugzError() {
Error k = new Error("foo", null, "11");
String content = "{\"errors\"=[" + mGson.toJson(k) + "]}";
ApiResponse<String> apiResponse = new ApiResponse<String>(Response.error(500, ResponseBody.create(MediaType.parse("application/json"), content)), mGson);
assertThat(apiResponse.body, notNullValue());
assertThat(apiResponse.httpCode, is(500));
assertThat(apiResponse.errorMessage, is("foo"));
}
use of in.bugzy.data.remote.model.Error in project bugzy by cpunq.
the class NetworkBoundResourceTest method failureFromNetwork.
@Test
public void failureFromNetwork() {
AtomicBoolean saved = new AtomicBoolean();
shouldFetch = Objects::isNull;
Foo fetchedDbValue = new Foo(1);
saveCallResult = foo -> {
saved.set(true);
dbData.setValue(fetchedDbValue);
return null;
};
Error k = new Error("foo", null, "11");
String content = "{\"errors\"=[" + mGson.toJson(k) + "]}";
ResponseBody body = ResponseBody.create(MediaType.parse("application/json"), content);
createCall = (aVoid) -> ApiUtil.createCall(Response.error(500, body));
Observer<Resource<Foo>> observer = Mockito.mock(Observer.class);
networkBoundResource.asLiveData().observeForever(observer);
// Drain always before verifying
drain();
verify(observer).onChanged(Resource.loading(null));
reset(observer);
dbData.setValue(null);
drain();
assertThat(saved.get(), is(false));
verify(observer).onChanged(Resource.error("foo", null));
}
Aggregations