Skip to content

Commit

Permalink
revert: auto select at least one channel as active
Browse files Browse the repository at this point in the history
  • Loading branch information
Silthus committed Feb 17, 2022
1 parent ea002fe commit ac87287
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import net.silthus.schat.identity.Identity;
import net.silthus.schat.message.Message;
import net.silthus.schat.pointer.Pointers;
import net.silthus.schat.util.Iterators;
import net.silthus.schat.view.ViewConnector;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -96,8 +95,7 @@ public void activeChannel(@Nullable Channel activeChannel) {

@Override
public @NotNull Optional<Channel> activeChannel() {
return Optional.ofNullable(activeChannel)
.or(Iterators.tryGetFirstIn(channels));
return Optional.ofNullable(activeChannel);
}

@Override
Expand Down
22 changes: 0 additions & 22 deletions core/src/test/java/net/silthus/schat/chatter/ChatterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,28 +80,6 @@ void when_isJoined_is_called_given_null_returns_false() {
assertThat(chatter.isJoined(null)).isFalse();
}

@Nested class given_chatter_has_channels_but_no_active_channel {
private Channel channel;

@BeforeEach
void setUp() {
channel = randomChannel();
chatter.join(channel);
}

@Test
void then_active_channel_returns_first_channel() {
assertThat(chatter.activeChannel())
.isPresent()
.get().isEqualTo(channel);
}

@Test
void then_isActive_returns_true_for_selected_channel() {
assertThat(chatter.isActiveChannel(channel)).isTrue();
}
}

@Nested class given_valid_channel {
private Channel channel;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import org.junit.jupiter.api.Test;

import static net.silthus.schat.channel.ChannelHelper.channelWith;
import static net.silthus.schat.channel.ChannelHelper.randomChannel;
import static net.silthus.schat.channel.ChannelRepository.createInMemoryChannelRepository;
import static net.silthus.schat.channel.ChannelSettings.GLOBAL;
import static net.silthus.schat.channel.ChannelSettings.PRIVATE;
Expand Down Expand Up @@ -74,14 +73,6 @@ private Message sendPrivateMessageFrom(Chatter source) {
return send(message().source(source).to(target));
}

private String idOf(Chatter chatter) {
return chatter.uniqueId().toString();
}

private String targetId() {
return target.uniqueId().toString();
}

private Channel privateChannel() {
return source.channels().stream().filter(channel -> channel.is(PRIVATE)).findFirst().orElseThrow();
}
Expand Down Expand Up @@ -125,10 +116,8 @@ void private_channel_is_set_active() {

@Test
void given_setActive_is_false_then_private_channel_is_not_set_as_active() {
final Channel channel = randomChannel();
source.activeChannel(channel);
sendPrivateMessageBuilder(source, target, randomText()).setActive(false).execute();
assertThat(source.isActiveChannel(channel)).isTrue();
assertThat(source.activeChannel()).isEmpty();
source.assertJoinedChannel(privateChannel().key());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import net.silthus.schat.channel.Channel;
import net.silthus.schat.chatter.ChatterMock;
import net.silthus.schat.command.Result;
import net.silthus.schat.eventbus.EventBus;
import net.silthus.schat.policies.JoinChannelPolicy;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested;
Expand All @@ -47,6 +48,7 @@ class SetActiveChannelCommandTests {
void setUp() {
chatter = ChatterMock.randomChatter();
channel = channelWith(builder -> builder.policy(JoinChannelPolicy.class, ALLOW));
JoinChannelCommand.prototype(builder -> builder.eventBus(EventBus.empty()));
}

private Result setActiveChannel() {
Expand Down

0 comments on commit ac87287

Please sign in to comment.