ParseConversationDataSource implements ConversationDataSource<ExampleConversation> { private Observable<ExampleConversation> getConversation(@NonNull String chatId) { final ParseQuery<ParseObject> parseQuery = new ParseQuery<>(ChatSubscriptionTable.NAME); parseQuery.include(ChatSubscriptionTable.Fields.CHAT); parseQuery.include(ChatSubscriptionTable.Fields.CHAT + "." + ChatTable.Fields.LAST_MESSAGE); parseQuery.whereEqualTo(ChatSubscriptionTable.Fields.CHAT, ParseObject.createWithoutData(ChatTable.NAME, chatId)); parseQuery.whereEqualTo(ChatSubscriptionTable.Fields.USER, ParseObject.createWithoutData(UsersTable.NAME, mParseHelper.getCurrentUser().getObjectId())); return mParseHelper.find(parseQuery) .flatMap(Observable::from) .map(in -> ParseUtils.conversationFromSubscription(in, mParseHelper)) .subscribeOn(Schedulers.io()); } ParseConversationDataSource(@NonNull ParseHelper parseHelper); void reloadConversation(@NonNull String chatId); @NonNull @Override Observable<LoadResult<ExampleConversation>> load(LoadConversationsQuery<ExampleConversation> query); @NonNull @Override Observable<ExampleConversation> get(GetConversationQuery query); @NonNull @Override Observable<Boolean> subscribe(SubscribeToUpdatesQuery query); @NonNull @Override Observable<ExampleConversation> create(CreateGroupConversationQuery query); @NonNull @Override Observable<ExampleConversation> create(CreateConversationQuery query); @NonNull @Override Observable<Void> markRead(MarkConversationReadQuery query); @NonNull @Override Observable<List<ExampleConversation>> delete(DeleteConversationsQuery<ExampleConversation> query);  }
@Test public void getConversation() { final String userId = "userId"; mockCurrentUser(userId); final List<ParseObject> subscriptions = ModelTestHelper.createSubscriptions(10); final String chatId = "chatId"; when(mMockParseHelper.find(Mockito.<ParseQuery<ParseObject>>any())).thenReturn(Observable.just(subscriptions)); final TestSubscriber<ExampleConversation> testSubscriber = executeTarget(mTarget.get(new GetConversationQuery(chatId))); testSubscriber.assertCompleted(); verify(mMockParseHelper).find(mParseQueryArgumentCaptor.capture()); final ParseQuery<ParseObject> parseQuery = mParseQueryArgumentCaptor.getValue(); assertThat(testSubscriber.getOnNextEvents().size(), is(10)); assertThat(parseQuery.getClassName(), is(ChatSubscriptionTable.NAME)); }