Search in sources :

Example 1 with Error

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));
}
Also used : Resource(in.bugzy.data.model.Resource) Error(in.bugzy.data.remote.model.Error) ResponseBody(okhttp3.ResponseBody) Test(org.junit.Test)

Example 2 with Error

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"));
}
Also used : Error(in.bugzy.data.remote.model.Error) Test(org.junit.Test)

Example 3 with Error

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));
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Objects(java.util.Objects) Resource(in.bugzy.data.model.Resource) Error(in.bugzy.data.remote.model.Error) ResponseBody(okhttp3.ResponseBody) Test(org.junit.Test)

Aggregations

Error (in.bugzy.data.remote.model.Error)3 Test (org.junit.Test)3 Resource (in.bugzy.data.model.Resource)2 ResponseBody (okhttp3.ResponseBody)2 Objects (java.util.Objects)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1