@Test public void logsForloadMailStatus() throws Exception { Provider<XWikiContext> xcontextProvider = mocker.registerMockComponent(XWikiContext.TYPE_PROVIDER); XWikiContext xcontext = mock(XWikiContext.class); when(xcontextProvider.get()).thenReturn(xcontext); when(xcontext.getWikiId()).thenReturn("wiki"); when(xcontext.getMainXWiki()).thenReturn("mainwiki"); XWikiHibernateStore hibernateStore = mock(XWikiHibernateStore.class); ReflectionUtils.setFieldValue(this.mocker.getComponentUnderTest(), "hibernateStore", hibernateStore); MailStatus status = new MailStatus(); status.setBatchId("batchid"); status.setMessageId("messageid"); status.setState(MailState.PREPARE_SUCCESS); status.setRecipients("recipients"); when(hibernateStore.executeRead(eq(xcontext), any())).thenReturn(Arrays.asList(status)); Map<String, Object> filterMap = new LinkedHashMap<>(); filterMap.put("status", "failed"); filterMap.put("wiki", "mywiki"); this.mocker.getComponentUnderTest().load(filterMap, 0, 0, null, false); assertEquals(2, this.logRule.size()); assertEquals("Find mail statuses for query [from org.xwiki.mail.MailStatus where mail_status like :status " + "and mail_wiki like :wiki] and parameters [[status] = [failed], [wiki] = [mywiki]]", this.logRule.getMessage(0)); assertEquals("Loaded mail status [messageId = [messageid], batchId = [batchid], state = [prepare_success], " + "date = [<null>], recipients = [recipients]]", this.logRule.getMessage(1)); }
@Override public MailStatus load(String uniqueMessageId) throws MailStoreException { List<MailStatus> statuses = load(Collections.<String, Object>singletonMap(ID_PARAMETER_NAME, uniqueMessageId), 0, 0, null, false); if (statuses.isEmpty()) { return null; } return statuses.get(0); }
DatabaseMailStatusStore implements MailStatusStore { @Override public MailStatus load(String uniqueMessageId) throws MailStoreException { List<MailStatus> statuses = load(Collections.<String, Object>singletonMap(ID_PARAMETER_NAME, uniqueMessageId), 0, 0, null, false); if (statuses.isEmpty()) { return null; } return statuses.get(0); } }
DatabaseMailStatusStore implements MailStatusStore { @Override public MailStatus load(String uniqueMessageId) throws MailStoreException { List<MailStatus> statuses = load(Collections.<String, Object>singletonMap(ID_PARAMETER_NAME, uniqueMessageId), 0, 0, null, false); if (statuses.isEmpty()) { return null; } return statuses.get(0); }  }
DatabaseMailStatusStore implements MailStatusStore { @Override public MailStatus load(String uniqueMessageId) throws MailStoreException { List<MailStatus> statuses = load(Collections.<String, Object>singletonMap(ID_PARAMETER_NAME, uniqueMessageId), 0, 0, null, false); if (statuses.isEmpty()) { return null; } return statuses.get(0); }  @Override void save(final MailStatus status, final Map<String, Object> parameters); @Override MailStatus load(String uniqueMessageId); @Override List<MailStatus> load(final Map<String, Object> filterMap, final int offset, final int count,
        String sortField, boolean sortAscending); @Override long count(final Map<String, Object> filterMap); @Override void delete(final String uniqueMessageId, Map<String, Object> parameters); }
DatabaseMailStatusStore implements MailStatusStore { @Override public MailStatus load(String uniqueMessageId) throws MailStoreException { List<MailStatus> statuses = load(Collections.<String, Object>singletonMap(ID_PARAMETER_NAME, uniqueMessageId), 0, 0, null, false); if (statuses.isEmpty()) { return null; } return statuses.get(0); }  @Override void save(final MailStatus status, final Map<String, Object> parameters); @Override MailStatus load(String uniqueMessageId); @Override List<MailStatus> load(final Map<String, Object> filterMap, final int offset, final int count,
        String sortField, boolean sortAscending); @Override long count(final Map<String, Object> filterMap); @Override void delete(final String uniqueMessageId, Map<String, Object> parameters);  }