### Question:
RerouteService { public void processSingleSwitchFlowStatusUpdate(SwitchStateChanged request) { transactionManager.doInTransaction(() -> { Collection<Flow> affectedFlows = flowRepository.findOneSwitchFlows(request.getSwitchId()); FlowStatus newFlowStatus = request.getStatus() == SwitchStatus.ACTIVE ? FlowStatus.UP : FlowStatus.DOWN; String newFlowStatusInfo = request.getStatus() == SwitchStatus.ACTIVE ? null : format("Switch %s is inactive", request.getSwitchId()); FlowPathStatus newFlowPathStatus = request.getStatus() == SwitchStatus.ACTIVE ? FlowPathStatus.ACTIVE : FlowPathStatus.INACTIVE; for (Flow flow : affectedFlows) { log.info("Updating flow and path statuses for flow {} to {}, {}", flow.getFlowId(), newFlowStatus, newFlowPathStatus); flowDashboardLogger.onFlowStatusUpdate(flow.getFlowId(), newFlowStatus); flow.setStatus(newFlowStatus); flow.setStatusInfo(newFlowStatusInfo); flow.getForwardPath().setStatus(newFlowPathStatus); flow.getReversePath().setStatus(newFlowPathStatus); } }); } RerouteService(PersistenceManager persistenceManager); void rerouteAffectedFlows(MessageSender sender, String correlationId, RerouteAffectedFlows command); void rerouteInactiveAffectedFlows(MessageSender sender, String correlationId,
                                             SwitchId switchId); void rerouteInactiveFlows(MessageSender sender, String correlationId, RerouteInactiveFlows command); Collection<FlowPath> getAffectedFlowPaths(SwitchId switchId, int port); List<FlowPath> getPathsForSwapping(Collection<FlowPath> paths); List<FlowWithAffectedPaths> groupPathsForRerouting(Collection<FlowPath> paths); Set<Flow> groupAffectedPinnedFlows(Collection<FlowPath> paths); Map<Flow, Set<PathId>> getInactiveFlowsForRerouting(); Set<Flow> getAffectedInactiveFlowsForRerouting(SwitchId switchId); void processManualRerouteRequest(MessageSender sender, String correlationId, FlowRerouteRequest request); void processSingleSwitchFlowStatusUpdate(SwitchStateChanged request);  }### Answer:
@Test public void handleUpdateSingleSwitchFlows() { FlowRepository flowRepository = mock(FlowRepository.class); when(flowRepository.findOneSwitchFlows(oneSwitchFlow.getSrcSwitch().getSwitchId())) .thenReturn(Arrays.asList(oneSwitchFlow)); FlowPathRepository flowPathRepository = mock(FlowPathRepository.class); RepositoryFactory repositoryFactory = mock(RepositoryFactory.class); when(repositoryFactory.createFlowRepository()) .thenReturn(flowRepository); when(repositoryFactory.createFlowPathRepository()) .thenReturn(flowPathRepository); PersistenceManager persistenceManager = mock(PersistenceManager.class); when(persistenceManager.getRepositoryFactory()).thenReturn(repositoryFactory); when(persistenceManager.getTransactionManager()).thenReturn(transactionManager); RerouteService rerouteService = new RerouteService(persistenceManager); rerouteService.processSingleSwitchFlowStatusUpdate( new SwitchStateChanged(oneSwitchFlow.getSrcSwitchId(), SwitchStatus.INACTIVE)); assertEquals(format("Switch %s is inactive", oneSwitchFlow.getSrcSwitchId()), FlowStatus.DOWN, oneSwitchFlow.getStatus()); }