aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/net/java/sip/communicator/impl/protocol/irc/command/MsgTest.java131
-rw-r--r--test/net/java/sip/communicator/impl/protocol/irc/command/NickTest.java111
2 files changed, 242 insertions, 0 deletions
diff --git a/test/net/java/sip/communicator/impl/protocol/irc/command/MsgTest.java b/test/net/java/sip/communicator/impl/protocol/irc/command/MsgTest.java
new file mode 100644
index 0000000..5e45794
--- /dev/null
+++ b/test/net/java/sip/communicator/impl/protocol/irc/command/MsgTest.java
@@ -0,0 +1,131 @@
+/*
+ * Jitsi, the OpenSource Java VoIP and Instant Messaging client.
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+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.*;
+
+/**
+ * @author Danny van Heumen
+ */
+public class MsgTest
+ extends TestCase
+{
+ public void testConstruction()
+ {
+ new Msg();
+ }
+
+ public void testGoodInit()
+ {
+ IrcConnection connection = EasyMock.createMock(IrcConnection.class);
+ EasyMock.replay(connection);
+
+ Msg msg = new Msg();
+ msg.init(null, connection);
+ }
+
+ public void testBadInit()
+ {
+ ProtocolProviderServiceIrcImpl provider = EasyMock.createMock(ProtocolProviderServiceIrcImpl.class);
+ EasyMock.replay(provider);
+
+ Msg msg = new Msg();
+ try
+ {
+ msg.init(provider, null);
+ Assert.fail("Should not reach this, expected IAE.");
+ }
+ catch (IllegalArgumentException e)
+ {
+ }
+ }
+
+ public void testMessageNoNickNoMsg()
+ {
+ ProtocolProviderServiceIrcImpl provider = EasyMock.createMock(ProtocolProviderServiceIrcImpl.class);
+ IrcConnection connection = EasyMock.createMock(IrcConnection.class);
+ EasyMock.replay(provider, connection);
+
+ Msg msg = new Msg();
+ msg.init(provider, connection);
+ msg.execute("#test", "/msg");
+ }
+
+ public void testMessageZeroLengthMsg()
+ {
+ ProtocolProviderServiceIrcImpl provider = EasyMock.createMock(ProtocolProviderServiceIrcImpl.class);
+ IrcConnection connection = EasyMock.createMock(IrcConnection.class);
+ EasyMock.replay(provider, connection);
+
+ Msg msg = new Msg();
+ msg.init(provider, connection);
+ try
+ {
+ msg.execute("#test", "/msg ");
+ Assert.fail();
+ }
+ catch (IllegalArgumentException e)
+ {
+ }
+ }
+
+ public void testMessageZeroLengthNickMsg()
+ {
+ ProtocolProviderServiceIrcImpl provider = EasyMock.createMock(ProtocolProviderServiceIrcImpl.class);
+ IrcConnection connection = EasyMock.createMock(IrcConnection.class);
+ EasyMock.replay(provider, connection);
+
+ Msg msg = new Msg();
+ msg.init(provider, connection);
+ try
+ {
+ msg.execute("#test", "/msg ");
+ Assert.fail();
+ }
+ catch (IllegalArgumentException e)
+ {
+ }
+ }
+
+ public void testMessageNickZeroLengthMsg()
+ {
+ ProtocolProviderServiceIrcImpl provider = EasyMock.createMock(ProtocolProviderServiceIrcImpl.class);
+ IrcConnection connection = EasyMock.createMock(IrcConnection.class);
+ EasyMock.replay(provider, connection);
+
+ Msg msg = new Msg();
+ msg.init(provider, connection);
+ try
+ {
+ msg.execute("#test", "/msg target ");
+ Assert.fail();
+ }
+ catch (IllegalArgumentException e)
+ {
+ }
+ }
+
+ public void testPrivateMessage()
+ {
+ ProtocolProviderServiceIrcImpl provider = EasyMock.createMock(ProtocolProviderServiceIrcImpl.class);
+ IrcConnection connection = EasyMock.createMock(IrcConnection.class);
+ IRCApi client = EasyMock.createMock(IRCApi.class);
+ EasyMock.expect(connection.getClient()).andReturn(client);
+ client.message(EasyMock.eq("target"), EasyMock.eq("This is my target message."));
+ EasyMock.expectLastCall();
+ EasyMock.replay(provider, connection);
+
+ Msg msg = new Msg();
+ msg.init(provider, connection);
+ msg.execute("#test", "/msg target This is my target message.");
+ }
+}
diff --git a/test/net/java/sip/communicator/impl/protocol/irc/command/NickTest.java b/test/net/java/sip/communicator/impl/protocol/irc/command/NickTest.java
new file mode 100644
index 0000000..1400c33
--- /dev/null
+++ b/test/net/java/sip/communicator/impl/protocol/irc/command/NickTest.java
@@ -0,0 +1,111 @@
+/*
+ * Jitsi, the OpenSource Java VoIP and Instant Messaging client.
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package net.java.sip.communicator.impl.protocol.irc.command;
+
+import junit.framework.*;
+import net.java.sip.communicator.impl.protocol.irc.*;
+
+import org.easymock.*;
+
+/**
+ * @author Danny van Heumen
+ */
+public class NickTest
+ extends TestCase
+{
+
+ public NickTest(String testName)
+ {
+ super(testName);
+ }
+
+ public void testConstruction()
+ {
+ new Nick();
+ }
+
+ public void testNullProviderInit()
+ {
+ IrcConnection connection = EasyMock.createMock(IrcConnection.class);
+ EasyMock.replay(connection);
+
+ Nick nick = new Nick();
+ nick.init(null, connection);
+ }
+
+ public void testNullConnectionInit()
+ {
+ ProtocolProviderServiceIrcImpl provider =
+ EasyMock.createMock(ProtocolProviderServiceIrcImpl.class);
+ EasyMock.replay(provider);
+
+ Nick nick = new Nick();
+ try
+ {
+ nick.init(provider, null);
+ Assert.fail("Should not reach this as we expected an IAE for null"
+ + " connection.");
+ }
+ catch (IllegalArgumentException e)
+ {
+ // IAE was expected.
+ }
+ }
+
+ public void testEmptyNickCommand()
+ {
+ ProtocolProviderServiceIrcImpl provider =
+ EasyMock.createMock(ProtocolProviderServiceIrcImpl.class);
+ IrcConnection connection = EasyMock.createMock(IrcConnection.class);
+ EasyMock.replay(provider, connection);
+
+ Nick nick = new Nick();
+ nick.init(provider, connection);
+ nick.execute("#test", "/nick");
+ }
+
+ public void testEmptyNickCommandWithSpace()
+ {
+ ProtocolProviderServiceIrcImpl provider =
+ EasyMock.createMock(ProtocolProviderServiceIrcImpl.class);
+ IrcConnection connection = EasyMock.createMock(IrcConnection.class);
+ EasyMock.replay(provider, connection);
+
+ Nick nick = new Nick();
+ nick.init(provider, connection);
+ nick.execute("#test", "/nick ");
+ }
+
+ public void testEmptyNickCommandWithDoubleSpace()
+ {
+ ProtocolProviderServiceIrcImpl provider =
+ EasyMock.createMock(ProtocolProviderServiceIrcImpl.class);
+ IrcConnection connection = EasyMock.createMock(IrcConnection.class);
+ EasyMock.replay(provider, connection);
+
+ Nick nick = new Nick();
+ nick.init(provider, connection);
+ nick.execute("#test", "/nick ");
+ }
+
+ public void testNickCommandWithNickAndSpace()
+ {
+ ProtocolProviderServiceIrcImpl provider =
+ EasyMock.createMock(ProtocolProviderServiceIrcImpl.class);
+ IrcConnection connection = EasyMock.createMock(IrcConnection.class);
+ IdentityManager idmgr = EasyMock.createMock(IdentityManager.class);
+
+ EasyMock.expect(connection.getIdentityManager()).andReturn(idmgr);
+ idmgr.setNick(EasyMock.eq("myNewN1ck"));
+ EasyMock.expectLastCall();
+ EasyMock.replay(provider, connection, idmgr);
+
+ Nick nick = new Nick();
+ nick.init(provider, connection);
+ nick.execute("#test", "/nick myNewN1ck ");
+ }
+}