### Question:
MdcsValidator implements AnnotationUsageValidator<Collection<Mdc>> { @Override public void validate(Method method, Collection<Mdc> target) throws AnnotationUsageException { target.stream().collect(groupingBy(Mdc::key)) .entrySet().stream() .filter(entry -> entry.getValue().size() > 1) .findFirst() .ifPresent(entry -> { throw new AnnotationUsageException(method, format("%s annotations with 'key = %s' on the annotated element", entry.getValue().size(), entry.getKey()), "Use unique 'key' per annotated element"); }); }  @Override void validate(Method method, Collection<Mdc> target);  }### Answer:
@Test(expected = AnnotationUsageException.class) public void validateDuplicate() { Mdc mdc = AnnotationUtils.synthesizeAnnotation(singletonMap("key", "key"), Mdc.class, null); Mdc mdc1 = AnnotationUtils.synthesizeAnnotation(singletonMap("key", "key"), Mdc.class, null); Collection<Mdc> target = asList(mdc, mdc1); mdcsValidator.validate(method, target); }
@Test(expected = AnnotationUsageException.class) public void validateEmptyDuplicate() { Mdc mdc = AnnotationUtils.synthesizeAnnotation(singletonMap("key", ""), Mdc.class, null); Mdc mdc1 = AnnotationUtils.synthesizeAnnotation(singletonMap("key", ""), Mdc.class, null); Collection<Mdc> target = asList(mdc, mdc1); mdcsValidator.validate(method, target); }