X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ftest%2Fjava%2Fnet%2Fpterodactylus%2Firc%2Fconnection%2FConnectionEstablishHandlerTest.java;fp=src%2Ftest%2Fjava%2Fnet%2Fpterodactylus%2Firc%2Fconnection%2FConnectionEstablishHandlerTest.java;h=dc9ad5a1431482dd3686d01de09493d3dae1a75a;hb=767b7be6c7e6f5a0d96895ab5019b7eca0982a59;hp=0000000000000000000000000000000000000000;hpb=141a62844c23f4b7734479273cef05cc065babeb;p=xudocci.git
diff --git a/src/test/java/net/pterodactylus/irc/connection/ConnectionEstablishHandlerTest.java b/src/test/java/net/pterodactylus/irc/connection/ConnectionEstablishHandlerTest.java
new file mode 100644
index 0000000..dc9ad5a
--- /dev/null
+++ b/src/test/java/net/pterodactylus/irc/connection/ConnectionEstablishHandlerTest.java
@@ -0,0 +1,58 @@
+package net.pterodactylus.irc.connection;
+
+import static java.util.Arrays.asList;
+import static net.pterodactylus.irc.connection.Replies.createReply;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.mockito.ArgumentCaptor.forClass;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+import net.pterodactylus.irc.Connection;
+import net.pterodactylus.irc.event.ConnectionEstablished;
+
+import com.google.common.eventbus.EventBus;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+
+/**
+ * Unit test for {@link ConnectionEstablishHandler}.
+ *
+ * @author David âBombeâ Roden
+ */
+public class ConnectionEstablishHandlerTest {
+
+ private final EventBus eventBus = mock(EventBus.class);
+ private final Connection connection = mock(Connection.class);
+ private final ConnectionEstablishHandler handler =
+ new ConnectionEstablishHandler(eventBus, connection);
+
+ @Test
+ public void freshHandlerWillHandleTheCorrectCommands() {
+ for (String command : asList("001", "002", "003", "004")) {
+ assertThat(handler.willHandle(createReply(command)), is(true));
+ }
+ }
+
+ @Test
+ public void sendingAllNecessaryCommandsResultsInAnEstablishedConnection() {
+ handler.handleReply(createReply("001"));
+ handler.handleReply(createReply("002"));
+ handler.handleReply(createReply("003"));
+ handler.handleReply(createReply("004"));
+ ArgumentCaptor eventCaptor = forClass(
+ ConnectionEstablished.class);
+ verify(eventBus).post(eventCaptor.capture());
+ ConnectionEstablished event = eventCaptor.getValue();
+ assertThat(event.connection(), is(connection));
+ }
+
+ @Test
+ public void afterAnEstablishedConnectionTheHandlerWillNotHandleTheCommandsAnymore() {
+ sendingAllNecessaryCommandsResultsInAnEstablishedConnection();
+ for (String command : asList("001", "002", "003", "004")) {
+ assertThat(handler.willHandle(createReply(command)), is(false));
+ }
+ }
+
+}