ReservedDocumentTypeNameValidator { public void validate(Map<String, NewDocumentType> documentDefinitions) { List<String> conflictingNames = documentDefinitions.keySet().stream() .filter(this::isReservedName) .collect(Collectors.toList()); if (!conflictingNames.isEmpty()) { throw new IllegalArgumentException(makeReservedNameMessage(conflictingNames)); } }  void validate(Map<String, NewDocumentType> documentDefinitions); static final List<String> ORDERED_RESERVED_NAMES; static final Set<String> RESERVED_NAMES; }
@Test public void exception_thrown_on_reserved_names() { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("The following document types conflict with reserved keyword names: " + "'and', 'false', 'id', 'not', 'null', 'or', 'true'. " + "Reserved keywords are 'and', 'false', 'id', 'not', 'null', 'or', 'true'"); Map<String, NewDocumentType> orderedDocTypes = new TreeMap<>(asDocTypeMapping(ReservedDocumentTypeNameValidator.ORDERED_RESERVED_NAMES)); ReservedDocumentTypeNameValidator validator = new ReservedDocumentTypeNameValidator(); validator.validate(orderedDocTypes); }
@Test public void exception_is_not_thrown_on_unreserved_name() { ReservedDocumentTypeNameValidator validator = new ReservedDocumentTypeNameValidator(); validator.validate(asDocTypeMapping(Collections.singletonList("foo"))); }
@Test public void validation_is_case_insensitive() { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("The following document types conflict with reserved keyword names: " + "'NULL', 'True', 'anD'."); ReservedDocumentTypeNameValidator validator = new ReservedDocumentTypeNameValidator(); Map<String, NewDocumentType> orderedDocTypes = new TreeMap<>(asDocTypeMapping(Arrays.asList("NULL", "True", "anD"))); validator.validate(orderedDocTypes); }