### Question:
Mediator implements MessageReceiver { @Override public void receiveMessage(Message message, AgentContext c) throws MessageException { if (!message.getRecipientId().equalsIgnoreCase(myAgent.getIdentifier())) { throw new MessageException("I'm not responsible for the receiver (something went very wrong)!"); } try { message.open(myAgent, c); if (getMyNode() != null && !message.getContent().equals("thank you")) { try { Message response = new Message(message, "thank you"); response.setSendingNodeId(getMyNode().getNodeId()); getMyNode().sendMessage(response, null); } catch (EncodingFailedException e) { throw new MessageException("Unable to send response ", e); } catch (SerializationException e) { throw new MessageException("Unable to send response ", e); } } } catch (InternalSecurityException e) { throw new MessageException("Unable to open message because of security problems! ", e); } catch (AgentNotFoundException e) { throw new MessageException( "Sender unkown (since this is the receiver). Has the sending node gone offline? ", e); } catch (AgentException e) { throw new MessageException("Could not read the sender agent", e); } if (!workOnMessage(message, c)) { pending.add(message); } } Mediator(Node n, AgentImpl a); Message getNextMessage(); boolean hasMessages(); @Override void receiveMessage(Message message, AgentContext c); boolean workOnMessage(Message message, AgentContext context); boolean isRegistered(); @Override String getResponsibleForAgentSafeId(); AgentImpl getAgent(); @Override void notifyRegistrationTo(Node node); @Override void notifyUnregister(); @Deprecated Serializable invoke(String service, String method, Serializable[] parameters, boolean localOnly); Serializable invoke(ServiceNameVersion serviceNameVersion, String method, Serializable[] parameters,
			boolean localOnly); int getNumberOfWaiting(); void registerMessageHandler(MessageHandler handler); void unregisterMessageHandler(MessageHandler handler); int unregisterMessageHandlerClass(Class<?> cls); int unregisterMessageHandlerClass(String classname); boolean hasMessageHandler(MessageHandler handler); boolean hasMessageHandlerClass(Class<?> cls);  }### Answer:
@Test public void testWrongRecipient() { try { UserAgentImpl eve = MockAgentFactory.getEve(); eve.unlock("evespass"); UserAgentImpl adam = MockAgentFactory.getAdam(); adam.unlock("adamspass"); Mediator testee = new Mediator(null, eve); Message m = new Message(eve, adam, "a message"); try { testee.receiveMessage(m, null); fail("MessageException expected!"); } catch (MessageException e) { assertTrue(e.getMessage().contains("not responsible")); } } catch (Exception e) { e.printStackTrace(); Assert.fail(e.toString()); } }