### Question:
PubSubConnection { public void subscribe(String channelName) throws IOException { if (closed.get()) throw new IOException("Connection closed!"); byte[] command = Util.combine(SUBSCRIBE_COMMAND, channelName.getBytes(), CRLF); outputStream.write(command); } PubSubConnection(Socket socket); void subscribe(String channelName); void unsubscribe(String channelName); PubSubReply read(); void close();  }### Answer:
@Test public void testSubscribe() throws IOException { OutputStream outputStream = mock(OutputStream.class); Socket socket = mock(Socket.class ); when(socket.getOutputStream()).thenReturn(outputStream); PubSubConnection connection = new PubSubConnection(socket); connection.subscribe("foobar"); ArgumentCaptor<byte[]> captor = ArgumentCaptor.forClass(byte[].class); verify(outputStream).write(captor.capture()); assertArrayEquals(captor.getValue(), "SUBSCRIBE foobar\r\n".getBytes()); }