### Eclipse Workspace Patch 1.0 #P org.eclipse.ecf.provider.irc Index: src/org/eclipse/ecf/internal/provider/irc/container/IRCRootContainerTest.java =================================================================== RCS file: src/org/eclipse/ecf/internal/provider/irc/container/IRCRootContainerTest.java diff -N src/org/eclipse/ecf/internal/provider/irc/container/IRCRootContainerTest.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/ecf/internal/provider/irc/container/IRCRootContainerTest.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,134 @@ +package org.eclipse.ecf.internal.provider.irc.container; + +import junit.framework.TestCase; + +import org.eclipse.ecf.core.identity.IDCreateException; +import org.schwering.irc.lib.IRCConnection; + +public class IRCRootContainerTest extends TestCase { + + /** + * IRCConnection, that doesn't actually send anything + */ + class MockIRCConnection extends IRCConnection { + public String sent; + public MockIRCConnection() { + super("", 0, 0, "", "", "", ""); + } + + @Override + public void send(String line) { + sent = line; + } + } + + protected MockIRCConnection connection = new MockIRCConnection(); + + /** + * IRCRootContainer with mock connection and verbose error handling + */ + class TestIRCRootContainer extends IRCRootContainer { + public TestIRCRootContainer() throws IDCreateException { + super(null); + this.connection = IRCRootContainerTest.this.connection; + } + + protected void traceStack(Throwable t, String msg) { + fail(msg); + } + + }; + + protected IRCRootContainer fixture; + + protected void setUp() throws IDCreateException { + fixture = new TestIRCRootContainer(); + } + + public void testParseCommandAndSendKick() { + fixture.parseCommandAndSend("/kick john", "#defaultchannel"); + assertEquals("KICK #defaultchannel john", connection.sent); + + fixture.parseCommandAndSend("/kick john go away", "#defaultchannel"); + assertEquals("KICK #defaultchannel john :go away", connection.sent); + + fixture.parseCommandAndSend("/kick #channel john", "#defaultchannel"); + assertEquals("KICK #channel john", connection.sent); + + fixture.parseCommandAndSend("/kick #channel john go away", "#defaultchannel"); + assertEquals("KICK #channel john :go away", connection.sent); + + fixture.parseCommandAndSend("/kick #channel john go away", "#defaultchannel"); + assertEquals("KICK #channel john :go away", connection.sent); + } + + public void testParseCommandAndSendBan() { + fixture.parseCommandAndSend("/ban john", "#defaultchannel"); + assertEquals("MODE #defaultchannel +b john", connection.sent); + } + + public void testParseCommandAndSendUnban() { + fixture.parseCommandAndSend("/unban john", "#defaultchannel"); + assertEquals("MODE #defaultchannel -b john", connection.sent); + } + + public void testParseCommandAndSendOp() { + fixture.parseCommandAndSend("/op john", "#defaultchannel"); + assertEquals("MODE #defaultchannel +o john", connection.sent); + } + + public void testParseCommandAndSendDop() { + fixture.parseCommandAndSend("/dop john", "#defaultchannel"); + assertEquals("MODE #defaultchannel -o john", connection.sent); + } + + public void testNextToken1() { + StringBuffer sb = new StringBuffer("oneToken"); + + String token = fixture.nextToken(sb); + assertEquals("oneToken", token); + assertEquals("", sb.toString()); + + token = fixture.nextToken(sb); + assertNull(token); + assertEquals("", sb.toString()); + } + + public void testNextToken2() { + StringBuffer sb = new StringBuffer("some tokens a "); + + String token = fixture.nextToken(sb); + assertEquals("some", token); + assertEquals("tokens a ", sb.toString()); + + token = fixture.nextToken(sb); + assertEquals("tokens", token); + assertEquals("a ", sb.toString()); + + token = fixture.nextToken(sb); + assertEquals("a", token); + assertEquals("", sb.toString()); + + token = fixture.nextToken(sb); + assertNull(token); + assertEquals("", sb.toString()); + } + + public void testNextToken3() { + StringBuffer sb = new StringBuffer(" afterSpaces"); + + // thats tricky - if buffer starts with whitespaces, they must be stripped first + String token = fixture.nextToken(sb); + assertEquals("", token); + assertEquals("afterSpaces", sb.toString()); + + token = fixture.nextToken(sb); + assertEquals("afterSpaces", token); + assertEquals("", sb.toString()); + + token = fixture.nextToken(sb); + assertNull(token); + assertEquals("", sb.toString()); + } + +}