### Question:
FermaFlowPathRepository extends FermaGenericRepository<FlowPath, FlowPathData, FlowPathFrame> implements FlowPathRepository { @Override public Collection<FlowPath> findBySrcSwitch(SwitchId switchId, boolean includeProtected) { List<FlowPath> result = new ArrayList<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.add(new FlowPath(frame))); if (includeProtected) { return result; } else { return result.stream() .filter(path -> !(path.isProtected() && switchId.equals(path.getSrcSwitchId()))) .collect(Collectors.toList()); } } FermaFlowPathRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<FlowPath> findAll(); @Override Optional<FlowPath> findById(PathId pathId); @Override Optional<FlowPath> findByFlowIdAndCookie(String flowId, FlowSegmentCookie cookie); @Override Collection<FlowPath> findByFlowId(String flowId); @Override Collection<FlowPath> findByFlowGroupId(String flowGroupId); @Override Collection<PathId> findPathIdsByFlowGroupId(String flowGroupId); @Override Collection<FlowPath> findActualByFlowIds(Set<String> flowIds); @Override Collection<FlowPath> findBySrcSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findByEndpointSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findInactiveBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentSwitchWithMultiTable(SwitchId switchId, boolean multiTable); @Override Collection<FlowPath> findWithPathSegment(SwitchId srcSwitchId, int srcPort,
                                                    SwitchId dstSwitchId, int dstPort); @Override Collection<FlowPath> findBySegmentDestSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentEndpoint(SwitchId switchId, int port); @Override void updateStatus(PathId pathId, FlowPathStatus pathStatus); @Override long getUsedBandwidthBetweenEndpoints(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort); @Override Optional<FlowPath> remove(PathId pathId);  }### Answer:
@Test public void shouldFindProtectedPathsBySrcSwitchIncludeProtected() { createTestFlowPathPair(); flow.setProtectedForwardPath(createFlowPath(flow, "_forward_protected", 10, 10, switchA, switchB)); flow.setProtectedReversePath(createFlowPath(flow, "_reverse_protected", 11, 11, switchB, switchA)); assertThat(flowPathRepository.findBySrcSwitch(switchA.getSwitchId(), true), containsInAnyOrder(flow.getForwardPath(), flow.getProtectedForwardPath())); assertThat(flowPathRepository.findBySrcSwitch(switchB.getSwitchId(), true), containsInAnyOrder(flow.getReversePath(), flow.getProtectedReversePath())); }
@Test public void shouldFindBySrcSwitch() { createTestFlowPathPair(); Collection<FlowPath> paths = flowPathRepository.findBySrcSwitch(switchA.getSwitchId()); assertThat(paths, containsInAnyOrder(flow.getForwardPath())); }
@Test public void shouldFindPathBySrc() { createTestFlowPath(); Collection<FlowPath> foundPaths = flowPathRepository.findBySrcSwitch(switchA.getSwitchId()); assertThat(foundPaths, hasSize(1)); }
@Test public void shouldNotFindPathByWrongSrc() { createTestFlowPath(); Collection<FlowPath> foundPaths = flowPathRepository.findBySrcSwitch(switchB.getSwitchId()); assertThat(foundPaths, Matchers.empty()); }