Skip to content

Commit ea50efb

Browse files
committed
HV-623: Simplifying test case a bit
1 parent f3c8d4b commit ea50efb

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

engine/src/test/java/org/hibernate/validator/test/internal/engine/constraintvalidation/ConstraintValidatorResolutionTest.java

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package org.hibernate.validator.test.internal.engine.constraintvalidation;
1818

1919
import java.lang.annotation.Documented;
20-
import java.lang.annotation.Inherited;
2120
import java.lang.annotation.Retention;
2221
import java.lang.annotation.RetentionPolicy;
2322
import java.lang.annotation.Target;
@@ -77,7 +76,7 @@ public void validatorForParametrizedTypeIsCorrectlyResolved() {
7776
Validator validator = configuration.buildValidatorFactory().getValidator();
7877

7978
//when
80-
Set<ConstraintViolation<IntegerValue>> constraintViolations = validator.validate( new IntegerValue() );
79+
Set<ConstraintViolation<Value<Integer>>> constraintViolations = validator.validate( new Value<Integer>() );
8180

8281
//then
8382
assertNumberOfViolations( constraintViolations, 1 );
@@ -94,14 +93,25 @@ public void validatorForRawTypeIsCorrectlyResolved() {
9493
Validator validator = configuration.buildValidatorFactory().getValidator();
9594

9695
//when
97-
Set<ConstraintViolation<IntegerValue>> constraintViolations = validator.validate( new IntegerValue() );
96+
Set<ConstraintViolation<Value<Integer>>> constraintViolations = validator.validate( new Value<Integer>() );
9897

9998
//then
10099
assertNumberOfViolations( constraintViolations, 1 );
101100
}
102101

102+
/**
103+
* As per the JLS, {@code Value<T>} is a sub-type of of the raw type
104+
* {@code Value}. Therefore
105+
* {@link ParametrizedValidatorForConstraintWithRawAndParametrizedValidator}
106+
* is more specific than
107+
* {@link RawValidatorForConstraintWithRawAndParametrizedValidator}.
108+
*
109+
* @see <a href="http://docs.oracle.com/javase/specs/jls/se7/html/jls-4.html#jls-4.10.2">JLS</a> (subtyping)
110+
* @see <a href="http://beanvalidation.org/1.1/spec/#typevalidatorresolution">BV spec</a> (constraint validator resolution)
111+
*/
103112
@Test
104113
@TestForIssue(jiraKey = "HV-623")
114+
105115
public void parametrizedValidatorHasPrecedenceOverRawValidator() {
106116

107117
//given
@@ -115,7 +125,7 @@ public void parametrizedValidatorHasPrecedenceOverRawValidator() {
115125
Validator validator = configuration.buildValidatorFactory().getValidator();
116126

117127
//when
118-
Set<ConstraintViolation<IntegerValue>> constraintViolations = validator.validate( new IntegerValue() );
128+
Set<ConstraintViolation<Value<Integer>>> constraintViolations = validator.validate( new Value<Integer>() );
119129

120130
//then
121131
assertNumberOfViolations( constraintViolations, 1 );
@@ -125,17 +135,13 @@ public void parametrizedValidatorHasPrecedenceOverRawValidator() {
125135
);
126136
}
127137

128-
public abstract class Value<T> {
129-
}
130-
131-
public class IntegerValue extends Value<Integer> {
138+
public class Value<T> {
132139
}
133140

134141
@Target({ TYPE, ANNOTATION_TYPE })
135142
@Retention(RetentionPolicy.RUNTIME)
136143
@Constraint(validatedBy = ParametrizedValidator.class)
137144
@Documented
138-
@Inherited
139145
public @interface ConstraintWithParametrizedValidator {
140146
String message() default "foo";
141147

0 commit comments

Comments
 (0)