### Question:
SocketProtocolListener extends SocketListener implements ProtocolListener { @Override public void addHandler(final ProtocolHandler handler) { if (handler == null) { throw new NullPointerException("Protocol handler may not be null."); } handlers.add(handler); } SocketProtocolListener(
            final int numThreads,
            final int port,
            final ServerSocketConfiguration configuration,
            final ProtocolContext<ProtocolMessage> protocolContext); @Override void setBulletinRepository(final BulletinRepository bulletinRepository); @Override void start(); @Override void stop(); @Override Collection<ProtocolHandler> getHandlers(); @Override void addHandler(final ProtocolHandler handler); @Override boolean removeHandler(final ProtocolHandler handler); @Override void dispatchRequest(final Socket socket);  }### Answer:
@Test public void testBadRequest() throws Exception { DelayedProtocolHandler handler = new DelayedProtocolHandler(0); listener.addHandler(handler); socket.getOutputStream().write(5); Thread.sleep(250); assertEquals(0, handler.getMessages().size()); }
@Test public void testRequest() throws Exception { ProtocolMessage msg = new PingMessage(); ReflexiveProtocolHandler handler = new ReflexiveProtocolHandler(); listener.addHandler(handler); marshaller.marshal(msg, socket.getOutputStream()); ProtocolMessage response = unmarshaller.unmarshal(socket.getInputStream()); assertEquals(msg.getType(), response.getType()); assertEquals(1, handler.getMessages().size()); assertEquals(msg.getType(), handler.getMessages().get(0).getType()); }
@Test public void testDelayedRequest() throws Exception { ProtocolMessage msg = new PingMessage(); DelayedProtocolHandler handler = new DelayedProtocolHandler(2000); listener.addHandler(handler); marshaller.marshal(msg, socket.getOutputStream()); try { socket.getInputStream().read(); fail("Socket timeout not received."); } catch (SocketTimeoutException ste) { } assertEquals(1, handler.getMessages().size()); assertEquals(msg.getType(), handler.getMessages().get(0).getType()); }