### Question:
DropDaemon implements Runnable { void receiveMessages() { try { Map<String, List<ChatDropMessage>> identityListMap = chatService.refreshMessages(); for (Map.Entry<String, List<ChatDropMessage>> messages: identityListMap.entrySet()) { String identityKeyId = messages.getKey(); Identity identity = identityRepository.find(identityKeyId); for (ChatDropMessage msg: messages.getValue()) { Contact contact = contactRepository.find(msg.getContactId()); DropMessage dropMessage = new DropMessage(contact, msg.getPayload().toString(), msg.getMessageType().getType()); boolean incoming = msg.getDirection().equals(ChatDropMessage.Direction.INCOMING); Entity sender = incoming ? contact : identity; Entity receiver = incoming ? identity : contact; PersistenceDropMessage message = new PersistenceDropMessage(dropMessage, sender, receiver, !incoming, false); dropMessageRepository.save(message); events.push(new MessageReceivedEvent(message)); } } } catch (Exception e) { logger.error("Unexpected error while polling drops: " + e.getMessage(), e); } } DropDaemon(ChatService chatService,
                      DropMessageRepository dropMessageRepository,
                      ContactRepository contactRepository,
                      IdentityRepository identityRepository,
                      EventSink events
    ); @Override void run();  }### Answer:
@Test public void receiveMessagesTest() throws Exception { send(c, senderIdentity); dd.receiveMessages(); List<PersistenceDropMessage> lst = dropMessageRepository.loadConversation(sender, identity); assertEquals(1, lst.size()); assertFalse(lst.get(0).isSent()); }
@Test public void helloProtocol() throws Exception { Identity otherIdentity = identityBuilderFactory.factory().withAlias("tester2").build(); Contact otherIdentitiesContact = getContact(otherIdentity); send(c, otherIdentity); dd.receiveMessages(); Contact other = contactRepository.findByKeyId(identity, otherIdentitiesContact.getKeyIdentifier()); assertThat(otherIdentitiesContact.getAlias(), equalTo(other.getAlias())); assertThat(other.getStatus(), equalTo(Contact.ContactStatus.UNKNOWN)); }
@Test public void receivesMessagesForAllIdentities() throws Exception { Identity otherIdentity = identityBuilderFactory.factory().withAlias("tester2").build(); Contact otherIdentitiesContact = getContact(otherIdentity); identityRepository.save(otherIdentity); contactRepository.save(sender, otherIdentity); send(otherIdentitiesContact, senderIdentity); dd.receiveMessages(); assertThat(dropMessageRepository.loadConversation(sender, otherIdentity), is(not(empty()))); }