@Test public void canRemoveOwnerFromPrivateChannel() { PersistedChannelService persistedChannelService = buildPersistedChannelService(); Observable<DatabaseResult<User>> userObservable = persistedChannelService.removeOwnerFromPrivateChannel(privateChannel, user); TestObserver<DatabaseResult<User>> testObserver = new TestObserver<>(); userObservable.subscribe(testObserver); verify(mockChannelsDatabase).removeOwnerFromPrivateChannel(user, privateChannel); verify(mockChannelsDatabase).removeChannelFromUserPrivateChannelIndex(user, privateChannel); }
@Override public Observable<DatabaseResult<User>> removeOwnerFromPrivateChannel(final Channel channel, final User removedOwner) { return channelsDatabase.removeOwnerFromPrivateChannel(removedOwner, channel) .flatMap(removeChannelReferenceFromUser(removedOwner)) .map(new Function<Channel, DatabaseResult<User>>() { @Override public DatabaseResult<User> apply(@NonNull Channel channel) throws Exception { return new DatabaseResult<>(removedOwner); } }) .onErrorReturn(DatabaseResult.<User>errorAsDatabaseResult()); }
PersistedChannelService implements ChannelService { @Override public Observable<DatabaseResult<User>> removeOwnerFromPrivateChannel(final Channel channel, final User removedOwner) { return channelsDatabase.removeOwnerFromPrivateChannel(removedOwner, channel) .flatMap(removeChannelReferenceFromUser(removedOwner)) .map(new Function<Channel, DatabaseResult<User>>() { @Override public DatabaseResult<User> apply(@NonNull Channel channel) throws Exception { return new DatabaseResult<>(removedOwner); } }) .onErrorReturn(DatabaseResult.<User>errorAsDatabaseResult()); } }
PersistedChannelService implements ChannelService { @Override public Observable<DatabaseResult<User>> removeOwnerFromPrivateChannel(final Channel channel, final User removedOwner) { return channelsDatabase.removeOwnerFromPrivateChannel(removedOwner, channel) .flatMap(removeChannelReferenceFromUser(removedOwner)) .map(new Function<Channel, DatabaseResult<User>>() { @Override public DatabaseResult<User> apply(@NonNull Channel channel) throws Exception { return new DatabaseResult<>(removedOwner); } }) .onErrorReturn(DatabaseResult.<User>errorAsDatabaseResult()); } PersistedChannelService(ChannelsDatabase channelsDatabase, UserDatabase userDatabase); }
PersistedChannelService implements ChannelService { @Override public Observable<DatabaseResult<User>> removeOwnerFromPrivateChannel(final Channel channel, final User removedOwner) { return channelsDatabase.removeOwnerFromPrivateChannel(removedOwner, channel) .flatMap(removeChannelReferenceFromUser(removedOwner)) .map(new Function<Channel, DatabaseResult<User>>() { @Override public DatabaseResult<User> apply(@NonNull Channel channel) throws Exception { return new DatabaseResult<>(removedOwner); } }) .onErrorReturn(DatabaseResult.<User>errorAsDatabaseResult()); } PersistedChannelService(ChannelsDatabase channelsDatabase, UserDatabase userDatabase); @Override Observable<Channels> getChannelsFor(User user); @Override Observable<DatabaseResult<Channel>> createPublicChannel(Channel newChannel); @Override Observable<DatabaseResult<Channel>> createPrivateChannel(final Channel newChannel, User owner); @Override Observable<DatabaseResult<User>> addOwnerToPrivateChannel(final Channel channel, final User newOwner); @Override Observable<DatabaseResult<User>> removeOwnerFromPrivateChannel(final Channel channel, final User removedOwner); @Override Observable<DatabaseResult<Users>> getOwnersOfChannel(Channel channel); }
PersistedChannelService implements ChannelService { @Override public Observable<DatabaseResult<User>> removeOwnerFromPrivateChannel(final Channel channel, final User removedOwner) { return channelsDatabase.removeOwnerFromPrivateChannel(removedOwner, channel) .flatMap(removeChannelReferenceFromUser(removedOwner)) .map(new Function<Channel, DatabaseResult<User>>() { @Override public DatabaseResult<User> apply(@NonNull Channel channel) throws Exception { return new DatabaseResult<>(removedOwner); } }) .onErrorReturn(DatabaseResult.<User>errorAsDatabaseResult()); } PersistedChannelService(ChannelsDatabase channelsDatabase, UserDatabase userDatabase); @Override Observable<Channels> getChannelsFor(User user); @Override Observable<DatabaseResult<Channel>> createPublicChannel(Channel newChannel); @Override Observable<DatabaseResult<Channel>> createPrivateChannel(final Channel newChannel, User owner); @Override Observable<DatabaseResult<User>> addOwnerToPrivateChannel(final Channel channel, final User newOwner); @Override Observable<DatabaseResult<User>> removeOwnerFromPrivateChannel(final Channel channel, final User removedOwner); @Override Observable<DatabaseResult<Users>> getOwnersOfChannel(Channel channel);  }