### Question:
FlowValidator { @VisibleForTesting void checkForEqualsEndpoints(RequestedFlow firstFlow, RequestedFlow secondFlow) throws InvalidFlowException { String message = "New requested endpoint for '%s' conflicts with existing endpoint for '%s'"; Set<FlowEndpoint> firstFlowEndpoints = validateFlowEqualsEndpoints(firstFlow, message); Set<FlowEndpoint> secondFlowEndpoints = validateFlowEqualsEndpoints(secondFlow, message); for (FlowEndpoint endpoint : secondFlowEndpoints) { if (firstFlowEndpoints.contains(endpoint)) { message = String.format(message, secondFlow.getFlowId(), firstFlow.getFlowId()); throw new InvalidFlowException(message, ErrorType.DATA_INVALID); } } } FlowValidator(FlowRepository flowRepository, SwitchRepository switchRepository,
                         IslRepository islRepository, SwitchPropertiesRepository switchPropertiesRepository); void validate(RequestedFlow flow); void validate(RequestedFlow flow, Set<String> bulkUpdateFlowIds); void validateForSwapEndpoints(RequestedFlow firstFlow, RequestedFlow secondFlow);  }### Answer:
@Test(expected = InvalidFlowException.class) public void shouldFailOnSwapWhenEqualsEndpointsOnFirstFlow() throws InvalidFlowException { RequestedFlow firstFlow = RequestedFlow.builder() .flowId("firstFlow") .srcSwitch(SWITCH_ID_1) .srcPort(10) .srcVlan(11) .destSwitch(SWITCH_ID_2) .destPort(10) .destVlan(11) .build(); RequestedFlow secondFlow = RequestedFlow.builder() .flowId("secondFlow") .srcSwitch(SWITCH_ID_2) .destSwitch(SWITCH_ID_2) .build(); flowValidator.checkForEqualsEndpoints(firstFlow, secondFlow); }
@Test(expected = InvalidFlowException.class) public void shouldFailOnSwapWhenEqualsEndpointsOnSecondFlow() throws InvalidFlowException { RequestedFlow firstFlow = RequestedFlow.builder() .flowId("firstFlow") .srcSwitch(SWITCH_ID_2) .srcPort(10) .srcVlan(11) .destSwitch(SWITCH_ID_2) .destPort(12) .build(); RequestedFlow secondFlow = RequestedFlow.builder() .flowId("secondFlow") .srcSwitch(SWITCH_ID_1) .srcPort(10) .srcVlan(11) .destSwitch(SWITCH_ID_1) .destPort(10) .destVlan(11) .build(); flowValidator.checkForEqualsEndpoints(firstFlow, secondFlow); }
@Test(expected = InvalidFlowException.class) public void shouldFailOnSwapWhenEqualsEndpointsOnFirstAndSecondFlow() throws InvalidFlowException { RequestedFlow firstFlow = RequestedFlow.builder() .flowId("firstFlow") .srcSwitch(SWITCH_ID_1) .srcPort(10) .srcVlan(11) .destSwitch(SWITCH_ID_2) .destPort(12) .destVlan(13) .build(); RequestedFlow secondFlow = RequestedFlow.builder() .flowId("secondFlow") .srcSwitch(SWITCH_ID_1) .srcPort(10) .srcVlan(11) .destSwitch(SWITCH_ID_2) .destPort(12) .destVlan(13) .build(); flowValidator.checkForEqualsEndpoints(firstFlow, secondFlow); }
@Test public void shouldNotFailOnSwapWhenDifferentEndpointsOnFirstAndSecondFlow() throws InvalidFlowException { RequestedFlow firstFlow = RequestedFlow.builder() .flowId("firstFlow") .srcSwitch(SWITCH_ID_1) .srcPort(10) .srcVlan(11) .destSwitch(SWITCH_ID_2) .destPort(12) .destVlan(13) .build(); RequestedFlow secondFlow = RequestedFlow.builder() .flowId("secondFlow") .srcSwitch(SWITCH_ID_1) .srcPort(14) .srcVlan(15) .destSwitch(SWITCH_ID_2) .destPort(16) .destVlan(17) .build(); flowValidator.checkForEqualsEndpoints(firstFlow, secondFlow); }