AbstractLuceneMetaAlertUpdateDao implements MetaAlertUpdateDao { @Override public Document addAlertsToMetaAlert(String metaAlertGuid, List<GetRequest> alertRequests) throws IOException { Document metaAlert = retrieveLatestDao .getLatest(metaAlertGuid, MetaAlertConstants.METAALERT_TYPE); if (metaAlert == null) { throw new IOException(String.format("Unable to add alerts to meta alert. Meta alert with guid %s cannot be found.", metaAlertGuid)); } if (MetaAlertStatus.ACTIVE.getStatusString() .equals(metaAlert.getDocument().get(MetaAlertConstants.STATUS_FIELD))) { Iterable<Document> alerts = retrieveLatestDao.getAllLatest(alertRequests); Set<String> missingAlerts = getMissingAlerts(alertRequests, alerts); if (!missingAlerts.isEmpty()) { throw new IOException(String.format("Unable to add alerts to meta alert. Alert with guid %s cannot be found.", missingAlerts.iterator().next())); } Map<Document, Optional<String>> updates = buildAddAlertToMetaAlertUpdates(metaAlert, alerts); update(updates); return metaAlert; } else { throw new IllegalStateException("Adding alerts to an INACTIVE meta alert is not allowed"); } } protected  AbstractLuceneMetaAlertUpdateDao(
      UpdateDao updateDao,
      MetaAlertRetrieveLatestDao retrieveLatestDao,
      MetaAlertConfig config); UpdateDao getUpdateDao(); MetaAlertRetrieveLatestDao getRetrieveLatestDao(); MetaAlertConfig getConfig(); @Override Document patch(RetrieveLatestDao retrieveLatestDao, PatchRequest request,
      Optional<Long> timestamp); @Override Map<Document, Optional<String>> batchUpdate(Map<Document, Optional<String>> updates); @Override Document addAlertsToMetaAlert(String metaAlertGuid, List<GetRequest> alertRequests); @Override @SuppressWarnings("unchecked") Document removeAlertsFromMetaAlert(String metaAlertGuid, List<GetRequest> alertRequests); @Override Document updateMetaAlertStatus(String metaAlertGuid, MetaAlertStatus status);  }
@Test public void addAlertsToMetaAlertShouldThrowExceptionOnMissingMetaAlert() { IOException e = assertThrows(IOException.class, () -> dao.addAlertsToMetaAlert("some_guid", new ArrayList<>())); assertEquals("Unable to add alerts to meta alert. Meta alert with guid some_guid cannot be found.", e.getMessage()); }