Skip to content

Commit

Permalink
fix: set channel active when joining
Browse files Browse the repository at this point in the history
  • Loading branch information
Silthus committed Feb 17, 2022
1 parent 19b295f commit b084af3
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 123 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* sChat, a Supercharged Minecraft Chat Plugin
* Copyright (C) Silthus <https://www.github.com/silthus>
* Copyright (C) sChat team and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package net.silthus.schat.channel;

import java.util.UUID;
import lombok.Getter;
import lombok.NonNull;
import net.silthus.schat.repository.Repository;
import net.silthus.schat.usecases.JoinChannel;

@Getter
public class ChannelInteractorSpy implements ChannelInteractor {

private boolean joinChannelCalled = false;
private boolean setActiveChannelCalled = false;

@Override
public void joinChannel(@NonNull UUID chatterId, @NonNull String channelId) throws Repository.NotFound, JoinChannel.Error {
this.joinChannelCalled = true;
}

@Override
public void setActiveChannel(@NonNull UUID chatterId, @NonNull String channelId) throws Repository.NotFound, JoinChannel.Error {
this.setActiveChannelCalled = true;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
/*
* This file is part of sChat, licensed under the MIT License.
* sChat, a Supercharged Minecraft Chat Plugin
* Copyright (C) Silthus <https://www.github.com/silthus>
* Copyright (C) sChat team and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package net.silthus.schat.platform.commands;
Expand Down Expand Up @@ -59,15 +54,6 @@ public void register(CommandManager<Sender> commandManager, AnnotationParser<Sen
@ProxiedBy("ch")
@CommandMethod("channel join <channel>")
void joinChannel(Sender sender, Chatter chatter, @Argument("channel") Channel channel) {
try {
interactor.joinChannel(chatter.getKey(), channel.getKey());
} catch (Repository.NotFound | JoinChannel.Error e) {
JOIN_CHANNEL_ERROR.send(sender, channel);
}
}

@CommandMethod("channel set-active <channel>")
void setActiveChannel(Sender sender, Chatter chatter, @Argument("channel") Channel channel) {
try {
interactor.setActiveChannel(chatter.getKey(), channel.getKey());
} catch (Repository.NotFound | JoinChannel.Error e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,27 @@
/*
* This file is part of sChat, licensed under the MIT License.
* sChat, a Supercharged Minecraft Chat Plugin
* Copyright (C) Silthus <https://www.github.com/silthus>
* Copyright (C) sChat team and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package net.silthus.schat.platform.commands;

import net.silthus.schat.channel.Channel;
import net.silthus.schat.channel.ChannelInteractorSpy;
import net.silthus.schat.channel.FailingChannelInteractorStub;
import net.silthus.schat.channel.SpyingChannelInteractorStub;
import net.silthus.schat.platform.commands.parser.ChannelArgument;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
Expand All @@ -40,11 +35,11 @@
class ChannelCommandsTests extends CommandTest {
private ChannelCommands channelCommands;
private Channel channel;
private SpyingChannelInteractorStub interactor;
private ChannelInteractorSpy interactor;

@BeforeEach
void setUp() {
interactor = new SpyingChannelInteractorStub();
interactor = new ChannelInteractorSpy();
channelCommands = new ChannelCommands(interactor);
commands.register(channelCommands);
channel = addRandomChannel();
Expand Down Expand Up @@ -75,7 +70,7 @@ void given_invalid_chanel_join_command_fails() {
@Test
void then_join_command_succeeds_and_calls_interactor() {
executeJoinCommand();
assertThat(interactor.isJoinChannelCalled()).isTrue();
assertThat(interactor.isSetActiveChannelCalled()).isTrue();
}

@Nested class given_join_fails {
Expand All @@ -93,34 +88,4 @@ void then_join_command_prints_error_message() {
}
}
}

@Nested class setActiveChannel {

@Nested class given_valid_channel {

private void executeSetActiveChannelCommand() {
cmd("channel set-active " + channel.getKey());
}

@Test
void then_setActiveChannel_command_succeeds() {
executeSetActiveChannelCommand();
assertThat(interactor.isSetActiveChannelCalled()).isTrue();
}

@Nested class given_join_channel_fails {

@BeforeEach
void setUp() {
channelCommands.interactor(new FailingChannelInteractorStub());
}

@Test
void then_setActiveChannel_command_does_not_throw() {
executeSetActiveChannelCommand();
assertLastMessageIs(JOIN_CHANNEL_ERROR.build(channel));
}
}
}
}
}

0 comments on commit b084af3

Please sign in to comment.