ParseConversationDataSource implements ConversationDataSource<ExampleConversation> { @NonNull @Override public Observable<ExampleConversation> create(CreateGroupConversationQuery query) { final Map<String, Object> params = new HashMap<>(); params.put(CreateChatFunc.Fields.OTHER_USER_IDS, query.getUserIds()); params.put(CreateChatFunc.Fields.GROUP_NAME, query.getName()); return mParseHelper.<ParseObject>callFunction(CreateChatFunc.NAME, params) .map(in -> ParseUtils.conversationFromChat(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 createGroupConversation() { final List<String> userIds = new ArrayList<>(); for (int i = 0; i < 10; i++) { userIds.add(Integer.toString(i)); } final String groupName = "groupName"; final Map<String, Object> expectedParams = new HashMap<>(); expectedParams.put(CreateChatFunc.Fields.OTHER_USER_IDS, userIds); expectedParams.put(CreateChatFunc.Fields.GROUP_NAME, groupName); ParseObject subscription = ModelTestHelper.createSubscription("id"); when(mMockParseHelper.<ParseObject>callFunction(eq(CreateChatFunc.NAME), argThat(MapMatchers.matchesEntriesIn(expectedParams)))) .thenReturn(Observable.just(subscription)); final TestSubscriber<ExampleConversation> testSubscriber = executeTarget( mTarget.create(new CreateGroupConversationQuery(userIds, groupName))); testSubscriber.assertCompleted(); assertThat(testSubscriber.getOnNextEvents().size(), is(1)); }
@Test public void createConversation() { final Map<String, Object> expectedParams = new HashMap<>(); expectedParams.put(CreateChatFunc.Fields.OTHER_USER_IDS, Collections.singletonList("0")); ParseObject subscription = ModelTestHelper.createSubscription("id"); when(mMockParseHelper.<ParseObject>callFunction(eq(CreateChatFunc.NAME), argThat(MapMatchers.matchesEntriesIn(expectedParams)))) .thenReturn(Observable.just(subscription)); final TestSubscriber<ExampleConversation> testSubscriber = executeTarget( mTarget.create(new CreateConversationQuery("0"))); testSubscriber.assertCompleted(); assertThat(testSubscriber.getOnNextEvents().size(), is(1)); }