### Question:
OfflineMessageStore extends BasicModule implements UserEventListener { static boolean shouldStoreMessage(final Message message) { if (message.getChildElement("no-store", "urn:xmpp:hints") != null) { return false; } switch (message.getType()) { case chat: Iterator<?> it = message.getElement().elementIterator(); while (it.hasNext()) { Object item = it.next(); if (item instanceof Element) { Element el = (Element) item; if (Namespace.NO_NAMESPACE.equals(el.getNamespace())) { continue; } if (!el.getNamespaceURI().equals("http: && !(el.getQName().equals(QName.get("rtt", "urn:xmpp:rtt:0"))) ) { return true; } } } return message.getBody() != null && !message.getBody().isEmpty(); case groupchat: case headline: return false; case error: if (message.getChildElement("amp", "http: return false; } break; default: break; } return true; } OfflineMessageStore(); static OfflineMessageStore getInstance(); boolean addMessage(Message message); Collection<OfflineMessage> getMessages(String username, boolean delete); OfflineMessage getMessage(String username, Date creationDate); void deleteMessages(String username); void deleteMessage(String username, Date creationDate); int getCount(String username); int getSize(String username); int getSize(); @Override void userCreated(User user, Map<String, Object> params); @Override void userDeleting(User user, Map<String, Object> params); @Override void userModified(User user, Map<String, Object> params); @Override void start(); @Override void stop();  }### Answer:
@Test public void shouldNotStoreGroupChatMessages() { Message message = new Message(); message.setType(Message.Type.groupchat); assertFalse(OfflineMessageStore.shouldStoreMessage(message)); }
@Test public void shouldNotStoreHeadlineMessages() { Message message = new Message(); message.setType(Message.Type.headline); assertFalse(OfflineMessageStore.shouldStoreMessage(message)); }
@Test public void shouldNotStoreErrorMessages() { Message message = new Message(); message.setType(Message.Type.error); assertFalse(OfflineMessageStore.shouldStoreMessage(message)); }
@Test public void shouldStoreNormalMessages() { Message message = new Message(); message.setType(Message.Type.normal); assertTrue(OfflineMessageStore.shouldStoreMessage(message)); Message message2 = new Message(); assertTrue(OfflineMessageStore.shouldStoreMessage(message2)); }
@Test public void shouldNotStoreEmptyChatMessages() { Message message = new Message(); message.setType(Message.Type.chat); assertFalse(OfflineMessageStore.shouldStoreMessage(message)); }
@Test public void shouldStoreNonEmptyChatMessages() { Message message = new Message(); message.setType(Message.Type.chat); message.setBody(" "); assertTrue(OfflineMessageStore.shouldStoreMessage(message)); }
@Test public void shouldNotStoreEmptyChatMessagesWithOnlyChatStates() { Message message = new Message(); message.setType(Message.Type.chat); PacketExtension chatState = new PacketExtension("composing", "http: message.addExtension(chatState); assertFalse(OfflineMessageStore.shouldStoreMessage(message)); }
@Test public void shouldNotStoreEmptyChatMessagesWithOnlyChatStatesAndThread() { Message message = new Message(); message.setType(Message.Type.chat); message.setThread("1234"); PacketExtension chatState = new PacketExtension("composing", "http: message.addExtension(chatState); assertFalse(OfflineMessageStore.shouldStoreMessage(message)); }
@Test public void shouldStoreEmptyChatMessagesWithOtherExtensions() { Message message = new Message(); message.setType(Message.Type.chat); PacketExtension chatState = new PacketExtension("composing", "http: message.addExtension(chatState); PacketExtension packetExtension2 = new PacketExtension("received", "urn:xmpp:receipts"); message.addExtension(packetExtension2); assertTrue(OfflineMessageStore.shouldStoreMessage(message)); }