use of in.bugzy.data.model.Resource in project bugzy by cpunq.
the class NetworkBoundResourceTest method dbSuccessWithFetch.
@Test
public void dbSuccessWithFetch() {
Foo dbFoo = new Foo(1);
AtomicBoolean saved = new AtomicBoolean();
shouldFetch = (foo) -> foo == dbFoo;
saveCallResult = foo -> {
saved.set(true);
return null;
};
Observer<Resource<Foo>> observer = Mockito.mock(Observer.class);
networkBoundResource.asLiveData().observeForever(observer);
MutableLiveData<ApiResponse<Foo>> apiResponseLiveData = new MutableLiveData();
createCall = (aVoid) -> apiResponseLiveData;
drain();
verify(observer).onChanged(Resource.loading(null));
reset(observer);
dbData.setValue(dbFoo);
drain();
verify(observer).onChanged(Resource.loading(dbFoo));
ResponseBody body = ResponseBody.create(MediaType.parse("text/html"), "error");
apiResponseLiveData.setValue(new ApiResponse<>(Response.error(400, body), mGson));
drain();
verify(observer).onChanged(Resource.error("Oops! We can't reach Fogbugz", dbFoo));
Foo dbFoo2 = new Foo(2);
dbData.setValue(dbFoo2);
drain();
verify(observer).onChanged(Resource.error("Oops! We can't reach Fogbugz", dbFoo2));
verifyNoMoreInteractions(observer);
}
Aggregations