ActionInterceptorsSorter { public ActionInterceptors sortInterceptors(List<InterceptionProcessContext> allInterceptors) { Map<ActionExecutionStage, List<InterceptionProcessContext>> interceptorsMap = new HashMap<ActionExecutionStage, List<InterceptionProcessContext>>(); for (ActionExecutionStage executionStage : ActionExecutionStage.values()) { List<InterceptionProcessContext> interceptorsForStage = chooseInterceptorsForStage(executionStage, allInterceptors); interceptorsMap.put(executionStage, interceptorsForStage); } return new ActionInterceptors(interceptorsMap); }  ActionInterceptors sortInterceptors(List<InterceptionProcessContext> allInterceptors);  }
@Test public void shouldSortActionInterceptors1() { ActionExecutionStage stage = ActionExecutionStage.ACTION_EXECUTION; ActionInterceptorInformation firstActionInterceptorInformation = mock(ActionInterceptorInformation.class); when(firstActionInterceptorInformation.getInterceptorInstance()).thenReturn(firstActionInterceptor); when(firstActionInterceptorInformation.getStages()).thenReturn(new ActionExecutionStage[]{stage}); InterceptionProcessContext firstActionInterceptorProcessContext = mock(InterceptionProcessContext.class); when(firstActionInterceptorProcessContext.getInterceptorInformation()).thenReturn(firstActionInterceptorInformation); ActionInterceptorInformation secondActionInterceptorInformation = mock(ActionInterceptorInformation.class); when(secondActionInterceptorInformation.getInterceptorInstance()).thenReturn(secondActionInterceptor); when(secondActionInterceptorInformation.getStages()).thenReturn(new ActionExecutionStage[]{stage}); InterceptionProcessContext secondActionInterceptorProcessContext = mock(InterceptionProcessContext.class); when(secondActionInterceptorProcessContext.getInterceptorInformation()).thenReturn(secondActionInterceptorInformation); ActionInterceptorInformation otherActionInterceptorInformation = mock(ActionInterceptorInformation.class); when(otherActionInterceptorInformation.getInterceptorInstance()).thenReturn(otherActionInterceptor); when(otherActionInterceptorInformation.getStages()).thenReturn(new ActionExecutionStage[]{stage}); InterceptionProcessContext otherActionInterceptorProcessContext = mock(InterceptionProcessContext.class); when(otherActionInterceptorProcessContext.getInterceptorInformation()).thenReturn(otherActionInterceptorInformation); List<InterceptionProcessContext> allInterceptors = Arrays.asList(secondActionInterceptorProcessContext, firstActionInterceptorProcessContext, otherActionInterceptorProcessContext); ActionInterceptors actionInterceptors = sorter.sortInterceptors(allInterceptors); List<InterceptionProcessContext> processContextList = actionInterceptors.getInterceptorsForStage(stage); assertThat(processContextList) .isNotNull() .hasSize(3) .containsExactly(firstActionInterceptorProcessContext, secondActionInterceptorProcessContext, otherActionInterceptorProcessContext); }