Skip to content
This repository has been archived by the owner on May 13, 2020. It is now read-only.

Commit

Permalink
Added ChannelHandler Tests. (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcelCoding committed Oct 29, 2019
1 parent 67b9254 commit 21f7d28
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@ public Channel addChanel(final String name) {
}

public void removeChannel(final UUID channelUuid, final UUID userUuid) {
this.removeChannel(channelUuid, userUuid, true);
}

public void removeChannel(final UUID channelUuid, final UUID userUuid, final boolean notifyUsers) {
final Channel channel = this.getChannelByUUID(channelUuid);
this.notifyAllChannelUsers(ChatAction.CHANNEL_DELETE, channel, userUuid);
if (notifyUsers) this.notifyAllChannelUsers(ChatAction.CHANNEL_DELETE, channel, userUuid);
this.channels.remove(channel);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package net.cryptic_game.microservice.chat.channel;

import org.junit.Test;

import static org.junit.Assert.*;

public class ChannelHandlerTests {

@Test
public void testChannelHandlerAddChannel() {
final ChannelHandler channelHandler = new ChannelHandler();

channelHandler.addChanel("test");

assertEquals("test", channelHandler.getChannels().get(0).getName());
}

@Test
public void testChannelHandlerRemoveChannel() {
final ChannelHandler channelHandler = new ChannelHandler();

channelHandler.addChanel("test");

final Channel testChannel = channelHandler.getChannels().get(0);
if (!channelHandler.getChannels().get(0).getName().equals("test")) {
fail();
}

channelHandler.removeChannel(testChannel.getUuid(), null, false);

assertNull(channelHandler.getChannelByUUID(testChannel.getUuid()));
}

@Test
public void testChannelHandlerGetChannelByUuid() {
final ChannelHandler channelHandler = new ChannelHandler();

channelHandler.addChanel("test");
final Channel testChannel = channelHandler.getChannels().get(0);

assertNotNull(channelHandler.getChannelByUUID(testChannel.getUuid()));
}
}

0 comments on commit 21f7d28

Please sign in to comment.