File tree Expand file tree Collapse file tree 4 files changed +46
-2
lines changed
main/java/io/github/sashirestela/slimvalidator/metadata
test/java/io/github/sashirestela/slimvalidator Expand file tree Collapse file tree 4 files changed +46
-2
lines changed Original file line number Diff line number Diff line change 6
6
7
7
<groupId >io.github.sashirestela</groupId >
8
8
<artifactId >slimvalidator</artifactId >
9
- <version >1.2.0 </version >
9
+ <version >1.2.1 </version >
10
10
<packaging >jar</packaging >
11
11
12
12
<name >slimvalidator</name >
Original file line number Diff line number Diff line change @@ -27,7 +27,7 @@ public static class FieldMetadata {
27
27
public Object getValue (Object object ) {
28
28
var clazz = object .getClass ();
29
29
try {
30
- var method = clazz .getDeclaredMethod (getMethodName (name ), (Class <?>[]) null );
30
+ var method = clazz .getMethod (getMethodName (name ), (Class <?>[]) null );
31
31
return method .invoke (object );
32
32
} catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException
33
33
| InvocationTargetException e ) {
Original file line number Diff line number Diff line change 1
1
package io .github .sashirestela .slimvalidator ;
2
2
3
+ import io .github .sashirestela .slimvalidator .data .AbstractClass .ChildClass ;
3
4
import io .github .sashirestela .slimvalidator .data .Address ;
4
5
import io .github .sashirestela .slimvalidator .data .Address .Coordinate ;
5
6
import io .github .sashirestela .slimvalidator .data .Person ;
@@ -75,4 +76,20 @@ void shouldReturnViolationsWhenObjectDoesNotAccomplishConstraints() {
75
76
assertEquals (expectedViolationMessage , actualViolationsMessage );
76
77
}
77
78
79
+ @ Test
80
+ void shouldExecuteValidationWhenThereIsClassHierarchy () {
81
+
82
+ var childObject = ChildClass .builder ()
83
+ .name ("name" )
84
+ .level (12 )
85
+ .category ("category" )
86
+ .build ();
87
+ var validator = new Validator ();
88
+ var violations = validator .validate (childObject );
89
+ var exception = new ConstraintViolationException (violations );
90
+ var actualViolationsMessage = exception .getMessage ();
91
+ var expectedViolationMessage = "level must be at least 1 at most 10." ;
92
+ assertEquals (expectedViolationMessage , actualViolationsMessage );
93
+ }
94
+
78
95
}
Original file line number Diff line number Diff line change
1
+ package io .github .sashirestela .slimvalidator .data ;
2
+
3
+ import io .github .sashirestela .slimvalidator .constraints .Range ;
4
+ import io .github .sashirestela .slimvalidator .constraints .Required ;
5
+ import lombok .Getter ;
6
+ import lombok .experimental .SuperBuilder ;
7
+
8
+ @ Getter
9
+ @ SuperBuilder
10
+ public abstract class AbstractClass {
11
+
12
+ @ Required
13
+ protected String name ;
14
+
15
+ @ Range (min = 1 , max = 10 )
16
+ protected Integer level ;
17
+
18
+ @ Getter
19
+ @ SuperBuilder
20
+ public static class ChildClass extends AbstractClass {
21
+
22
+ @ Required
23
+ private String category ;
24
+
25
+ }
26
+
27
+ }
You can’t perform that action at this time.
0 commit comments