DefaultWorldpayOrderModificationNotifierStrategy implements WorldpayOrderModificationNotifierStrategy { @Override public void notifyThatOrdersHaveNotBeenProcessed(int days) { final List<WorldpayOrderModificationModel> unprocessedOrderModifications = getOrderModificationDao().findUnprocessedAndNotNotifiedOrderModificationsBeforeDate(createDateInPast(days)); if (!unprocessedOrderModifications.isEmpty()) { for (final WorldpayOrderModificationModel worldpayOrderModificationModel : unprocessedOrderModifications) { final String worldpayOrderCode = worldpayOrderModificationModel.getWorldpayOrderCode(); final String unprocessedOrderMessage = format("{0} for worldpay order: {1}", getL10nService().getLocalizedString(WORLDPAYNOTIFICATIONS_ERRORS_UNPROCESSED_ORDERS), worldpayOrderCode); getTicketBusinessService().createTicket(createParameters(unprocessedOrderMessage)); worldpayOrderModificationModel.setNotified(true); modelService.save(worldpayOrderModificationModel); LOG.info(unprocessedOrderMessage); } } else { LOG.info("No Unprocessed order were found"); } }  @Override void notifyThatOrdersHaveNotBeenProcessed(int days); TicketBusinessService getTicketBusinessService(); @Required void setTicketBusinessService(TicketBusinessService ticketBusinessService); ModelService getModelService(); @Required void setModelService(ModelService modelService); OrderModificationDao getOrderModificationDao(); @Required void setOrderModificationDao(OrderModificationDao orderModificationDao); L10NService getL10nService(); @Required void setL10nService(L10NService l10nService); @Required void setWorldpayPaymentTransactionService(final WorldpayPaymentTransactionService worldpayPaymentTransactionService); WorldpayPaymentTransactionService getWorldpayPaymentTransactionService();  }
@Test public void whenUnprocessedModificationReturnedThenPublishTicket() { when(orderModificationDaoMock.findUnprocessedAndNotNotifiedOrderModificationsBeforeDate(any(Date.class))).thenReturn(Collections.singletonList(orderModificationModelMock)); when(modelServiceMock.create(CsTicketModel.class)).thenReturn(new CsTicketModel()); testObj.notifyThatOrdersHaveNotBeenProcessed(UNPROCESSED_DAYS); verify(ticketBusinessServiceMock).createTicket(csTicketParameterArgumentCaptor.capture()); verify(orderModificationModelMock).setNotified(true); verify(modelServiceMock).save(orderModificationModelMock); final CsTicketParameter csTicketParameter = csTicketParameterArgumentCaptor.getValue(); assertEquals(THERE_ARE_UNPROCESSED_ORDERS, csTicketParameter.getHeadline()); assertEquals(CsTicketCategory.PROBLEM, csTicketParameter.getCategory()); assertEquals(CsTicketPriority.HIGH, csTicketParameter.getPriority()); assertTrue(csTicketParameter.getCreationNotes().startsWith(UNPROCESSED_ORDERS)); }
@Test public void whenNoUnprocessedModificationsThenDoNotPublishTickets() { when(orderModificationDaoMock.findUnprocessedAndNotNotifiedOrderModificationsBeforeDate(new Date())).thenReturn(Collections.emptyList()); testObj.notifyThatOrdersHaveNotBeenProcessed(5); verify(ticketBusinessServiceMock, never()).createTicket(any(CsTicketParameter.class)); }