### Question:
User implements Serializable { public void receiveMessage(Message message) { for (MessageReceivedObserver observer : observers) { observer.onMessage(message); } } User(String username); String getUsername(); void setUsername(String username); void listenToMessages(MessageReceivedObserver observer); void receiveMessage(Message message); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString();  }### Answer:
@Test public void receiveMessage() { User carl = new User("carl"); when(group.getName()).thenReturn("mocked-group"); john.listenToMessages(receiver); Message message = new Message(group, carl, "Hello everybody!"); john.receiveMessage(message); Message received = receiver.get(); assertEquals(message, received); }
@Test public void receiveMessageTest() { User carl = new User("carl"); when(group.getName()).thenReturn("mocked-group"); john.listenToMessages(receiver); Message message = new Message(group, carl, "Hello everybody!"); john.receiveMessage(message); Message received = receiver.get(); assertEquals(message, received); }