From da53b1f81012fa99d5090c2c587fef370d3c0de7 Mon Sep 17 00:00:00 2001 From: Danny van Heumen Date: Sun, 9 Nov 2014 20:53:39 +0100 Subject: Fine-tuned commands Mode, Join + added unit tests. --- .../impl/protocol/irc/command/JoinTest.java | 98 ++++++++++++++++++++++ .../impl/protocol/irc/command/ModeTest.java | 94 +++++++++++++++++++++ 2 files changed, 192 insertions(+) create mode 100644 test/net/java/sip/communicator/impl/protocol/irc/command/JoinTest.java create mode 100644 test/net/java/sip/communicator/impl/protocol/irc/command/ModeTest.java (limited to 'test') diff --git a/test/net/java/sip/communicator/impl/protocol/irc/command/JoinTest.java b/test/net/java/sip/communicator/impl/protocol/irc/command/JoinTest.java new file mode 100644 index 0000000..3819f33 --- /dev/null +++ b/test/net/java/sip/communicator/impl/protocol/irc/command/JoinTest.java @@ -0,0 +1,98 @@ +package net.java.sip.communicator.impl.protocol.irc.command; + +import junit.framework.*; +import net.java.sip.communicator.impl.protocol.irc.*; + +import org.easymock.*; + +import com.ircclouds.irc.api.*; + +public class JoinTest + extends TestCase +{ + + public void testConstruction() + { + new Join(); + } + + public void testGoodInit() + { + IrcConnection connection = EasyMock.createMock(IrcConnection.class); + EasyMock.replay(connection); + + Join join = new Join(); + join.init(null, connection); + } + + public void testBadInit() + { + ProtocolProviderServiceIrcImpl provider = EasyMock.createMock(ProtocolProviderServiceIrcImpl.class); + EasyMock.replay(provider); + + Join join = new Join(); + try + { + join.init(provider, null); + Assert.fail(); + } + catch (IllegalArgumentException e) + { + } + } + + public void testEmptyJoin() + { + IrcConnection connection = EasyMock.createMock(IrcConnection.class); + EasyMock.replay(connection); + + Join join = new Join(); + join.init(null, connection); + join.execute("#test", "/join"); + } + + public void testJoinEmptyChannelNoPassword() + { + IrcConnection connection = EasyMock.createMock(IrcConnection.class); + EasyMock.replay(connection); + + Join join = new Join(); + join.init(null, connection); + try + { + join.execute("#test", "/join "); + Assert.fail(); + } + catch (IllegalArgumentException e) + { + } + } + + public void testJoinWithChannelNoPassword() + { + IrcConnection connection = EasyMock.createMock(IrcConnection.class); + IRCApi client = EasyMock.createMock(IRCApi.class); + EasyMock.expect(connection.getClient()).andReturn(client); + client.joinChannel(EasyMock.eq("#test"), EasyMock.eq("")); + EasyMock.expectLastCall(); + EasyMock.replay(connection, client); + + Join join = new Join(); + join.init(null, connection); + join.execute("#test", "/join #test"); + } + + public void testJoinWithChannelWithPassword() + { + IrcConnection connection = EasyMock.createMock(IrcConnection.class); + IRCApi client = EasyMock.createMock(IRCApi.class); + EasyMock.expect(connection.getClient()).andReturn(client); + client.joinChannel(EasyMock.eq("#test"), EasyMock.eq("top-secret")); + EasyMock.expectLastCall(); + EasyMock.replay(connection, client); + + Join join = new Join(); + join.init(null, connection); + join.execute("#test", "/join #test top-secret"); + } +} diff --git a/test/net/java/sip/communicator/impl/protocol/irc/command/ModeTest.java b/test/net/java/sip/communicator/impl/protocol/irc/command/ModeTest.java new file mode 100644 index 0000000..9c582e3 --- /dev/null +++ b/test/net/java/sip/communicator/impl/protocol/irc/command/ModeTest.java @@ -0,0 +1,94 @@ +package net.java.sip.communicator.impl.protocol.irc.command; + +import junit.framework.*; +import net.java.sip.communicator.impl.protocol.irc.*; + +import org.easymock.*; + +import com.ircclouds.irc.api.*; + +public class ModeTest + extends TestCase +{ + + public void testConstruction() + { + new Mode(); + } + + public void testGoodInit() + { + IrcConnection connection = EasyMock.createMock(IrcConnection.class); + EasyMock.replay(connection); + + Mode mode = new Mode(); + mode.init(null, connection); + } + + public void testBadInit() + { + ProtocolProviderServiceIrcImpl provider = + EasyMock.createMock(ProtocolProviderServiceIrcImpl.class); + EasyMock.replay(provider); + + Mode mode = new Mode(); + try + { + mode.init(provider, null); + Assert.fail(); + } + catch (IllegalArgumentException e) + { + } + } + + public void testEmptyCommand() + { + IrcConnection connection = EasyMock.createMock(IrcConnection.class); + EasyMock.replay(connection); + + Mode mode = new Mode(); + mode.init(null, connection); + mode.execute("#test", "/mode"); + } + + public void testEmptyModeLine() + { + IrcConnection connection = EasyMock.createMock(IrcConnection.class); + EasyMock.replay(connection); + + Mode mode = new Mode(); + mode.init(null, connection); + mode.execute("#test", "/mode "); + } + + public void testSpacesModeLine() + { + IrcConnection connection = EasyMock.createMock(IrcConnection.class); + EasyMock.replay(connection); + + Mode mode = new Mode(); + mode.init(null, connection); + try + { + mode.execute("#test", "/mode "); + } + catch (IllegalArgumentException e) + { + } + } + + public void testCorrectModeCommand() + { + IrcConnection connection = EasyMock.createMock(IrcConnection.class); + IRCApi client = EasyMock.createMock(IRCApi.class); + EasyMock.expect(connection.getClient()).andReturn(client); + client.changeMode(EasyMock.eq("#test +o ThaDud3")); + EasyMock.expectLastCall(); + EasyMock.replay(connection, client); + + Mode mode = new Mode(); + mode.init(null, connection); + mode.execute("#test", "/mode +o ThaDud3"); + } +} -- cgit v1.1