### Question:
HooksPhaseBuilder { public List<HookPhase> buildHookPhases(List<HookPhase> hookPhases, ProcessContext context) { return hookPhases.stream() .map(hookPhase -> buildPhase(hookPhase, context)) .map(HookPhase::fromString) .collect(Collectors.toList()); } @Inject  HooksPhaseBuilder(ProcessTypeParser processTypeParser); List<HookPhase> buildHookPhases(List<HookPhase> hookPhases, ProcessContext context);  }### Answer:
@Test void testBuildHookPhaseForDeployProcess() { Mockito.when(processTypeParser.getProcessType(context.getExecution())) .thenReturn(ProcessType.DEPLOY); HooksPhaseBuilder hooksPhaseBuilder = new HooksPhaseBuilder(processTypeParser); List<HookPhase> hookPhases = hooksPhaseBuilder.buildHookPhases(List.of(HookPhase.BEFORE_STOP), context); Assertions.assertEquals(List.of(HookPhase.DEPLOY_APPLICATION_BEFORE_STOP), hookPhases); }
@Test void testBuildHookPhaseForBlueGreenDeployProcessWithSubprocessPhaseBeforeApplicationStop() { Mockito.when(processTypeParser.getProcessType(context.getExecution())) .thenReturn(ProcessType.BLUE_GREEN_DEPLOY); context.setVariable(Variables.SUBPROCESS_PHASE, SubprocessPhase.BEFORE_APPLICATION_STOP); HooksPhaseBuilder hooksPhaseBuilder = new HooksPhaseBuilder(processTypeParser); List<HookPhase> hookPhases = hooksPhaseBuilder.buildHookPhases(List.of(HookPhase.BEFORE_STOP), context); Assertions.assertEquals(List.of(HookPhase.BLUE_GREEN_APPLICATION_BEFORE_STOP_IDLE), hookPhases); }
@Test void testBuildHookPhaseForBlueGreenDeployProcessWithSubprocessPhaseBeforeApplicationStart() { Mockito.when(processTypeParser.getProcessType(context.getExecution())) .thenReturn(ProcessType.BLUE_GREEN_DEPLOY); context.setVariable(Variables.SUBPROCESS_PHASE, SubprocessPhase.BEFORE_APPLICATION_START); HooksPhaseBuilder hooksPhaseBuilder = new HooksPhaseBuilder(processTypeParser); List<HookPhase> hookPhases = hooksPhaseBuilder.buildHookPhases(List.of(HookPhase.BEFORE_START), context); Assertions.assertEquals(List.of(HookPhase.BLUE_GREEN_APPLICATION_BEFORE_START_IDLE), hookPhases); }
@Test void testBuildHookPhaseForBlueGreenProcessWithPhaseUndeploy() { Mockito.when(processTypeParser.getProcessType(context.getExecution())) .thenReturn(ProcessType.BLUE_GREEN_DEPLOY); context.setVariable(Variables.PHASE, Phase.UNDEPLOY); HooksPhaseBuilder hooksPhaseBuilder = new HooksPhaseBuilder(processTypeParser); List<HookPhase> hookPhases = hooksPhaseBuilder.buildHookPhases(List.of(HookPhase.AFTER_STOP), context); Assertions.assertEquals(List.of(HookPhase.BLUE_GREEN_APPLICATION_AFTER_STOP_LIVE), hookPhases); }
@Test void testBuildHookPhaseForBlueGreenProcessWithPhaseAfterResume() { Mockito.when(processTypeParser.getProcessType(context.getExecution())) .thenReturn(ProcessType.BLUE_GREEN_DEPLOY); context.setVariable(Variables.PHASE, Phase.AFTER_RESUME); HooksPhaseBuilder hooksPhaseBuilder = new HooksPhaseBuilder(processTypeParser); List<HookPhase> hookPhases = hooksPhaseBuilder.buildHookPhases(List.of(HookPhase.BEFORE_START), context); Assertions.assertEquals(List.of(HookPhase.BLUE_GREEN_APPLICATION_BEFORE_START_LIVE), hookPhases); }