public static StringConversion decide(ParameterTypeContext p, Only only) { return decide(p, only.by(), Only.class); }
@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; }
@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); } }
public static StringConversion decide(ParameterTypeContext p, Only only) { return decide(p, only.by(), Only.class); }
StringConversion conversion = StringConversions.decide(p, only); Set<Object> values = Arrays.stream(only.value()) .map(conversion::convert) .collect(toSet());
@Property(mode = EXHAUSTIVE) public void shouldHold(@Only("true") boolean b) { testCases.add(b); ++iterations; } }
@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(@Only({"14", "-15"}) Byte b) { testCases.add(b); ++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(mode = EXHAUSTIVE) public void shouldHold( @Only(value = {"2017/01/01", "2001/12/25"}, by = YYYYMMDD.class) LocalDate d) { testCases.add(d); ++iterations; } }
StringConversion conversion = StringConversions.decide(p, only); Set<Object> values = Arrays.stream(only.value()) .map(conversion::convert) .collect(toSet());
@Property(mode = EXHAUSTIVE) public void shouldHold(@Only({"@", "#"}) Character ch) { testCases.add(ch); ++iterations; } }
@Property(mode = EXHAUSTIVE) public void shouldHold(@Only({"1", "2", "3"}) int i) { testCases.add(i); ++iterations; } }
@Property(mode = EXHAUSTIVE) public void shouldHold(@Only({"4", "5"}) Integer i) { testCases.add(i); ++iterations; } }
@Property(mode = EXHAUSTIVE) public void shouldHold(@Only({"-13", "-14"}) Short sh) { testCases.add(sh); ++iterations; } }
@Property(trials = 11, mode = EXHAUSTIVE) public void exhaustiveOnly( int arg0, boolean arg1, Response arg2, @Only({"1", "2", "0", "-1"}) int arg3) { System.out.printf("%d %s %s %d\n", arg0, arg1, arg2, arg3); }
@Property(mode = EXHAUSTIVE) public void shouldHold(@Only({"Z", "z"}) char ch) { testCases.add(ch); ++iterations; } }