/** * The argument to this constructor is a List (not a SortedSet) to prevent Jackson from silently * removing duplicate entries. */ @JsonCreator public ReferenceLibrary(@JsonProperty(PROP_BOOKS) List<ReferenceBook> books) { List<ReferenceBook> nnBooks = firstNonNull(books, ImmutableList.of()); checkDuplicates( "book", nnBooks.stream().map(ReferenceBook::getName).collect(Collectors.toList())); _books = nnBooks.stream() .collect(ImmutableSortedSet.toImmutableSortedSet(Comparator.naturalOrder())); }
/** check that we do NOT barf on duplicates */ @Test public void checkDuplicatesNoDups() { checkDuplicates("test", ImmutableList.of("")); checkDuplicates("test", ImmutableList.of("a")); checkDuplicates("test", ImmutableList.of("a", "b", "c")); }
ReferenceLibrary.checkDuplicates("address group", addressGroupNames); ReferenceLibrary.checkDuplicates("filter group", filterGroupNames); ReferenceLibrary.checkDuplicates("interface group", interfaceGroupNames); ReferenceLibrary.checkDuplicates("service endpoint", serviceEndpointNames); ReferenceLibrary.checkDuplicates("service object group", serviceObjectGroupNames); ReferenceLibrary.checkDuplicates("service objects", serviceObjectNames); ReferenceLibrary.checkDuplicates("service object or group", allServiceNames);
/** check that we barf on duplicates */ @Test public void checkDuplicatesDups() { _thrown.expect(IllegalArgumentException.class); _thrown.expectMessage("Duplicate"); checkDuplicates("test", ImmutableList.of("a", "b", "a")); }