Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@Target(ANNOTATION_TYPE) for @ValidateWith, fixes #1611 #1612

Merged
merged 3 commits into from
Oct 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/main/java/org/junit/validator/ValidateWith.java
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -13,6 +15,7 @@
* @since 4.12
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.ANNOTATION_TYPE)
@Inherited
public @interface ValidateWith {
Class<? extends AnnotationValidator> value();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,29 @@ 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 {
}

@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");
new AnnotationValidatorFactory().createAnnotationValidator(validateWith);
}

@ValidateWith(value = ValidatorThatThrowsException.class)
public static class SampleTestWithValidatorThatThrowsException {
public @interface SampleAnnotationWithValidatorThatThrowsException {
}

public static class ValidatorThatThrowsException extends AnnotationValidator {
Expand Down