From ebf301a563acaacf0bccbc437ca5316887ad76ca Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Mon, 10 Aug 2015 18:44:33 +0200 Subject: [PATCH] Add toString() method to default connection --- .../net/pterodactylus/irc/DefaultConnection.java | 5 +++++ .../pterodactylus/irc/DefaultConnectionTest.java | 25 ++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 src/test/java/net/pterodactylus/irc/DefaultConnectionTest.java diff --git a/src/main/java/net/pterodactylus/irc/DefaultConnection.java b/src/main/java/net/pterodactylus/irc/DefaultConnection.java index dd6955c..d352b55 100644 --- a/src/main/java/net/pterodactylus/irc/DefaultConnection.java +++ b/src/main/java/net/pterodactylus/irc/DefaultConnection.java @@ -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 index 0000000..80ee8de --- /dev/null +++ b/src/test/java/net/pterodactylus/irc/DefaultConnectionTest.java @@ -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 David ‘Bombe’ Roden + */ +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))); + } + +} -- 2.7.4