MessageHelper { public static List<MessageActionType> allowedActions(final Message message) { Assert.notNull(message, "the message must not be null."); return ACTION_TYPES.keySet().stream() .filter(key -> ACTION_TYPES.get(key).contains(message.getState())) .collect(Collectors.toList()); } private  MessageHelper(); static void updateBusinessErrors(Message msg, Map<String, Object> properties); static List<MessageActionType> allowedActions(final Message message); static final Set<MsgStateEnum> RESTART_STATES; static final Set<MsgStateEnum> CANCEL_STATES; }
@Test public void test_allowedActions() { assertThat(allowedActions(createMessage(MsgStateEnum.NEW)), hasSize(1)); assertThat(allowedActions(createMessage(MsgStateEnum.NEW)).contains(MessageActionType.CANCEL), is(Boolean.TRUE)); assertThat(allowedActions(createMessage(MsgStateEnum.OK)), hasSize(1)); assertThat(allowedActions(createMessage(MsgStateEnum.OK)).contains(MessageActionType.RESTART), is(Boolean.TRUE)); assertThat(allowedActions(createMessage(MsgStateEnum.IN_QUEUE)), hasSize(1)); assertThat(allowedActions(createMessage(MsgStateEnum.IN_QUEUE)).contains(MessageActionType.CANCEL), is(Boolean.TRUE)); assertThat(allowedActions(createMessage(MsgStateEnum.PROCESSING)), hasSize(1)); assertThat(allowedActions(createMessage(MsgStateEnum.PROCESSING)).contains(MessageActionType.CANCEL), is(Boolean.TRUE)); assertThat(allowedActions(createMessage(MsgStateEnum.PARTLY_FAILED)), hasSize(1)); assertThat(allowedActions(createMessage(MsgStateEnum.FAILED)), hasSize(1)); assertThat(allowedActions(createMessage(MsgStateEnum.FAILED)).contains(MessageActionType.RESTART), is(Boolean.TRUE)); assertThat(allowedActions(createMessage(MsgStateEnum.WAITING)), hasSize(1)); assertThat(allowedActions(createMessage(MsgStateEnum.WAITING)).contains(MessageActionType.CANCEL), is(Boolean.TRUE)); assertThat(allowedActions(createMessage(MsgStateEnum.WAITING_FOR_RES)), hasSize(1)); assertThat(allowedActions(createMessage(MsgStateEnum.WAITING_FOR_RES)).contains(MessageActionType.CANCEL), is(Boolean.TRUE)); assertThat(allowedActions(createMessage(MsgStateEnum.POSTPONED)), hasSize(1)); assertThat(allowedActions(createMessage(MsgStateEnum.POSTPONED)).contains(MessageActionType.CANCEL), is(Boolean.TRUE)); assertThat(allowedActions(createMessage(MsgStateEnum.CANCEL)), hasSize(1)); assertThat(allowedActions(createMessage(MsgStateEnum.CANCEL)).contains(MessageActionType.RESTART), is(Boolean.TRUE)); }