@@ -43,7 +43,8 @@ public PrimitiveSpecimen(final SpecimenType<T> type, final Context context) {
4343 @ Override
4444 public T create (final CustomizationContext customizationContext , Annotation [] annotations ) {
4545 if (type .asClass ().equals (String .class )) {
46- return context .preDefined (type , (T ) pseudoRandom .nextString (detectStringConstraints (annotations )));
46+ StringConstraints constraints = getStringConstraints (annotations );
47+ return context .preDefined (type , (T ) pseudoRandom .nextString (constraints ));
4748 }
4849
4950 if (type .asClass ().equals (Boolean .class ) || type .asClass ().equals (boolean .class )) {
@@ -81,25 +82,20 @@ public T create(final CustomizationContext customizationContext, Annotation[] an
8182 throw new SpecimenException ("Unsupported type: " + type );
8283 }
8384
84- private StringConstraints detectStringConstraints (Annotation [] annotations ) {
85+ private StringConstraints getStringConstraints (Annotation [] annotations ) {
86+ var constraints = new StringConstraints (0 , Integer .MAX_VALUE );
8587 for (var annotation : annotations ) {
8688 if (Size .class .isAssignableFrom (annotation .annotationType ())) {
87- return new StringConstraints (((Size )annotation ).min (), ((Size )annotation ).max ());
88- }
89-
90- if (Column .class .isAssignableFrom (annotation .annotationType ())) {
91- return new StringConstraints (0 , ((Column ) annotation ).length ());
92- }
93-
94- if (jakarta .validation .constraints .Size .class .isAssignableFrom (annotation .annotationType ())) {
95- return new StringConstraints (((jakarta .validation .constraints .Size )annotation ).min (), ((jakarta .validation .constraints .Size )annotation ).max ());
96- }
97-
98- if (jakarta .persistence .Column .class .isAssignableFrom (annotation .annotationType ())) {
99- return new StringConstraints (0 , ((jakarta .persistence .Column ) annotation ).length ());
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 ());
10096 }
10197 }
102- return new StringConstraints ( 0 , Integer . MAX_VALUE ) ;
98+ return constraints ;
10399 }
104100}
105101
0 commit comments