|
10 | 10 | import com.github.nylle.javafixture.specimen.constraints.StringConstraints; |
11 | 11 |
|
12 | 12 | import java.lang.annotation.Annotation; |
13 | | -import javax.persistence.Column; |
14 | | -import javax.validation.constraints.Size; |
15 | 13 |
|
16 | 14 | public class PrimitiveSpecimen<T> implements ISpecimen<T> { |
17 | 15 |
|
@@ -85,14 +83,19 @@ public T create(final CustomizationContext customizationContext, Annotation[] an |
85 | 83 | private StringConstraints getStringConstraints(Annotation[] annotations) { |
86 | 84 | var constraints = new StringConstraints(0, Integer.MAX_VALUE); |
87 | 85 | for (var annotation : annotations) { |
88 | | - if(Size.class.isAssignableFrom(annotation.annotationType())) { |
89 | | - constraints = new StringConstraints(((Size)annotation).min(), ((Size)annotation).max()); |
90 | | - } else if(Column.class.isAssignableFrom(annotation.annotationType())) { |
91 | | - 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()); |
| 86 | + switch (annotation.annotationType().getCanonicalName()) { |
| 87 | + case "jakarta.persistence.Column": |
| 88 | + constraints = new StringConstraints(0, ((jakarta.persistence.Column) annotation).length()); |
| 89 | + break; |
| 90 | + case "jakarta.validation.constraints.Size": |
| 91 | + constraints = new StringConstraints(((jakarta.validation.constraints.Size) annotation).min(), ((jakarta.validation.constraints.Size) annotation).max()); |
| 92 | + break; |
| 93 | + case "javax.persistence.Column": |
| 94 | + constraints = new StringConstraints(0, ((javax.persistence.Column) annotation).length()); |
| 95 | + break; |
| 96 | + case "javax.validation.constraints.Size": |
| 97 | + constraints = new StringConstraints(((javax.validation.constraints.Size) annotation).min(), ((javax.validation.constraints.Size) annotation).max()); |
| 98 | + break; |
96 | 99 | } |
97 | 100 | } |
98 | 101 | return constraints; |
|
0 commit comments