private static <T extends Annotation> StringConversion decide( ParameterTypeContext p, Class<? extends StringConversion> custom, Class<T> markerClass) { return custom.equals(defaultValueOf(markerClass, "by")) ? to(p.getRawClass()) : instantiate(custom); }
@Override public int sizeFactor(ParameterTypeContext p) { Only only = p.annotatedType().getAnnotation(Only.class); if (only != null) return new HashSet<>(asList(only.value())).size(); Also also = p.annotatedType().getAnnotation(Also.class); if (also != null) return max(sizeFactor, new HashSet<>(asList(also.value())).size()); if (Boolean.class.equals(maybeWrap(p.getRawClass()))) return 2; if (p.isEnum()) { return Array.getLength( invoke( findMethod(p.getRawClass(), "values"), null)); } return sizeFactor; }
@Property(mode = EXHAUSTIVE) public void shouldHold(@Also({"a", "b"}) Target t) { ++iterations; } }
@Override public Generator<?> decideGenerator( GeneratorRepository repository, ParameterTypeContext p) { Only only = p.annotatedType().getAnnotation(Only.class); if (only != null) { StringConversion conversion = StringConversions.decide(p, only); Set<Object> values = Arrays.stream(only.value()) .map(conversion::convert) .collect(toSet()); return new SamplingDomainGenerator(values); } Also also = p.annotatedType().getAnnotation(Also.class); if (also != null) { StringConversion conversion = StringConversions.decide(p, also); Set<Object> values = Arrays.stream(also.value()) .map(conversion::convert) .collect(toSet()); return new GuaranteeValuesGenerator( new ExhaustiveDomainGenerator(values), repository.produceGenerator(p)); } return repository.produceGenerator(p); } }
private static <T extends Annotation> StringConversion decide( ParameterTypeContext p, Class<? extends StringConversion> custom, Class<T> markerClass) { return custom.equals(defaultValueOf(markerClass, "by")) ? to(p.getRawClass()) : instantiate(custom); }
@Property(mode = EXHAUSTIVE) public void shouldHold(@Also({"HALF_EVEN", "HALF_UP"}) RoundingMode mode) { values.add(mode); ++iterations; } }
StringConversion conversion = StringConversions.decide(p, also); Set<Object> values = Arrays.stream(also.value()) .map(conversion::convert) .collect(toSet());
@Property(trials = 11, mode = EXHAUSTIVE) public void exhaustiveAlso( int arg0, boolean arg1, Response arg2, @Also({"1", "2", "0", "-1"}) int arg3) { System.out.printf("%d %s %s %d\n", arg0, arg1, arg2, arg3); } }
@Override public int sizeFactor(ParameterTypeContext p) { Only only = p.annotatedType().getAnnotation(Only.class); if (only != null) return new HashSet<>(asList(only.value())).size(); Also also = p.annotatedType().getAnnotation(Also.class); if (also != null) return max(sizeFactor, new HashSet<>(asList(also.value())).size()); if (Boolean.class.equals(maybeWrap(p.getRawClass()))) return 2; if (p.isEnum()) { return Array.getLength( invoke( findMethod(p.getRawClass(), "values"), null)); } return sizeFactor; }
@Property public void shouldHold(@Also({"HALF_EVEN", "HALF_UP"}) RoundingMode mode) { values.add(mode); ++iterations; } }
@Override public Generator<?> decideGenerator( GeneratorRepository repository, ParameterTypeContext p) { Only only = p.annotatedType().getAnnotation(Only.class); if (only != null) { StringConversion conversion = StringConversions.decide(p, only); Set<Object> values = Arrays.stream(only.value()) .map(conversion::convert) .collect(toSet()); return new SamplingDomainGenerator(values); } Also also = p.annotatedType().getAnnotation(Also.class); if (also != null) { StringConversion conversion = StringConversions.decide(p, also); Set<Object> values = Arrays.stream(also.value()) .map(conversion::convert) .collect(toSet()); return new GuaranteeValuesGenerator( new ExhaustiveDomainGenerator(values), repository.produceGenerator(p)); } return repository.produceGenerator(p); } }
@Property public void shouldHold(@Also({"a", "b"}) Target t) { ++iterations; } }
StringConversion conversion = StringConversions.decide(p, also); Set<Object> values = Arrays.stream(also.value()) .map(conversion::convert) .collect(toSet());
@Property(trials = 4, mode = EXHAUSTIVE) public void shouldHold( @Also({"3", "7"}) @From(AnInt.class) int i, @Also({"a", "b", "c"}) @From(AChar.class) char ch, boolean b, RoundingMode mode) { firstTestCases.add(i); secondTestCases.add(ch); thirdTestCases.add(b); fourthTestCases.add(mode); ++iterations; } }
@Property(mode = EXHAUSTIVE) public void shouldHold(@Also({"14", "-15"}) @From(AByte.class) Byte b) { values.add(b); ++iterations; } }
@Property(mode = EXHAUSTIVE) public void shouldHold( @Also(value = {"2017/01/01", "2001/12/25"}, by = YYYYMMDD.class) @From(LocalDates.class) LocalDate d) { values.add(d); ++iterations; } }
@Property public void shouldHold(@Also({"1.7", "-4.14"}) @From(AFloat.class) Float f) { values.add(f); ++iterations; } }