MessageUtil { public static Message emitResourceLimitReachedMessage(StateManager stateManager, RunState runState, List<String> depletedResources) { if (depletedResources.isEmpty()) { throw new IllegalArgumentException(); } final List<String> depletedResourcesOrdered = depletedResources.stream().sorted().collect(toList()); final Message message = Message.info("Resource limit reached for: " + depletedResourcesOrdered); if (!runState.data().message().map(message::equals).orElse(false)) { stateManager.receiveIgnoreClosed(Event.info(runState.workflowInstance(), message), runState.counter()); } return message; } private  MessageUtil(); static Message emitResourceLimitReachedMessage(StateManager stateManager, RunState runState,
                                                        List<String> depletedResources);  }
@Test public void shouldNotEmitResourceLimitReachedMessage() { MessageUtil.emitResourceLimitReachedMessage(stateManager, RUNSTATE_WITH_MESSAGE, DEPLETED_RESOURCES); verifyZeroInteractions(stateManager); }
@Test public void shouldEmitResourceLimitReachedMessage() { MessageUtil.emitResourceLimitReachedMessage(stateManager, RUNSTATE_WITH_STALE_MESSAGE, DEPLETED_RESOURCES); verify(stateManager).receiveIgnoreClosed(INFO, RUNSTATE_WITH_MESSAGE.counter()); }
@Test(expected = IllegalArgumentException.class) public void shouldFailIfNoResources() { MessageUtil.emitResourceLimitReachedMessage(stateManager, RUNSTATE_WITH_STALE_MESSAGE, Collections.emptyList()); }