17
17
package org .hibernate .validator .test .internal .engine .constraintvalidation ;
18
18
19
19
import java .lang .annotation .Documented ;
20
- import java .lang .annotation .Inherited ;
21
20
import java .lang .annotation .Retention ;
22
21
import java .lang .annotation .RetentionPolicy ;
23
22
import java .lang .annotation .Target ;
@@ -77,7 +76,7 @@ public void validatorForParametrizedTypeIsCorrectlyResolved() {
77
76
Validator validator = configuration .buildValidatorFactory ().getValidator ();
78
77
79
78
//when
80
- Set <ConstraintViolation <IntegerValue >> constraintViolations = validator .validate ( new IntegerValue () );
79
+ Set <ConstraintViolation <Value < Integer >>> constraintViolations = validator .validate ( new Value < Integer > () );
81
80
82
81
//then
83
82
assertNumberOfViolations ( constraintViolations , 1 );
@@ -94,14 +93,25 @@ public void validatorForRawTypeIsCorrectlyResolved() {
94
93
Validator validator = configuration .buildValidatorFactory ().getValidator ();
95
94
96
95
//when
97
- Set <ConstraintViolation <IntegerValue >> constraintViolations = validator .validate ( new IntegerValue () );
96
+ Set <ConstraintViolation <Value < Integer >>> constraintViolations = validator .validate ( new Value < Integer > () );
98
97
99
98
//then
100
99
assertNumberOfViolations ( constraintViolations , 1 );
101
100
}
102
101
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
+ */
103
112
@ Test
104
113
@ TestForIssue (jiraKey = "HV-623" )
114
+
105
115
public void parametrizedValidatorHasPrecedenceOverRawValidator () {
106
116
107
117
//given
@@ -115,7 +125,7 @@ public void parametrizedValidatorHasPrecedenceOverRawValidator() {
115
125
Validator validator = configuration .buildValidatorFactory ().getValidator ();
116
126
117
127
//when
118
- Set <ConstraintViolation <IntegerValue >> constraintViolations = validator .validate ( new IntegerValue () );
128
+ Set <ConstraintViolation <Value < Integer >>> constraintViolations = validator .validate ( new Value < Integer > () );
119
129
120
130
//then
121
131
assertNumberOfViolations ( constraintViolations , 1 );
@@ -125,17 +135,13 @@ public void parametrizedValidatorHasPrecedenceOverRawValidator() {
125
135
);
126
136
}
127
137
128
- public abstract class Value <T > {
129
- }
130
-
131
- public class IntegerValue extends Value <Integer > {
138
+ public class Value <T > {
132
139
}
133
140
134
141
@ Target ({ TYPE , ANNOTATION_TYPE })
135
142
@ Retention (RetentionPolicy .RUNTIME )
136
143
@ Constraint (validatedBy = ParametrizedValidator .class )
137
144
@ Documented
138
- @ Inherited
139
145
public @interface ConstraintWithParametrizedValidator {
140
146
String message () default "foo" ;
141
147
0 commit comments