Is there a way to pass parameters to @Provide
? I want something equivalent to the following:
@Property
void test(@ForAll("charSequence", 2, 5) CharSequence cs) {
// test property on cs, which is an arbitrary CharSequence of length minimum 2 and maximum length 5
}
@Provide
Arbitrary<CharSequence> charSequence(int minLength, int maxLength) {
Arbitrary<String> stringArbitrary = Arbitraries.strings().ofMinLength(minLength).ofMaxLength(maxLength).injectNull(0.01);
Arbitrary<StringBuffer> stringBufferArbitrary = stringArbitrary.map
(str -> null == str ? null : new StringBuffer(str));
Arbitrary<StringBuilder> stringBuilderArbitrary = stringArbitrary.map
(str -> null == str ? null : new StringBuilder(str));
return Arbitraries.oneOf(stringArbitrary, stringBufferArbitrary, stringBuilderArbitrary);
}
I tried creating a custom annotation
public @interface Length {
int min();
int max();
}
and using it as void test(@ForAll("charSequence") @Length(min = 2, max = 5) CharSequence cs)
as suggested in Provider Methods with Parameters, but TypeUsage
doesn't seem to pick up the custom annotation, @Length
. (Only @ForAll
is picked.)