PickledGraphite implements GraphiteSender { @Override public void connect() throws IllegalStateException, IOException { if (isConnected()) { throw new IllegalStateException("Already connected"); } InetSocketAddress address = this.address; if (address == null) { address = new InetSocketAddress(hostname, port); } if (address.getAddress() == null) { throw new UnknownHostException(address.getHostName()); } this.socket = socketFactory.createSocket(address.getAddress(), address.getPort()); this.writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream(), charset)); } PickledGraphite(InetSocketAddress address);  PickledGraphite(InetSocketAddress address, int batchSize);  PickledGraphite(InetSocketAddress address, SocketFactory socketFactory, int batchSize);  PickledGraphite(InetSocketAddress address, SocketFactory socketFactory, Charset charset, int batchSize);  PickledGraphite(String hostname, int port);  PickledGraphite(String hostname, int port, int batchSize);  PickledGraphite(String hostname, int port, SocketFactory socketFactory, int batchSize);  PickledGraphite(String hostname, int port, SocketFactory socketFactory, Charset charset, int batchSize); @Override void connect(); @Override boolean isConnected(); @Override void send(String name, String value, long timestamp); @Override void flush(); @Override void close(); @Override int getFailures();  }
@Test public void doesNotAllowDoubleConnections() throws Exception { graphite.connect(); try { graphite.connect(); failBecauseExceptionWasNotThrown(IllegalStateException.class); } catch (IllegalStateException e) { assertThat(e.getMessage()) .isEqualTo("Already connected"); } }