### Question:
LogValidator implements AnnotationUsageValidator<T> { @Override public void validate(Method method, T target) throws AnnotationUsageException { LogLevel expectedLevel = AnnotationAttribute.LEVEL.extract(target); LogLevel ifEnabledLevel = AnnotationAttribute.IF_ENABLED.extract(target); if (ifEnabledLevel.ordinal() >= expectedLevel.ordinal() && ifEnabledLevel != OFF) { throw new AnnotationUsageException(method, format("'ifEnabled = %s' should be more strict than 'level = %s'", ifEnabledLevel, expectedLevel), "Correct specified levels relation or replace 'ifEnabled' by default value 'OFF'", target); } String printerName = AnnotationAttribute.PRINTER.extract(target); if (StringUtils.hasText(printerName)) { Printer printer = printerResolver.resolve(printerName); if (isNull(printer)) { throw new AnnotationUsageException(method, format("Unknown printer '%s'", printerName), "Use correct bean name or alias to specify 'printer'", target); } } } LogValidator(PrinterResolver printerResolver); @Override void validate(Method method, T target);  }### Answer:
@Test(expected = AnnotationUsageException.class) public void validateLevels() { PrinterResolver printerResolver = new AliasedPrinterResolver(emptyMap(), emptyMap()); LogValidator<Log> logValidator = new LogValidator<>(printerResolver); Log log = AnnotationUtils.synthesizeAnnotation(singletonMap("ifEnabled", DEBUG), Log.class, null); logValidator.validate(method, log); }
@Test(expected = AnnotationUsageException.class) public void validatePrinter() { PrinterResolver printerResolver = new AliasedPrinterResolver(emptyMap(), emptyMap()); LogValidator<Log> logValidator = new LogValidator<>(printerResolver); Log log = AnnotationUtils.synthesizeAnnotation(singletonMap("printer", "unknown"), Log.class, null); logValidator.validate(method, log); }