@Test public void addHandler() { MessageDeserializer deserializer = mock(MessageDeserializer.class); MessageDataExtractor extractor = mock(MessageDataExtractor.class); MessageDispatcher dispatcher = new MessageDispatcher(deserializer, extractor); MessageHandler<String> handler = mock(MessageHandler.class); when(handler.getMessageType()).thenReturn(String.class); dispatcher.addHandler(handler); byte[] payload = new byte[0]; when(extractor.getMessageData(eq(payload))).thenReturn( new MessageData( "String", "content" ) ); when( deserializer.deserialize(eq("content"), eq(String.class))).thenReturn("XXX"); dispatcher.dispatch(payload); verify(handler).accept(eq("XXX")); }
public void addHandler(MessageHandler<?> handler) { this.handlers.put(typeName(handler.getMessageType()), handler); }
MessageDispatcher { public void addHandler(MessageHandler<?> handler) { this.handlers.put(typeName(handler.getMessageType()), handler); } }
MessageDispatcher { public void addHandler(MessageHandler<?> handler) { this.handlers.put(typeName(handler.getMessageType()), handler); }  }
MessageDispatcher { public void addHandler(MessageHandler<?> handler) { this.handlers.put(typeName(handler.getMessageType()), handler); }  void addHandler(MessageHandler<?> handler); void dispatch(byte[] payload); }
MessageDispatcher { public void addHandler(MessageHandler<?> handler) { this.handlers.put(typeName(handler.getMessageType()), handler); }  void addHandler(MessageHandler<?> handler); void dispatch(byte[] payload);  }