Add toString() method to default connection
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 10 Aug 2015 16:44:33 +0000 (18:44 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 10 Aug 2015 16:44:33 +0000 (18:44 +0200)
src/main/java/net/pterodactylus/irc/DefaultConnection.java
src/test/java/net/pterodactylus/irc/DefaultConnectionTest.java [new file with mode: 0644]

index dd6955c..d352b55 100644 (file)
@@ -410,6 +410,11 @@ public class DefaultConnection extends AbstractExecutionThreadService implements
                return Optional.empty();
        }
 
+       @Override
+       public String toString() {
+               return String.format("→ %s:%d", hostname, port);
+       }
+
        /** Handles input and output for the connection. */
        private class ConnectionHandler implements Closeable {
 
diff --git a/src/test/java/net/pterodactylus/irc/DefaultConnectionTest.java b/src/test/java/net/pterodactylus/irc/DefaultConnectionTest.java
new file mode 100644 (file)
index 0000000..80ee8de
--- /dev/null
@@ -0,0 +1,25 @@
+package net.pterodactylus.irc;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.containsString;
+
+import org.junit.Test;
+
+/**
+ * Unit test for {@link DefaultConnection}.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class DefaultConnectionTest {
+
+       private static final String HOSTNAME = "some.host.name";
+       private static final int PORT = 12345;
+
+       @Test
+       public void toStringContainsHostnameAndPort() {
+               DefaultConnection defaultConnection = new DefaultConnection(null, null, HOSTNAME, PORT);
+               assertThat(defaultConnection.toString(), containsString(HOSTNAME));
+               assertThat(defaultConnection.toString(), containsString(String.valueOf(PORT)));
+       }
+
+}