File tree Expand file tree Collapse file tree 4 files changed +70
-2
lines changed
main/java/com/github/nylle/javafixture/specimen
test/java/com/github/nylle/javafixture Expand file tree Collapse file tree 4 files changed +70
-2
lines changed Original file line number Diff line number Diff line change 3838 <artifactId >javassist</artifactId >
3939 <version >3.27.0-GA</version >
4040 </dependency >
41+ <dependency >
42+ <groupId >javax.validation</groupId >
43+ <artifactId >validation-api</artifactId >
44+ <version >2.0.1.Final</version >
45+ </dependency >
4146 <dependency >
4247 <groupId >jakarta.validation</groupId >
4348 <artifactId >jakarta.validation-api</artifactId >
44- <version >2.0.2</version >
49+ <version >3.0.1</version >
50+ </dependency >
51+ <dependency >
52+ <groupId >javax.persistence</groupId >
53+ <artifactId >javax.persistence-api</artifactId >
54+ <version >2.2</version >
4555 </dependency >
4656 <dependency >
4757 <groupId >jakarta.persistence</groupId >
4858 <artifactId >jakarta.persistence-api</artifactId >
49- <version >2.2.3 </version >
59+ <version >3.1.0 </version >
5060 </dependency >
5161 <dependency >
5262 <groupId >org.junit.jupiter</groupId >
Original file line number Diff line number Diff line change @@ -89,6 +89,10 @@ private StringConstraints getStringConstraints(Annotation[] annotations) {
8989 constraints = new StringConstraints (((Size )annotation ).min (), ((Size )annotation ).max ());
9090 } else if (Column .class .isAssignableFrom (annotation .annotationType ())) {
9191 constraints = new StringConstraints (0 , ((Column ) annotation ).length ());
92+ } else if (jakarta .validation .constraints .Size .class .isAssignableFrom (annotation .annotationType ())) {
93+ constraints = new StringConstraints (((jakarta .validation .constraints .Size )annotation ).min (), ((jakarta .validation .constraints .Size )annotation ).max ());
94+ } else if (jakarta .persistence .Column .class .isAssignableFrom (annotation .annotationType ())) {
95+ constraints = new StringConstraints (0 , ((jakarta .persistence .Column ) annotation ).length ());
9296 }
9397 }
9498 return constraints ;
Original file line number Diff line number Diff line change 11package com .github .nylle .javafixture ;
22
33import com .github .nylle .javafixture .annotations .fixture .TestWithFixture ;
4+ import com .github .nylle .javafixture .testobjects .TestObjectWithJakartaValidationAnnotations ;
45import com .github .nylle .javafixture .testobjects .TestObjectWithJavaxValidationAnnotations ;
56import org .junit .jupiter .api .Test ;
67
@@ -20,6 +21,16 @@ void javaxSizeAnnotationIsSupported() {
2021 assertThat (sut .getWithColumnLengthAnnotation ().length ()).isBetween (0 , 5 );
2122 }
2223
24+ @ Test
25+ void jakartaSizeAnnotationIsSupported () {
26+ var sut = new Fixture ().create (TestObjectWithJakartaValidationAnnotations .class );
27+
28+ assertThat (sut .getWithMinAnnotation ().length ()).isGreaterThanOrEqualTo (5 );
29+ assertThat (sut .getWithMaxAnnotation ().length ()).isLessThanOrEqualTo (100 );
30+ assertThat (sut .getWithMinMaxAnnotation ().length ()).isBetween (3 , 6 );
31+ assertThat (sut .getWithColumnLengthAnnotation ().length ()).isBetween (0 , 5 );
32+ }
33+
2334 @ Test
2435 void lastOfMultipleAnnotationsWins () {
2536 var sut = new Fixture ().create (TestObjectWithJavaxValidationAnnotations .class );
Original file line number Diff line number Diff line change 1+ package com .github .nylle .javafixture .testobjects ;
2+
3+
4+ import jakarta .persistence .Column ;
5+ import jakarta .validation .constraints .Size ;
6+
7+ public class TestObjectWithJakartaValidationAnnotations {
8+ @ Size (min = 3 , max = 6 )
9+ private String withMinMaxAnnotation ;
10+
11+ @ Size (min = 5 )
12+ private String withMinAnnotation ;
13+
14+ @ Size (max = 100 )
15+ private String withMaxAnnotation ;
16+
17+ @ Column (length = 5 )
18+ private String withColumnLengthAnnotation ;
19+
20+ @ Size (max = 100 )
21+ @ Column (length = 5 )
22+ private String withMaxAnnotationAndColumnLengthAnnotation ;
23+
24+ public String getWithMinMaxAnnotation () {
25+ return withMinMaxAnnotation ;
26+ }
27+
28+ public String getWithMinAnnotation () {
29+ return withMinAnnotation ;
30+ }
31+
32+ public String getWithMaxAnnotation () {
33+ return withMaxAnnotation ;
34+ }
35+
36+ public String getWithColumnLengthAnnotation () {
37+ return withColumnLengthAnnotation ;
38+ }
39+
40+ public String getWithColumnLengthAnnotationAndMaxAnnotation () {
41+ return withMaxAnnotationAndColumnLengthAnnotation ;
42+ }
43+ }
You can’t perform that action at this time.
0 commit comments