Search in sources :

Example 1 with TweetWithUser

use of com.pushtorefresh.storio.sample.db.entities.TweetWithUser 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")));
}
Also used : TweetWithUser(com.pushtorefresh.storio.sample.db.entities.TweetWithUser) SampleApp(com.pushtorefresh.storio.sample.SampleApp) Test(org.junit.Test)

Example 2 with TweetWithUser

use of com.pushtorefresh.storio.sample.db.entities.TweetWithUser in project storio by pushtorefresh.

the class TweetWithUserGetResolver method mapFromCursor.

// We expect that cursor will contain both Tweet and User: SQL JOIN
@NonNull
@Override
public TweetWithUser mapFromCursor(@NonNull Cursor cursor) {
    final Tweet tweet = Tweet.newTweet(cursor.getLong(cursor.getColumnIndexOrThrow(Relations.QUERY_COLUMN_TWEET_ID)), cursor.getString(cursor.getColumnIndexOrThrow(Relations.QUERY_COLUMN_TWEET_AUTHOR)), cursor.getString(cursor.getColumnIndexOrThrow(Relations.QUERY_COLUMN_TWEET_CONTENT)));
    final User user = User.newUser(cursor.getLong(cursor.getColumnIndexOrThrow(Relations.QUERY_COLUMN_USER_ID)), cursor.getString(cursor.getColumnIndexOrThrow(Relations.QUERY_COLUMN_USER_NICK)));
    return new TweetWithUser(tweet, user);
}
Also used : User(com.pushtorefresh.storio.sample.db.entities.User) TweetWithUser(com.pushtorefresh.storio.sample.db.entities.TweetWithUser) TweetWithUser(com.pushtorefresh.storio.sample.db.entities.TweetWithUser) Tweet(com.pushtorefresh.storio.sample.db.entities.Tweet) NonNull(android.support.annotation.NonNull)

Aggregations

TweetWithUser (com.pushtorefresh.storio.sample.db.entities.TweetWithUser)2 NonNull (android.support.annotation.NonNull)1 SampleApp (com.pushtorefresh.storio.sample.SampleApp)1 Tweet (com.pushtorefresh.storio.sample.db.entities.Tweet)1 User (com.pushtorefresh.storio.sample.db.entities.User)1 Test (org.junit.Test)1