ParseConversationDataSource implements ConversationDataSource<ExampleConversation> { @NonNull @Override public Observable<List<ExampleConversation>> delete(DeleteConversationsQuery<ExampleConversation> query) { final Map<String, Object> params = new HashMap<>(); List<String> chatIds = new ArrayList<>(); for (ExampleConversation c : query.getConversations()) { chatIds.add(c.getId()); } params.put(DeleteConversationsFunc.Fields.CHAT_IDS, chatIds); return mParseHelper.<List<ParseObject>>callFunction(DeleteConversationsFunc.NAME, params) .flatMap(Observable::from) .map(in -> ParseUtils.conversationFromChat(in, mParseHelper)) .doOnNext(exampleConversation -> mConversationUpdatePublisher.onNext(true)) .toList() .ignoreElements() .concatWith(load(null).ignoreElements().map(i -> Collections.<ExampleConversation>emptyList())) .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 deleteConversations() { final List<String> chatIds = new ArrayList<>(); for (int i = 0; i < 10; i++) { chatIds.add(Integer.toString(i)); } final Map<String, Object> expectedParams = new HashMap<>(); expectedParams.put(DeleteConversationsFunc.Fields.CHAT_IDS, chatIds); final List<ParseObject> subscription = ModelTestHelper.createSubscriptions(10); when(mMockParseHelper.<List<ParseObject>>callFunction(eq(DeleteConversationsFunc.NAME), argThat(MapMatchers.matchesEntriesIn(expectedParams)))) .thenReturn(Observable.just(subscription)); when(mMockParseHelper.<List<ParseObject>>callFunction(eq(GetMySubscriptionsFunc.NAME), Matchers.<Map<String, Object>>any())).thenReturn(Observable.empty()); final List<ExampleConversation> conversations = ModelTestHelper.createConversations(10); final TestSubscriber<?> testSubscriber = executeTarget(mTarget.delete(new DeleteConversationsQuery<>(conversations))); testSubscriber.assertCompleted(); verify(mMockParseHelper).<List<ParseObject>>callFunction(eq(DeleteConversationsFunc.NAME), argThat(MapMatchers.matchesEntriesIn(expectedParams))); }