### Question:
Group implements Serializable { public void sendMessage(Message message) throws UserNotInGroupException { checkUserInGroup(message.getSender()); messages.add(message); for(User user: users) { user.receiveMessage(message); } } Group(); void sendMessage(Message message); void join(User user); void leave(User user); void observe(GroupChangeListener listener); List<Message> messages(); int size(); Set<User> users(); String getName(); void setName(String name); boolean in(User user); @Override boolean equals(Object o); @Override int hashCode();  }### Answer:
@Test public void sendMessageTest() { System.out.println(john); group.join(john); group.join(carl); group.join(mark); Message m = new Message(group, john, "hello"); group.sendMessage(m); List<Message> messages = group.messages(); List<Message> expected = Collections.singletonList(m); assertThat(messages, is(expected)); verify(john).receiveMessage(m); verify(carl).receiveMessage(m); verify(mark).receiveMessage(m); }
@Test(expected = UserNotInGroupException.class) public void testIllegalMessage() throws RemoteException { Message message = new Message(group, john, "hello"); group.sendMessage(message); }