### Question:
GatewayV4RequestValidator implements Validator<GatewayV4Request> { @Override public ValidationResult validate(GatewayV4Request subject) { ValidationResultBuilder validationResultBuilder = ValidationResult.builder(); if (CollectionUtils.isEmpty(subject.getTopologies())) { return validationResultBuilder.error("No topology is defined in gateway request. Please define a topology in " + "'gateway.topologies'.").build(); } validateTopologyNames(subject, validationResultBuilder); return validationResultBuilder.build(); }  @Override ValidationResult validate(GatewayV4Request subject);  }### Answer:
@Test public void testValidationWithNameDuplicates() { GatewayV4Request gatewayJson = new GatewayV4Request(); GatewayTopologyV4Request topology1 = new GatewayTopologyV4Request(); topology1.setTopologyName("Apple"); GatewayTopologyV4Request topology2 = new GatewayTopologyV4Request(); topology2.setTopologyName("Apple"); GatewayTopologyV4Request topology3 = new GatewayTopologyV4Request(); topology3.setTopologyName("Banana"); gatewayJson.setTopologies(Arrays.asList(topology1, topology2, topology3)); ValidationResult result = underTest.validate(gatewayJson); assertEquals(State.ERROR, result.getState()); assertTrue(result.getFormattedErrors().contains("Apple")); }
@Test public void testValidationWithoutNameDuplicates() { GatewayV4Request gatewayJsonV4Request = new GatewayV4Request(); GatewayTopologyV4Request topology1 = new GatewayTopologyV4Request(); topology1.setTopologyName("Apple"); GatewayTopologyV4Request topology2 = new GatewayTopologyV4Request(); topology2.setTopologyName("Banana"); GatewayTopologyV4Request topology3 = new GatewayTopologyV4Request(); topology3.setTopologyName("Citrone"); gatewayJsonV4Request.setTopologies(Arrays.asList(topology1, topology2, topology3)); ValidationResult result = underTest.validate(gatewayJsonV4Request); assertEquals(State.VALID, result.getState()); }
@Test public void testValidationWithMissingTopology() { GatewayV4Request gatewayJson = new GatewayV4Request(); ValidationResult result = underTest.validate(gatewayJson); assertEquals(State.ERROR, result.getState()); assertTrue(result.getFormattedErrors().contains("No topology is defined in gateway request.")); }