use of com.pushtorefresh.storio3.sqlite.StorIOSQLite in project storio by pushtorefresh.
the class RelationsTest method name.
@Test
public void name() {
SampleApp sampleApp = (SampleApp) RuntimeEnvironment.application;
sampleApp.appComponent().storIOSQLite().put().objects(asList(Tweet.newTweet(1L, "artem_zin", "test tweet 1"), Tweet.newTweet(2L, "artem_zin", "test tweet 2"), Tweet.newTweet(3L, "nikitin-da", "test tweet 3"), User.newUser(1L, "artem_zin"), User.newUser(2L, "nikitin-da"))).prepare().executeAsBlocking();
Relations relations = new Relations(sampleApp.appComponent().storIOSQLite());
List<TweetWithUser> tweetsWithUsers = relations.getTweetWithUser();
// Same as count of tweets, not users.
assertThat(tweetsWithUsers).hasSize(3);
assertThat(tweetsWithUsers.get(0)).isEqualTo(new TweetWithUser(Tweet.newTweet(1L, "artem_zin", "test tweet 1"), User.newUser(1L, "artem_zin")));
assertThat(tweetsWithUsers.get(1)).isEqualTo(new TweetWithUser(Tweet.newTweet(2L, "artem_zin", "test tweet 2"), User.newUser(1L, "artem_zin")));
assertThat(tweetsWithUsers.get(2)).isEqualTo(new TweetWithUser(Tweet.newTweet(3L, "nikitin-da", "test tweet 3"), User.newUser(2L, "nikitin-da")));
}
use of com.pushtorefresh.storio3.sqlite.StorIOSQLite in project storio by pushtorefresh.
the class DefaultDeleteResolverTest method performDelete.
@Test
public void performDelete() {
final StorIOSQLite storIOSQLite = mock(StorIOSQLite.class);
final StorIOSQLite.LowLevel lowLevel = mock(StorIOSQLite.LowLevel.class);
final String testTable = "test_table";
final Set<String> testTags = singleton("test_tag");
final DeleteQuery deleteQuery = DeleteQuery.builder().table(testTable).affectsTags(testTags).build();
when(storIOSQLite.lowLevel()).thenReturn(lowLevel);
when(lowLevel.delete(deleteQuery)).thenReturn(1);
final TestItem testItem = new TestItem();
final DefaultDeleteResolver<TestItem> defaultDeleteResolver = new DefaultDeleteResolver<TestItem>() {
@NonNull
@Override
public DeleteQuery mapToDeleteQuery(@NonNull TestItem testItem) {
return deleteQuery;
}
};
final DeleteResult deleteResult = defaultDeleteResolver.performDelete(storIOSQLite, testItem);
verify(lowLevel).delete(any(DeleteQuery.class));
verify(lowLevel).delete(deleteQuery);
assertThat(deleteResult.numberOfRowsDeleted()).isEqualTo(1);
assertThat(deleteResult.affectedTables()).isEqualTo(singleton(testTable));
assertThat(deleteResult.affectedTags()).isEqualTo(testTags);
}
use of com.pushtorefresh.storio3.sqlite.StorIOSQLite in project storio by pushtorefresh.
the class PreparedDeleteByQueryTest method shouldWrapExceptionIntoStorIOExceptionCompletable.
@Test
public void shouldWrapExceptionIntoStorIOExceptionCompletable() {
final StorIOSQLite storIOSQLite = mock(StorIOSQLite.class);
final StorIOSQLite.LowLevel lowLevel = mock(StorIOSQLite.LowLevel.class);
when(storIOSQLite.lowLevel()).thenReturn(lowLevel);
// noinspection unchecked
final DeleteResolver<DeleteQuery> deleteResolver = mock(DeleteResolver.class);
when(deleteResolver.performDelete(same(storIOSQLite), any(DeleteQuery.class))).thenThrow(new IllegalStateException("test exception"));
final TestObserver<DeleteResult> testObserver = new TestObserver<DeleteResult>();
new PreparedDeleteByQuery.Builder(storIOSQLite, DeleteQuery.builder().table("test_table").build()).withDeleteResolver(deleteResolver).prepare().asRxCompletable().subscribe(testObserver);
testObserver.awaitTerminalEvent();
testObserver.assertNoValues();
testObserver.assertError(StorIOException.class);
// noinspection ThrowableResultOfMethodCallIgnored
StorIOException expected = (StorIOException) testObserver.errors().get(0);
IllegalStateException cause = (IllegalStateException) expected.getCause();
assertThat(cause).hasMessage("test exception");
verify(storIOSQLite).defaultRxScheduler();
verify(deleteResolver).performDelete(same(storIOSQLite), any(DeleteQuery.class));
verify(storIOSQLite).interceptors();
verifyNoMoreInteractions(storIOSQLite, lowLevel, deleteResolver);
}
use of com.pushtorefresh.storio3.sqlite.StorIOSQLite in project storio by pushtorefresh.
the class PreparedDeleteByQueryTest method shouldNotNotifyIfWasNotDeleted.
@Test
public void shouldNotNotifyIfWasNotDeleted() {
final StorIOSQLite storIOSQLite = mock(StorIOSQLite.class);
final StorIOSQLite.LowLevel lowLevel = mock(StorIOSQLite.LowLevel.class);
when(storIOSQLite.lowLevel()).thenReturn(lowLevel);
final DeleteQuery deleteQuery = DeleteQuery.builder().table("test_table").where("column1 = ?").whereArgs(1).build();
// noinspection unchecked
final DeleteResolver<DeleteQuery> deleteResolver = mock(DeleteResolver.class);
// No items were deleted
final DeleteResult expectedDeleteResult = DeleteResult.newInstance(0, deleteQuery.table());
when(deleteResolver.performDelete(same(storIOSQLite), same(deleteQuery))).thenReturn(expectedDeleteResult);
final DeleteResult actualDeleteResult = new PreparedDeleteByQuery.Builder(storIOSQLite, deleteQuery).withDeleteResolver(deleteResolver).prepare().executeAsBlocking();
assertThat(actualDeleteResult).isEqualTo(expectedDeleteResult);
verify(deleteResolver).performDelete(same(storIOSQLite), same(deleteQuery));
verify(lowLevel, never()).notifyAboutChanges(any(Changes.class));
verify(storIOSQLite).interceptors();
verifyNoMoreInteractions(storIOSQLite, lowLevel, deleteResolver);
}
use of com.pushtorefresh.storio3.sqlite.StorIOSQLite in project storio by pushtorefresh.
the class PreparedDeleteByQueryTest method shouldWrapExceptionIntoStorIOExceptionBlocking.
@Test
public void shouldWrapExceptionIntoStorIOExceptionBlocking() {
final StorIOSQLite storIOSQLite = mock(StorIOSQLite.class);
final StorIOSQLite.LowLevel lowLevel = mock(StorIOSQLite.LowLevel.class);
when(storIOSQLite.lowLevel()).thenReturn(lowLevel);
// noinspection unchecked
final DeleteResolver<DeleteQuery> deleteResolver = mock(DeleteResolver.class);
when(deleteResolver.performDelete(same(storIOSQLite), any(DeleteQuery.class))).thenThrow(new IllegalStateException("test exception"));
try {
new PreparedDeleteByQuery.Builder(storIOSQLite, DeleteQuery.builder().table("test_table").build()).withDeleteResolver(deleteResolver).prepare().executeAsBlocking();
failBecauseExceptionWasNotThrown(StorIOException.class);
} catch (StorIOException expected) {
IllegalStateException cause = (IllegalStateException) expected.getCause();
assertThat(cause).hasMessage("test exception");
verify(deleteResolver).performDelete(same(storIOSQLite), any(DeleteQuery.class));
verify(storIOSQLite).interceptors();
verifyNoMoreInteractions(storIOSQLite, lowLevel, deleteResolver);
}
}
Aggregations