Exemplo n.º 1
0
 public void testRegisterCorrectCommand() {
   CommandFactory.registerCommand("test", Test.class);
   Assert.assertEquals(1, CommandFactory.getCommands().size());
   Assert.assertEquals(Test.class, CommandFactory.getCommands().get("test"));
   CommandFactory.unregisterCommand(Test.class, "test");
   Assert.assertEquals(0, CommandFactory.getCommands().size());
 }
Exemplo n.º 2
0
  public void testNonExistingCommand() throws BadCommandException {
    ProtocolProviderServiceIrcImpl provider =
        EasyMock.createMock(ProtocolProviderServiceIrcImpl.class);
    IrcConnection connection = EasyMock.createMock(IrcConnection.class);
    EasyMock.replay(provider, connection);

    try {
      CommandFactory factory = new CommandFactory(provider, connection);
      factory.createCommand("test");
      Assert.fail();
    } catch (UnsupportedCommandException e) {
    }
  }
Exemplo n.º 3
0
 public void testUnregisterOneAmongMultipleSameType() {
   CommandFactory.registerCommand("test", Test.class);
   CommandFactory.registerCommand("bla", Test.class);
   Assert.assertEquals(Test.class, CommandFactory.getCommands().get("test"));
   Assert.assertEquals(Test.class, CommandFactory.getCommands().get("bla"));
   Assert.assertEquals(2, CommandFactory.getCommands().size());
   CommandFactory.unregisterCommand(Test.class, "test");
   Assert.assertEquals(1, CommandFactory.getCommands().size());
   Assert.assertEquals(Test.class, CommandFactory.getCommands().get("bla"));
   CommandFactory.unregisterCommand(Test.class, null);
 }
Exemplo n.º 4
0
  public void testCreateNullCommandName() throws UnsupportedCommandException, BadCommandException {
    ProtocolProviderServiceIrcImpl provider =
        EasyMock.createMock(ProtocolProviderServiceIrcImpl.class);
    IrcConnection connection = EasyMock.createMock(IrcConnection.class);
    EasyMock.replay(provider, connection);

    CommandFactory.registerCommand("test", Test.class);
    try {
      CommandFactory factory = new CommandFactory(provider, connection);
      factory.createCommand(null);
      Assert.fail();
    } catch (IllegalArgumentException e) {
    }
    CommandFactory.unregisterCommand(Test.class, null);
  }
Exemplo n.º 5
0
 public void testRegisterNullType() {
   try {
     CommandFactory.registerCommand("test", null);
     Assert.fail();
   } catch (IllegalArgumentException e) {
   }
 }
Exemplo n.º 6
0
 public void testRegisterNullCommand() {
   try {
     CommandFactory.registerCommand(null, Test.class);
     Assert.fail();
   } catch (IllegalArgumentException e) {
   }
 }
Exemplo n.º 7
0
  public void testBadCommand() throws UnsupportedCommandException {
    ProtocolProviderServiceIrcImpl provider =
        EasyMock.createMock(ProtocolProviderServiceIrcImpl.class);
    IrcConnection connection = EasyMock.createMock(IrcConnection.class);
    EasyMock.replay(provider, connection);

    CommandFactory.registerCommand("test", BadImplementation.class);
    try {
      CommandFactory factory = new CommandFactory(provider, connection);
      factory.createCommand("test");
      Assert.fail();
    } catch (BadCommandException e) {
    } finally {
      CommandFactory.unregisterCommand(BadImplementation.class, null);
    }
  }
Exemplo n.º 8
0
  public void testExistingCommand() throws UnsupportedCommandException, BadCommandException {
    ProtocolProviderServiceIrcImpl provider =
        EasyMock.createMock(ProtocolProviderServiceIrcImpl.class);
    IrcConnection connection = EasyMock.createMock(IrcConnection.class);
    EasyMock.replay(provider, connection);

    CommandFactory.registerCommand("test", Test.class);
    try {
      CommandFactory factory = new CommandFactory(provider, connection);
      Command cmd = factory.createCommand("test");
      Assert.assertNotNull(cmd);
      Assert.assertTrue(cmd instanceof Test);
    } finally {
      CommandFactory.unregisterCommand(Test.class, null);
    }
  }
Exemplo n.º 9
0
 public void testRegisterMultipleCommandsForType() {
   CommandFactory.registerCommand("test", Test.class);
   CommandFactory.registerCommand("bla", Test.class);
   Assert.assertEquals(Test.class, CommandFactory.getCommands().get("test"));
   Assert.assertEquals(Test.class, CommandFactory.getCommands().get("bla"));
   Assert.assertEquals(2, CommandFactory.getCommands().size());
   CommandFactory.unregisterCommand(Test.class, null);
   Assert.assertEquals(0, CommandFactory.getCommands().size());
 }
Exemplo n.º 10
0
  public void testUnregisterMultipleAmongOtherTypes() {
    Command anotherType =
        new Command() {

          @Override
          public void execute(String source, String line) {}

          @Override
          public String help() {
            return null;
          }
        };
    CommandFactory.registerCommand("test", Test.class);
    CommandFactory.registerCommand("foo", anotherType.getClass());
    CommandFactory.registerCommand("bla", Test.class);
    Assert.assertEquals(Test.class, CommandFactory.getCommands().get("test"));
    Assert.assertEquals(Test.class, CommandFactory.getCommands().get("bla"));
    Assert.assertNotNull(CommandFactory.getCommands().get("foo"));
    Assert.assertEquals(3, CommandFactory.getCommands().size());
    CommandFactory.unregisterCommand(Test.class, null);
    Assert.assertEquals(1, CommandFactory.getCommands().size());
    Assert.assertNotSame(Test.class, CommandFactory.getCommands().get("foo"));
    CommandFactory.unregisterCommand(anotherType.getClass(), null);
  }
Exemplo n.º 11
0
 public void testCommandsAvailable() {
   Assert.assertNotNull(CommandFactory.getCommands());
 }