SurveyInstanceStateMachine { public List<SurveyInstanceAction> nextPossibleActions(SurveyInstancePermissions permissions, SurveyInstance instance) { return transitions.getOrDefault(current, emptyList()) .stream() .filter(t -> t.getPredicate().apply(permissions, instance)) .map(t -> t.getAction()) .collect(toList()); } SurveyInstanceStateMachine(SurveyInstanceStatus current, MultiValueMap<SurveyInstanceStatus, SurveyInstanceStateTransition> transitions); SurveyInstanceStatus getCurrent(); List<SurveyInstanceStatus> nextPossibleStatus(SurveyInstancePermissions permissions, SurveyInstance instance); List<SurveyInstanceAction> nextPossibleActions(SurveyInstancePermissions permissions, SurveyInstance instance); SurveyInstanceStatus process(SurveyInstanceAction action, SurveyInstancePermissions permissions, SurveyInstance instance);  }
@Test public void nextPossibleTransitions() { SurveyInstanceStateMachine completed = SurveyInstanceStateMachineFactory.simple("COMPLETED"); assertEquals(2, completed.nextPossibleActions(admin, survey).size()); assertTrue(completed.nextPossibleActions(admin, survey).contains(APPROVING)); assertTrue(completed.nextPossibleActions(admin, survey).contains(REJECTING)); assertEquals(0, completed.nextPossibleActions(participant, survey).size()); }