diff options
author | Danny van Heumen <danny@dannyvanheumen.nl> | 2014-11-17 23:12:00 +0100 |
---|---|---|
committer | Danny van Heumen <danny@dannyvanheumen.nl> | 2014-11-20 21:00:49 +0100 |
commit | d750dab7987c4ea9272475fa7be33db98b5a8daf (patch) | |
tree | 131a29c5aef5f672c5ed5ebd7221aedecbb7e1c7 /test/net/java/sip/communicator | |
parent | 6cb3c0e2dea8015e31a281d21f47861e31105ab4 (diff) | |
download | jitsi-d750dab7987c4ea9272475fa7be33db98b5a8daf.zip jitsi-d750dab7987c4ea9272475fa7be33db98b5a8daf.tar.gz jitsi-d750dab7987c4ea9272475fa7be33db98b5a8daf.tar.bz2 |
Improved the Command - CommandFactory implementation.
* Moved from 'init' method to constructor.
* Expected format for the constructor described in the Command
interface comments.
* Distinguish between exceptions that occur during construction of the
command, log these and inform the user of an error; and exception
occurring during the execution of the command.
* Better error handling for commands.
To do:
* Add 'help' method to the Command interface.
* Catch IllegalArgumentException and automatically display help()
information to the user.
Diffstat (limited to 'test/net/java/sip/communicator')
6 files changed, 44 insertions, 117 deletions
diff --git a/test/net/java/sip/communicator/impl/protocol/irc/CommandFactoryTest.java b/test/net/java/sip/communicator/impl/protocol/irc/CommandFactoryTest.java index 2b5c6b4..a47f0d4 100644 --- a/test/net/java/sip/communicator/impl/protocol/irc/CommandFactoryTest.java +++ b/test/net/java/sip/communicator/impl/protocol/irc/CommandFactoryTest.java @@ -23,19 +23,7 @@ public class CommandFactoryTest { try { - CommandFactory.registerCommand(null, new Command() - { - @Override - public void init(ProtocolProviderServiceIrcImpl provider, - IrcConnection connection) - { - } - - @Override - public void execute(String source, String line) - { - } - }.getClass()); + CommandFactory.registerCommand(null, Test.class); Assert.fail(); } catch (IllegalArgumentException e) @@ -83,12 +71,6 @@ public class CommandFactoryTest Command anotherType = new Command() { @Override - public void init(ProtocolProviderServiceIrcImpl provider, - IrcConnection connection) - { - } - - @Override public void execute(String source, String line) { }}; @@ -124,9 +106,7 @@ public class CommandFactoryTest public static class Test implements Command { - - @Override - public void init(ProtocolProviderServiceIrcImpl provider, + public Test(ProtocolProviderServiceIrcImpl provider, IrcConnection connection) { } @@ -177,7 +157,7 @@ public class CommandFactoryTest new CommandFactory(provider, connection); } - public void testNonExistingCommand() + public void testNonExistingCommand() throws BadCommandException { ProtocolProviderServiceIrcImpl provider = EasyMock.createMock(ProtocolProviderServiceIrcImpl.class); IrcConnection connection = EasyMock.createMock(IrcConnection.class); @@ -194,7 +174,7 @@ public class CommandFactoryTest } } - public void testCreateNullCommandName() throws UnsupportedCommandException + public void testCreateNullCommandName() throws UnsupportedCommandException, BadCommandException { ProtocolProviderServiceIrcImpl provider = EasyMock.createMock(ProtocolProviderServiceIrcImpl.class); IrcConnection connection = EasyMock.createMock(IrcConnection.class); @@ -213,7 +193,7 @@ public class CommandFactoryTest CommandFactory.unregisterCommand(Test.class, null); } - public void testCreateEmptyCommandName() throws UnsupportedCommandException + public void testCreateEmptyCommandName() throws UnsupportedCommandException, BadCommandException { ProtocolProviderServiceIrcImpl provider = EasyMock.createMock(ProtocolProviderServiceIrcImpl.class); IrcConnection connection = EasyMock.createMock(IrcConnection.class); @@ -235,7 +215,7 @@ public class CommandFactoryTest } } - public void testExistingCommand() throws UnsupportedCommandException + public void testExistingCommand() throws UnsupportedCommandException, BadCommandException { ProtocolProviderServiceIrcImpl provider = EasyMock.createMock(ProtocolProviderServiceIrcImpl.class); IrcConnection connection = EasyMock.createMock(IrcConnection.class); @@ -268,7 +248,7 @@ public class CommandFactoryTest factory.createCommand("test"); Assert.fail(); } - catch (IllegalStateException e) + catch (BadCommandException e) { } finally @@ -290,7 +270,7 @@ public class CommandFactoryTest factory.createCommand("test"); Assert.fail(); } - catch (IllegalStateException e) + catch (BadCommandException e) { } finally @@ -299,11 +279,9 @@ public class CommandFactoryTest } } - private static class Unreachable implements Command + private static final class Unreachable implements Command { - - @Override - public void init(ProtocolProviderServiceIrcImpl provider, + private Unreachable(ProtocolProviderServiceIrcImpl provider, IrcConnection connection) { } @@ -316,5 +294,9 @@ public class CommandFactoryTest public abstract static class BadImplementation implements Command { + public BadImplementation(ProtocolProviderServiceIrcImpl provider, + IrcConnection connection) + { + } } } 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 index e2cc5a6..1e56f55 100644 --- a/test/net/java/sip/communicator/impl/protocol/irc/command/JoinTest.java +++ b/test/net/java/sip/communicator/impl/protocol/irc/command/JoinTest.java @@ -17,18 +17,12 @@ 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); + new Join(null, connection); } public void testBadInit() @@ -36,10 +30,9 @@ public class JoinTest ProtocolProviderServiceIrcImpl provider = EasyMock.createMock(ProtocolProviderServiceIrcImpl.class); EasyMock.replay(provider); - Join join = new Join(); try { - join.init(provider, null); + new Join(provider, null); Assert.fail(); } catch (IllegalArgumentException e) @@ -52,8 +45,7 @@ public class JoinTest IrcConnection connection = EasyMock.createMock(IrcConnection.class); EasyMock.replay(connection); - Join join = new Join(); - join.init(null, connection); + Join join = new Join(null, connection); join.execute("#test", "/join"); } @@ -62,8 +54,7 @@ public class JoinTest IrcConnection connection = EasyMock.createMock(IrcConnection.class); EasyMock.replay(connection); - Join join = new Join(); - join.init(null, connection); + Join join = new Join(null, connection); try { join.execute("#test", "/join "); @@ -83,8 +74,7 @@ public class JoinTest EasyMock.expectLastCall(); EasyMock.replay(connection, client); - Join join = new Join(); - join.init(null, connection); + Join join = new Join(null, connection); join.execute("#test", "/join #test"); } @@ -97,8 +87,7 @@ public class JoinTest EasyMock.expectLastCall(); EasyMock.replay(connection, client); - Join join = new Join(); - join.init(null, connection); + Join join = new Join(null, connection); join.execute("#test", "/join #test top-secret"); } } diff --git a/test/net/java/sip/communicator/impl/protocol/irc/command/MeTest.java b/test/net/java/sip/communicator/impl/protocol/irc/command/MeTest.java index 7bb410b..5987d85 100644 --- a/test/net/java/sip/communicator/impl/protocol/irc/command/MeTest.java +++ b/test/net/java/sip/communicator/impl/protocol/irc/command/MeTest.java @@ -16,18 +16,12 @@ import com.ircclouds.irc.api.*; public class MeTest extends TestCase { - public void testConstruction() - { - new Me(); - } - public void testGoodInit() { IrcConnection connection = EasyMock.createMock(IrcConnection.class); EasyMock.replay(connection); - Me me = new Me(); - me.init(null, connection); + Me me = new Me(null, connection); } public void testBadInit() @@ -35,10 +29,9 @@ public class MeTest extends TestCase ProtocolProviderServiceIrcImpl provider = EasyMock.createMock(ProtocolProviderServiceIrcImpl.class); EasyMock.replay(provider); - Me me = new Me(); try { - me.init(provider, null); + Me me = new Me(provider, null); Assert.fail(); } catch (IllegalArgumentException e) @@ -52,8 +45,7 @@ public class MeTest extends TestCase IrcConnection connection = EasyMock.createMock(IrcConnection.class); EasyMock.replay(provider, connection); - Me me = new Me(); - me.init(provider, connection); + Me me = new Me(provider, connection); me.execute("#test", "/me"); } @@ -63,8 +55,7 @@ public class MeTest extends TestCase IrcConnection connection = EasyMock.createMock(IrcConnection.class); EasyMock.replay(provider, connection); - Me me = new Me(); - me.init(provider, connection); + Me me = new Me(provider, connection); try { me.execute("#test", "/me "); @@ -85,8 +76,7 @@ public class MeTest extends TestCase EasyMock.expectLastCall(); EasyMock.replay(provider, connection, client); - Me me = new Me(); - me.init(provider, connection); + Me me = new Me(provider, connection); me.execute("#test", "/me says hello world!"); } } 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 index 1a9aa95..fd6b910 100644 --- a/test/net/java/sip/communicator/impl/protocol/irc/command/ModeTest.java +++ b/test/net/java/sip/communicator/impl/protocol/irc/command/ModeTest.java @@ -17,18 +17,12 @@ 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); + Mode mode = new Mode(null, connection); } public void testBadInit() @@ -37,10 +31,9 @@ public class ModeTest EasyMock.createMock(ProtocolProviderServiceIrcImpl.class); EasyMock.replay(provider); - Mode mode = new Mode(); try { - mode.init(provider, null); + Mode mode = new Mode(provider, null); Assert.fail(); } catch (IllegalArgumentException e) @@ -53,8 +46,7 @@ public class ModeTest IrcConnection connection = EasyMock.createMock(IrcConnection.class); EasyMock.replay(connection); - Mode mode = new Mode(); - mode.init(null, connection); + Mode mode = new Mode(null, connection); mode.execute("#test", "/mode"); } @@ -63,8 +55,7 @@ public class ModeTest IrcConnection connection = EasyMock.createMock(IrcConnection.class); EasyMock.replay(connection); - Mode mode = new Mode(); - mode.init(null, connection); + Mode mode = new Mode(null, connection); mode.execute("#test", "/mode "); } @@ -73,8 +64,7 @@ public class ModeTest IrcConnection connection = EasyMock.createMock(IrcConnection.class); EasyMock.replay(connection); - Mode mode = new Mode(); - mode.init(null, connection); + Mode mode = new Mode(null, connection); try { mode.execute("#test", "/mode "); @@ -93,8 +83,7 @@ public class ModeTest EasyMock.expectLastCall(); EasyMock.replay(connection, client); - Mode mode = new Mode(); - mode.init(null, connection); + Mode mode = new Mode(null, connection); mode.execute("#test", "/mode +o ThaDud3"); } } 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 index 5e45794..67adf1d 100644 --- a/test/net/java/sip/communicator/impl/protocol/irc/command/MsgTest.java +++ b/test/net/java/sip/communicator/impl/protocol/irc/command/MsgTest.java @@ -19,18 +19,12 @@ import com.ircclouds.irc.api.*; 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); + new Msg(null, connection); } public void testBadInit() @@ -38,10 +32,9 @@ public class MsgTest ProtocolProviderServiceIrcImpl provider = EasyMock.createMock(ProtocolProviderServiceIrcImpl.class); EasyMock.replay(provider); - Msg msg = new Msg(); try { - msg.init(provider, null); + new Msg(provider, null); Assert.fail("Should not reach this, expected IAE."); } catch (IllegalArgumentException e) @@ -55,8 +48,7 @@ public class MsgTest IrcConnection connection = EasyMock.createMock(IrcConnection.class); EasyMock.replay(provider, connection); - Msg msg = new Msg(); - msg.init(provider, connection); + Msg msg = new Msg(provider, connection); msg.execute("#test", "/msg"); } @@ -66,8 +58,7 @@ public class MsgTest IrcConnection connection = EasyMock.createMock(IrcConnection.class); EasyMock.replay(provider, connection); - Msg msg = new Msg(); - msg.init(provider, connection); + Msg msg = new Msg(provider, connection); try { msg.execute("#test", "/msg "); @@ -84,8 +75,7 @@ public class MsgTest IrcConnection connection = EasyMock.createMock(IrcConnection.class); EasyMock.replay(provider, connection); - Msg msg = new Msg(); - msg.init(provider, connection); + Msg msg = new Msg(provider, connection); try { msg.execute("#test", "/msg "); @@ -102,8 +92,7 @@ public class MsgTest IrcConnection connection = EasyMock.createMock(IrcConnection.class); EasyMock.replay(provider, connection); - Msg msg = new Msg(); - msg.init(provider, connection); + Msg msg = new Msg(provider, connection); try { msg.execute("#test", "/msg target "); @@ -124,8 +113,7 @@ public class MsgTest EasyMock.expectLastCall(); EasyMock.replay(provider, connection); - Msg msg = new Msg(); - msg.init(provider, connection); + Msg msg = new Msg(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 index 1400c33..494f86e 100644 --- a/test/net/java/sip/communicator/impl/protocol/irc/command/NickTest.java +++ b/test/net/java/sip/communicator/impl/protocol/irc/command/NickTest.java @@ -23,18 +23,12 @@ public class NickTest 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); + new Nick(null, connection); } public void testNullConnectionInit() @@ -43,10 +37,9 @@ public class NickTest EasyMock.createMock(ProtocolProviderServiceIrcImpl.class); EasyMock.replay(provider); - Nick nick = new Nick(); try { - nick.init(provider, null); + new Nick(provider, null); Assert.fail("Should not reach this as we expected an IAE for null" + " connection."); } @@ -63,8 +56,7 @@ public class NickTest IrcConnection connection = EasyMock.createMock(IrcConnection.class); EasyMock.replay(provider, connection); - Nick nick = new Nick(); - nick.init(provider, connection); + Nick nick = new Nick(provider, connection); nick.execute("#test", "/nick"); } @@ -75,8 +67,7 @@ public class NickTest IrcConnection connection = EasyMock.createMock(IrcConnection.class); EasyMock.replay(provider, connection); - Nick nick = new Nick(); - nick.init(provider, connection); + Nick nick = new Nick(provider, connection); nick.execute("#test", "/nick "); } @@ -87,8 +78,7 @@ public class NickTest IrcConnection connection = EasyMock.createMock(IrcConnection.class); EasyMock.replay(provider, connection); - Nick nick = new Nick(); - nick.init(provider, connection); + Nick nick = new Nick(provider, connection); nick.execute("#test", "/nick "); } @@ -104,8 +94,7 @@ public class NickTest EasyMock.expectLastCall(); EasyMock.replay(provider, connection, idmgr); - Nick nick = new Nick(); - nick.init(provider, connection); + Nick nick = new Nick(provider, connection); nick.execute("#test", "/nick myNewN1ck "); } } |