AbstractLuceneMetaAlertUpdateDao implements MetaAlertUpdateDao { @Override public Document updateMetaAlertStatus(String metaAlertGuid, MetaAlertStatus status) throws IOException { Document metaAlert = retrieveLatestDao .getLatest(metaAlertGuid, MetaAlertConstants.METAALERT_TYPE); if (metaAlert == null) { throw new IOException(String.format("Unable to update meta alert status. Meta alert with guid %s cannot be found.", metaAlertGuid)); } String currentStatus = (String) metaAlert.getDocument().get(MetaAlertConstants.STATUS_FIELD); boolean metaAlertUpdated = !status.getStatusString().equals(currentStatus); if (metaAlertUpdated) { List<GetRequest> getRequests = new ArrayList<>(); @SuppressWarnings("unchecked") List<Map<String, Object>> currentAlerts = (List<Map<String, Object>>) metaAlert.getDocument() .get(MetaAlertConstants.ALERT_FIELD); currentAlerts.stream() .forEach(currentAlert -> getRequests.add(new GetRequest((String) currentAlert.get(GUID), (String) currentAlert.get(config.getSourceTypeField())))); Iterable<Document> alerts = retrieveLatestDao.getAllLatest(getRequests); Map<Document, Optional<String>> updates = buildStatusChangeUpdates(metaAlert, alerts, status); update(updates); } return metaAlert; } 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 updateMetaAlertStatusShouldThrowExceptionOnMissingMetaAlert() { IOException e = assertThrows(IOException.class, () -> dao.updateMetaAlertStatus("some_guid", MetaAlertStatus.INACTIVE)); assertEquals("Unable to update meta alert status. Meta alert with guid some_guid cannot be found.", e.getMessage()); }