### Question:
HibernateSystemMessageDAO extends HibernatePersistentObjectDAO<SystemMessage> implements SystemMessageDAO { @Override public boolean store(SystemMessage message) throws PersistenceException { long originalId = message.getId(); boolean stored = super.store(message); if (stored && originalId == 0L && message.getType() == SystemMessage.TYPE_SYSTEM) { UserHistoryDAO hDao = (UserHistoryDAO) Context.get().getBean(UserHistoryDAO.class); UserDAO uDao = (UserDAO) Context.get().getBean(UserDAO.class); for (Recipient rec : message.getRecipients()) { if (rec.getType() == Recipient.TYPE_EMAIL) continue; UserHistory history = new UserHistory(); history.setTenantId(message.getTenantId()); history.setComment(message.getMessageText()); history.setEvent(UserEvent.MESSAGE_RECEIVED.toString()); history.setAuthor(message.getAuthor()); history.setNotifyEvent(message.isNotify()); User recipient = uDao.findByUsername(rec.getName()); if (recipient != null) history.setUser(recipient); User author = uDao.findByUsername(message.getAuthor()); if (author != null) history.setAuthor(author.getFullName()); hDao.store(history); } } return stored; } HibernateSystemMessageDAO(); @Override List<SystemMessage> findByRecipient(String recipient, int type, Integer read); @Override int getUnreadCount(String recipient, int type); void deleteExpiredMessages(String recipient); void deleteExpiredMessages(int type); @Override List<SystemMessage> findByMode(String mode); @Override List<SystemMessage> findByType(int type); @Override void initialize(SystemMessage message); @Override List<SystemMessage> findMessagesToBeSent(int type, int maxTrial); @Override boolean store(SystemMessage message);  }### Answer:
@Test public void testStore() throws PersistenceException { Set<Recipient> recipients = new HashSet<Recipient>(); Recipient recipient = new Recipient(); recipient.setName("pippo"); recipient.setAddress("pippo"); recipient.setType(Recipient.TYPE_SYSTEM); recipient.setMode("test1"); recipients.add(recipient); recipient = new Recipient(); recipient.setName("paperino"); recipient.setAddress("paperino"); recipient.setType(Recipient.TYPE_EMAIL); recipient.setMode("test2"); recipients.add(recipient); SystemMessage message = new SystemMessage(); message.setAuthor("admin"); message.setMessageText("text"); message.setLastNotified(new Date()); message.setType(SystemMessage.TYPE_SYSTEM); message.setStatus(SystemMessage.STATUS_NEW); message.setRecipients(recipients); Assert.assertTrue(dao.store(message)); message = dao.findById(message.getId()); Assert.assertNotNull(message); Assert.assertEquals(2, message.getRecipients().size()); message = dao.findById(1); Assert.assertNotNull(message); Assert.assertEquals("message text1", message.getMessageText()); message.setMessageText("xxxx"); message.setRecipients(recipients); dao.store(message); message = dao.findById(1); Assert.assertNotNull(message); Assert.assertEquals("xxxx", message.getMessageText()); Assert.assertEquals(2, message.getRecipients().size()); }