ErrorDefinitionValidator { public static void validate(ErrorDefinition definition) { UNIQUE_FIELD_NAMES_VALIDATOR.validate( Stream.concat(definition.getSafeArgs().stream(), definition.getUnsafeArgs().stream()) .map(FieldDefinition::getFieldName) .collect(Collectors.toSet())); } private  ErrorDefinitionValidator(); static void validate(ErrorDefinition definition);  }
@Test public void testUniqueArgNamesValidator() { FieldDefinition safeArg1 = FieldDefinition.builder() .fieldName(FieldName.of("fooBar")) .type(Type.primitive(PrimitiveType.STRING)) .build(); FieldDefinition unsafeArg1 = FieldDefinition.builder() .fieldName(FieldName.of("foo-bar")) .type(Type.primitive(PrimitiveType.STRING)) .build(); ErrorDefinition definition1 = ErrorDefinition.builder() .errorName(TypeName.of("Foo", "package")) .namespace(ErrorNamespace.of("Test")) .code(ErrorCode.INVALID_ARGUMENT) .safeArgs(safeArg1) .unsafeArgs(unsafeArg1) .build(); assertThatThrownBy(() -> ErrorDefinitionValidator.validate(definition1)) .isInstanceOf(IllegalArgumentException.class) .hasMessage("ErrorDefinition must not contain duplicate field names (modulo case normalization): " + "foo-bar vs fooBar"); FieldDefinition safeArg2 = FieldDefinition.builder() .fieldName(FieldName.of("foo-bar")) .type(Type.primitive(PrimitiveType.STRING)) .build(); FieldDefinition unsafeArg2 = FieldDefinition.builder() .fieldName(FieldName.of("foo_bar")) .type(Type.primitive(PrimitiveType.STRING)) .build(); ErrorDefinition definition2 = ErrorDefinition.builder() .errorName(TypeName.of("Foo", "package")) .namespace(ErrorNamespace.of("Test")) .code(ErrorCode.INVALID_ARGUMENT) .safeArgs(safeArg2) .unsafeArgs(unsafeArg2) .build(); assertThatThrownBy(() -> ErrorDefinitionValidator.validate(definition2)) .isInstanceOf(IllegalArgumentException.class) .hasMessage("ErrorDefinition must not contain duplicate field names (modulo case normalization): " + "foo-bar vs foo_bar"); }