### Question:
FermaSwitchRepository extends FermaGenericRepository<Switch, SwitchData, SwitchFrame> implements SwitchRepository { @Override public Collection<Switch> findSwitchesInFlowPathByFlowId(String flowId) { List<? extends FlowPathFrame> flowPathFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.FLOW_ID_PROPERTY, flowId)) .toListExplicit(FlowPathFrame.class); if (flowPathFrames.isEmpty()) { return emptyList(); } Map<SwitchId, Switch> result = new HashMap<>(); flowPathFrames.forEach(flowPath -> { Stream.of(flowPath.getSrcSwitch(), flowPath.getDestSwitch()) .forEach(sw -> result.put(sw.getSwitchId(), sw)); flowPath.getSegments().forEach(pathSegment -> { Stream.of(pathSegment.getSrcSwitch(), pathSegment.getDestSwitch()) .forEach(sw -> result.put(sw.getSwitchId(), sw)); }); }); return result.values(); } FermaSwitchRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<Switch> findAll(); @Override boolean exists(SwitchId switchId); @Override Collection<Switch> findActive(); @Override Optional<Switch> findById(SwitchId switchId); @Override Collection<Switch> findSwitchesInFlowPathByFlowId(String flowId); @Override @TransactionRequired boolean removeIfNoDependant(Switch entity);  }### Answer:
@Test public void shouldFindSwitchesByFlowId() { createTwoFlows(); Collection<SwitchId> switches = switchRepository.findSwitchesInFlowPathByFlowId(TEST_FLOW_ID_A).stream() .map(Switch::getSwitchId) .collect(Collectors.toList()); assertEquals(2, switches.size()); assertTrue(switches.contains(TEST_SWITCH_ID_A)); assertTrue(switches.contains(TEST_SWITCH_ID_B)); assertFalse(switches.contains(TEST_SWITCH_ID_C)); }
@Test public void shouldFindSwitchOfOneSwitchFlowByFlowId() { createOneSwitchFlow(); Collection<SwitchId> switches = switchRepository.findSwitchesInFlowPathByFlowId(TEST_FLOW_ID_A).stream() .map(Switch::getSwitchId) .collect(Collectors.toList()); assertEquals(1, switches.size()); assertTrue(switches.contains(TEST_SWITCH_ID_A)); }