有没有办法将参数传递给@Provide
?我想要与以下内容等效的东西:
@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);
}
我尝试创建自定义注释
public @interface Length {
int min();
int max();
}
并按照Provider Methods with Parametersvoid test(@ForAll("charSequence") @Length(min = 2, max = 5) CharSequence cs)
中的建议使用它,但似乎没有选择自定义注释,. (仅被选中。)TypeUsage
@Length
@ForAll