diff --git a/src/main/java/org/junit/validator/ValidateWith.java b/src/main/java/org/junit/validator/ValidateWith.java index 03d790670f75..3725db81f954 100644 --- a/src/main/java/org/junit/validator/ValidateWith.java +++ b/src/main/java/org/junit/validator/ValidateWith.java @@ -1,8 +1,10 @@ package org.junit.validator; +import java.lang.annotation.ElementType; import java.lang.annotation.Inherited; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; /** * Allows for an {@link AnnotationValidator} to be attached to an annotation. @@ -13,6 +15,7 @@ * @since 4.12 */ @Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.ANNOTATION_TYPE) @Inherited public @interface ValidateWith { Class value(); diff --git a/src/test/java/org/junit/validator/AnnotationValidatorFactoryTest.java b/src/test/java/org/junit/validator/AnnotationValidatorFactoryTest.java index 4003ff347280..6e8135d97406 100644 --- a/src/test/java/org/junit/validator/AnnotationValidatorFactoryTest.java +++ b/src/test/java/org/junit/validator/AnnotationValidatorFactoryTest.java @@ -14,13 +14,13 @@ public class AnnotationValidatorFactoryTest { @Test public void createAnnotationValidator() { - ValidateWith validateWith = SampleTestWithValidator.class.getAnnotation(ValidateWith.class); + ValidateWith validateWith = SampleAnnotationWithValidator.class.getAnnotation(ValidateWith.class); AnnotationValidator annotationValidator = new AnnotationValidatorFactory().createAnnotationValidator(validateWith); assertThat(annotationValidator, is(instanceOf(Validator.class))); } @ValidateWith(value = Validator.class) - public static class SampleTestWithValidator { + public @interface SampleAnnotationWithValidator { } public static class Validator extends AnnotationValidator { @@ -28,7 +28,7 @@ public static class Validator extends AnnotationValidator { @Test public void exceptionWhenAnnotationValidatorCantBeCreated() { - ValidateWith validateWith = SampleTestWithValidatorThatThrowsException.class.getAnnotation(ValidateWith.class); + ValidateWith validateWith = SampleAnnotationWithValidatorThatThrowsException.class.getAnnotation(ValidateWith.class); exception.expect(RuntimeException.class); exception.expectMessage("Exception received when creating AnnotationValidator class " + "org.junit.validator.AnnotationValidatorFactoryTest$ValidatorThatThrowsException"); @@ -36,7 +36,7 @@ public void exceptionWhenAnnotationValidatorCantBeCreated() { } @ValidateWith(value = ValidatorThatThrowsException.class) - public static class SampleTestWithValidatorThatThrowsException { + public @interface SampleAnnotationWithValidatorThatThrowsException { } public static class ValidatorThatThrowsException extends AnnotationValidator {