use of com.pushtorefresh.storio.contentresolver.StorIOContentResolver in project storio by pushtorefresh.
the class DefaultGetResolverTest method query.
@Test
public void query() {
final StorIOContentResolver storIOContentResolver = mock(StorIOContentResolver.class);
final StorIOContentResolver.LowLevel lowLevel = mock(StorIOContentResolver.LowLevel.class);
final Query query = Query.builder().uri(mock(Uri.class)).build();
final Cursor expectedCursor = mock(Cursor.class);
when(storIOContentResolver.lowLevel()).thenReturn(lowLevel);
when(lowLevel.query(query)).thenReturn(expectedCursor);
final GetResolver<TestItem> defaultGetResolver = new DefaultGetResolver<TestItem>() {
@NonNull
@Override
public TestItem mapFromCursor(@NonNull Cursor cursor) {
assertThat(cursor).isSameAs(expectedCursor);
return new TestItem();
}
};
final Cursor actualCursor = defaultGetResolver.performGet(storIOContentResolver, query);
// only one request should occur
verify(lowLevel, times(1)).query(any(Query.class));
// and this request should be equals to original
verify(lowLevel, times(1)).query(query);
assertThat(actualCursor).isSameAs(expectedCursor);
}
use of com.pushtorefresh.storio.contentresolver.StorIOContentResolver in project storio by pushtorefresh.
the class PreparedGetNumberOfResultsTest method shouldWrapExceptionIntoStorIOExceptionForObservable.
@Test
public void shouldWrapExceptionIntoStorIOExceptionForObservable() {
final StorIOContentResolver storIOContentResolver = mock(StorIOContentResolver.class);
Uri testUri = mock(Uri.class);
when(storIOContentResolver.observeChangesOfUri(eq(testUri))).thenReturn(Observable.<Changes>empty());
//noinspection unchecked
final GetResolver<Integer> getResolver = mock(GetResolver.class);
when(getResolver.performGet(eq(storIOContentResolver), any(Query.class))).thenThrow(new IllegalStateException("test exception"));
final TestSubscriber<Integer> testSubscriber = new TestSubscriber<Integer>();
new PreparedGetNumberOfResults.Builder(storIOContentResolver).withQuery(Query.builder().uri(testUri).build()).withGetResolver(getResolver).prepare().asRxObservable().subscribe(testSubscriber);
testSubscriber.awaitTerminalEvent(60, SECONDS);
testSubscriber.assertError(StorIOException.class);
assertThat(testSubscriber.getOnErrorEvents()).hasSize(1);
StorIOException storIOException = (StorIOException) testSubscriber.getOnErrorEvents().get(0);
IllegalStateException cause = (IllegalStateException) storIOException.getCause();
assertThat(cause).hasMessage("test exception");
testSubscriber.unsubscribe();
}
use of com.pushtorefresh.storio.contentresolver.StorIOContentResolver in project storio by pushtorefresh.
the class PreparedGetNumberOfResultsTest method shouldWrapExceptionIntoStorIOExceptionForSingle.
@Test
public void shouldWrapExceptionIntoStorIOExceptionForSingle() {
final StorIOContentResolver storIOContentResolver = mock(StorIOContentResolver.class);
Uri testUri = mock(Uri.class);
//noinspection unchecked
final GetResolver<Integer> getResolver = mock(GetResolver.class);
when(getResolver.performGet(eq(storIOContentResolver), any(Query.class))).thenThrow(new IllegalStateException("test exception"));
final TestSubscriber<Integer> testSubscriber = new TestSubscriber<Integer>();
new PreparedGetNumberOfResults.Builder(storIOContentResolver).withQuery(Query.builder().uri(testUri).build()).withGetResolver(getResolver).prepare().asRxSingle().subscribe(testSubscriber);
testSubscriber.awaitTerminalEvent(60, SECONDS);
testSubscriber.assertError(StorIOException.class);
assertThat(testSubscriber.getOnErrorEvents()).hasSize(1);
StorIOException storIOException = (StorIOException) testSubscriber.getOnErrorEvents().get(0);
IllegalStateException cause = (IllegalStateException) storIOException.getCause();
assertThat(cause).hasMessage("test exception");
testSubscriber.unsubscribe();
}
Aggregations