diff --git a/core/src/main/java/com/pholser/junit/quickcheck/generator/Fields.java b/core/src/main/java/com/pholser/junit/quickcheck/generator/Fields.java index c99373231..fc1ce7825 100644 --- a/core/src/main/java/com/pholser/junit/quickcheck/generator/Fields.java +++ b/core/src/main/java/com/pholser/junit/quickcheck/generator/Fields.java @@ -78,11 +78,12 @@ public Fields(Class type) { Class type = types().get(0); Object generated = instantiate(type); - for (Field each : fields) { + for (int i = 0; i < fields.size(); i++) { + Field each = fields.get(i); setField( each, generated, - gen().field(each).generate(random, status), + fieldGenerators.get(i).generate(random, status), true); } diff --git a/generators/src/main/java/com/pholser/junit/quickcheck/generator/java/util/LocaleGenerator.java b/generators/src/main/java/com/pholser/junit/quickcheck/generator/java/util/LocaleGenerator.java index 7d45731af..92b3f362b 100644 --- a/generators/src/main/java/com/pholser/junit/quickcheck/generator/java/util/LocaleGenerator.java +++ b/generators/src/main/java/com/pholser/junit/quickcheck/generator/java/util/LocaleGenerator.java @@ -37,11 +37,13 @@ a copy of this software and associated documentation files (the * Produces values of type {@link Locale}. */ public class LocaleGenerator extends Generator { + private final static Locale[] availableLocales = getAvailableLocales(); + public LocaleGenerator() { super(Locale.class); } @Override public Locale generate(SourceOfRandomness random, GenerationStatus status) { - return random.choose(getAvailableLocales()); + return random.choose(availableLocales); } } diff --git a/generators/src/main/java/com/pholser/junit/quickcheck/generator/java/util/RFC4122.java b/generators/src/main/java/com/pholser/junit/quickcheck/generator/java/util/RFC4122.java index 68d473138..a61fd838c 100644 --- a/generators/src/main/java/com/pholser/junit/quickcheck/generator/java/util/RFC4122.java +++ b/generators/src/main/java/com/pholser/junit/quickcheck/generator/java/util/RFC4122.java @@ -29,6 +29,7 @@ a copy of this software and associated documentation files (the import java.lang.annotation.Target; import java.nio.ByteBuffer; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.UUID; @@ -88,7 +89,7 @@ protected NameBasedUUIDGenerator(String hashAlgorithmName, int versionMask) { @Override public UUID generate(SourceOfRandomness random, GenerationStatus status) { digest.reset(); digest.update((namespace == null ? Namespaces.URL : namespace.value()).bytes); - digest.update(stringGenerator.generate(random, status).getBytes(Charset.forName("UTF-8"))); + digest.update(stringGenerator.generate(random, status).getBytes(StandardCharsets.UTF_8)); byte[] hash = digest.digest(); setVersion(hash, (byte) versionMask); diff --git a/generators/src/main/java/com/pholser/junit/quickcheck/generator/java/util/TimeZoneGenerator.java b/generators/src/main/java/com/pholser/junit/quickcheck/generator/java/util/TimeZoneGenerator.java index 654141b5f..386ad64e3 100644 --- a/generators/src/main/java/com/pholser/junit/quickcheck/generator/java/util/TimeZoneGenerator.java +++ b/generators/src/main/java/com/pholser/junit/quickcheck/generator/java/util/TimeZoneGenerator.java @@ -37,11 +37,13 @@ a copy of this software and associated documentation files (the * Produces values of type {@link TimeZone}. */ public class TimeZoneGenerator extends Generator { + private final static String[] availableIDs = getAvailableIDs(); + public TimeZoneGenerator() { super(TimeZone.class); } @Override public TimeZone generate(SourceOfRandomness random, GenerationStatus status) { - return getTimeZone(random.choose(getAvailableIDs())); + return getTimeZone(random.choose(availableIDs)); } } diff --git a/generators/src/main/java/com/pholser/junit/quickcheck/generator/java/util/function/BiPredicateGenerator.java b/generators/src/main/java/com/pholser/junit/quickcheck/generator/java/util/function/BiPredicateGenerator.java index 58ceb96cc..28bd24634 100644 --- a/generators/src/main/java/com/pholser/junit/quickcheck/generator/java/util/function/BiPredicateGenerator.java +++ b/generators/src/main/java/com/pholser/junit/quickcheck/generator/java/util/function/BiPredicateGenerator.java @@ -29,6 +29,8 @@ a copy of this software and associated documentation files (the import com.pholser.junit.quickcheck.generator.ComponentizedGenerator; import com.pholser.junit.quickcheck.generator.GenerationStatus; +import com.pholser.junit.quickcheck.generator.Generator; +import com.pholser.junit.quickcheck.generator.Generators; import com.pholser.junit.quickcheck.random.SourceOfRandomness; import static com.pholser.junit.quickcheck.generator.Lambdas.*; @@ -40,13 +42,21 @@ a copy of this software and associated documentation files (the * @param type of second parameter of produced predicate */ public class BiPredicateGenerator extends ComponentizedGenerator { + private Generator generator; + public BiPredicateGenerator() { super(BiPredicate.class); } + @Override + public void provide(Generators provided) { + super.provide(provided); + generator = gen().type(boolean.class); + } + @SuppressWarnings("unchecked") @Override public BiPredicate generate(SourceOfRandomness random, GenerationStatus status) { - return makeLambda(BiPredicate.class, gen().type(boolean.class), status); + return makeLambda(BiPredicate.class, generator, status); } @Override public int numberOfNeededComponents() { diff --git a/generators/src/main/java/com/pholser/junit/quickcheck/generator/java/util/function/PredicateGenerator.java b/generators/src/main/java/com/pholser/junit/quickcheck/generator/java/util/function/PredicateGenerator.java index b3834215e..c02b184b1 100644 --- a/generators/src/main/java/com/pholser/junit/quickcheck/generator/java/util/function/PredicateGenerator.java +++ b/generators/src/main/java/com/pholser/junit/quickcheck/generator/java/util/function/PredicateGenerator.java @@ -29,6 +29,8 @@ a copy of this software and associated documentation files (the import com.pholser.junit.quickcheck.generator.ComponentizedGenerator; import com.pholser.junit.quickcheck.generator.GenerationStatus; +import com.pholser.junit.quickcheck.generator.Generator; +import com.pholser.junit.quickcheck.generator.Generators; import com.pholser.junit.quickcheck.random.SourceOfRandomness; import static com.pholser.junit.quickcheck.generator.Lambdas.*; @@ -39,13 +41,21 @@ a copy of this software and associated documentation files (the * @param type of parameter of produced predicate */ public class PredicateGenerator extends ComponentizedGenerator { + private Generator generator; + public PredicateGenerator() { super(Predicate.class); } + @Override + public void provide(Generators provided) { + super.provide(provided); + generator = gen().type(boolean.class); + } + @SuppressWarnings("unchecked") @Override public Predicate generate(SourceOfRandomness random, GenerationStatus status) { - return makeLambda(Predicate.class, gen().type(boolean.class), status); + return makeLambda(Predicate.class, generator, status); } @Override public int numberOfNeededComponents() { diff --git a/generators/src/main/java/com/pholser/junit/quickcheck/generator/java/util/function/ToDoubleBiFunctionGenerator.java b/generators/src/main/java/com/pholser/junit/quickcheck/generator/java/util/function/ToDoubleBiFunctionGenerator.java index 5d4a678c4..29de687a8 100644 --- a/generators/src/main/java/com/pholser/junit/quickcheck/generator/java/util/function/ToDoubleBiFunctionGenerator.java +++ b/generators/src/main/java/com/pholser/junit/quickcheck/generator/java/util/function/ToDoubleBiFunctionGenerator.java @@ -29,6 +29,8 @@ a copy of this software and associated documentation files (the import com.pholser.junit.quickcheck.generator.ComponentizedGenerator; import com.pholser.junit.quickcheck.generator.GenerationStatus; +import com.pholser.junit.quickcheck.generator.Generator; +import com.pholser.junit.quickcheck.generator.Generators; import com.pholser.junit.quickcheck.random.SourceOfRandomness; import static com.pholser.junit.quickcheck.generator.Lambdas.*; @@ -40,13 +42,21 @@ a copy of this software and associated documentation files (the * @param type of second parameter of produced function */ public class ToDoubleBiFunctionGenerator extends ComponentizedGenerator { + private Generator generator; + public ToDoubleBiFunctionGenerator() { super(ToDoubleBiFunction.class); } + @Override + public void provide(Generators provided) { + super.provide(provided); + generator = gen().type(double.class); + } + @SuppressWarnings("unchecked") @Override public ToDoubleBiFunction generate(SourceOfRandomness random, GenerationStatus status) { - return makeLambda(ToDoubleBiFunction.class, gen().type(double.class), status); + return makeLambda(ToDoubleBiFunction.class, generator, status); } @Override public int numberOfNeededComponents() { diff --git a/generators/src/main/java/com/pholser/junit/quickcheck/generator/java/util/function/ToDoubleFunctionGenerator.java b/generators/src/main/java/com/pholser/junit/quickcheck/generator/java/util/function/ToDoubleFunctionGenerator.java index 56b737ef8..e1a8f7a1f 100644 --- a/generators/src/main/java/com/pholser/junit/quickcheck/generator/java/util/function/ToDoubleFunctionGenerator.java +++ b/generators/src/main/java/com/pholser/junit/quickcheck/generator/java/util/function/ToDoubleFunctionGenerator.java @@ -29,6 +29,8 @@ a copy of this software and associated documentation files (the import com.pholser.junit.quickcheck.generator.ComponentizedGenerator; import com.pholser.junit.quickcheck.generator.GenerationStatus; +import com.pholser.junit.quickcheck.generator.Generator; +import com.pholser.junit.quickcheck.generator.Generators; import com.pholser.junit.quickcheck.random.SourceOfRandomness; import static com.pholser.junit.quickcheck.generator.Lambdas.*; @@ -39,13 +41,21 @@ a copy of this software and associated documentation files (the * @param type of parameter of produced function */ public class ToDoubleFunctionGenerator extends ComponentizedGenerator { + private Generator generator; + public ToDoubleFunctionGenerator() { super(ToDoubleFunction.class); } + @Override + public void provide(Generators provided) { + super.provide(provided); + generator = gen().type(double.class); + } + @SuppressWarnings("unchecked") @Override public ToDoubleFunction generate(SourceOfRandomness random, GenerationStatus status) { - return makeLambda(ToDoubleFunction.class, gen().type(double.class), status); + return makeLambda(ToDoubleFunction.class, generator, status); } @Override public int numberOfNeededComponents() { diff --git a/generators/src/main/java/com/pholser/junit/quickcheck/generator/java/util/function/ToIntBiFunctionGenerator.java b/generators/src/main/java/com/pholser/junit/quickcheck/generator/java/util/function/ToIntBiFunctionGenerator.java index fb0073baf..d7a6540df 100644 --- a/generators/src/main/java/com/pholser/junit/quickcheck/generator/java/util/function/ToIntBiFunctionGenerator.java +++ b/generators/src/main/java/com/pholser/junit/quickcheck/generator/java/util/function/ToIntBiFunctionGenerator.java @@ -29,6 +29,8 @@ a copy of this software and associated documentation files (the import com.pholser.junit.quickcheck.generator.ComponentizedGenerator; import com.pholser.junit.quickcheck.generator.GenerationStatus; +import com.pholser.junit.quickcheck.generator.Generator; +import com.pholser.junit.quickcheck.generator.Generators; import com.pholser.junit.quickcheck.random.SourceOfRandomness; import static com.pholser.junit.quickcheck.generator.Lambdas.*; @@ -40,13 +42,21 @@ a copy of this software and associated documentation files (the * @param type of second parameter of produced function */ public class ToIntBiFunctionGenerator extends ComponentizedGenerator { + private Generator generator; + public ToIntBiFunctionGenerator() { super(ToIntBiFunction.class); } + @Override + public void provide(Generators provided) { + super.provide(provided); + generator = gen().type(int.class); + } + @SuppressWarnings("unchecked") @Override public ToIntBiFunction generate(SourceOfRandomness random, GenerationStatus status) { - return makeLambda(ToIntBiFunction.class, gen().type(int.class), status); + return makeLambda(ToIntBiFunction.class, generator, status); } @Override public int numberOfNeededComponents() { diff --git a/generators/src/main/java/com/pholser/junit/quickcheck/generator/java/util/function/ToIntFunctionGenerator.java b/generators/src/main/java/com/pholser/junit/quickcheck/generator/java/util/function/ToIntFunctionGenerator.java index 8e02d05c8..c57c7d3a6 100644 --- a/generators/src/main/java/com/pholser/junit/quickcheck/generator/java/util/function/ToIntFunctionGenerator.java +++ b/generators/src/main/java/com/pholser/junit/quickcheck/generator/java/util/function/ToIntFunctionGenerator.java @@ -29,6 +29,8 @@ a copy of this software and associated documentation files (the import com.pholser.junit.quickcheck.generator.ComponentizedGenerator; import com.pholser.junit.quickcheck.generator.GenerationStatus; +import com.pholser.junit.quickcheck.generator.Generator; +import com.pholser.junit.quickcheck.generator.Generators; import com.pholser.junit.quickcheck.random.SourceOfRandomness; import static com.pholser.junit.quickcheck.generator.Lambdas.*; @@ -39,13 +41,21 @@ a copy of this software and associated documentation files (the * @param type of parameter of produced function */ public class ToIntFunctionGenerator extends ComponentizedGenerator { + private Generator generator; + public ToIntFunctionGenerator() { super(ToIntFunction.class); } + @Override + public void provide(Generators provided) { + super.provide(provided); + generator = gen().type(int.class); + } + @SuppressWarnings("unchecked") @Override public ToIntFunction generate(SourceOfRandomness random, GenerationStatus status) { - return makeLambda(ToIntFunction.class, gen().type(int.class), status); + return makeLambda(ToIntFunction.class, generator, status); } @Override public int numberOfNeededComponents() { diff --git a/generators/src/main/java/com/pholser/junit/quickcheck/generator/java/util/function/ToLongBiFunctionGenerator.java b/generators/src/main/java/com/pholser/junit/quickcheck/generator/java/util/function/ToLongBiFunctionGenerator.java index 9a477f8b5..19716fbd7 100644 --- a/generators/src/main/java/com/pholser/junit/quickcheck/generator/java/util/function/ToLongBiFunctionGenerator.java +++ b/generators/src/main/java/com/pholser/junit/quickcheck/generator/java/util/function/ToLongBiFunctionGenerator.java @@ -29,6 +29,8 @@ a copy of this software and associated documentation files (the import com.pholser.junit.quickcheck.generator.ComponentizedGenerator; import com.pholser.junit.quickcheck.generator.GenerationStatus; +import com.pholser.junit.quickcheck.generator.Generator; +import com.pholser.junit.quickcheck.generator.Generators; import com.pholser.junit.quickcheck.random.SourceOfRandomness; import static com.pholser.junit.quickcheck.generator.Lambdas.*; @@ -40,13 +42,21 @@ a copy of this software and associated documentation files (the * @param type of second parameter of produced function */ public class ToLongBiFunctionGenerator extends ComponentizedGenerator { + private Generator generator; + public ToLongBiFunctionGenerator() { super(ToLongBiFunction.class); } + @Override + public void provide(Generators provided) { + super.provide(provided); + generator = gen().type(long.class); + } + @SuppressWarnings("unchecked") @Override public ToLongBiFunction generate(SourceOfRandomness random, GenerationStatus status) { - return makeLambda(ToLongBiFunction.class, gen().type(long.class), status); + return makeLambda(ToLongBiFunction.class, generator, status); } @Override public int numberOfNeededComponents() { diff --git a/generators/src/main/java/com/pholser/junit/quickcheck/generator/java/util/function/ToLongFunctionGenerator.java b/generators/src/main/java/com/pholser/junit/quickcheck/generator/java/util/function/ToLongFunctionGenerator.java index 9ac429511..1fb217665 100644 --- a/generators/src/main/java/com/pholser/junit/quickcheck/generator/java/util/function/ToLongFunctionGenerator.java +++ b/generators/src/main/java/com/pholser/junit/quickcheck/generator/java/util/function/ToLongFunctionGenerator.java @@ -29,6 +29,8 @@ a copy of this software and associated documentation files (the import com.pholser.junit.quickcheck.generator.ComponentizedGenerator; import com.pholser.junit.quickcheck.generator.GenerationStatus; +import com.pholser.junit.quickcheck.generator.Generator; +import com.pholser.junit.quickcheck.generator.Generators; import com.pholser.junit.quickcheck.random.SourceOfRandomness; import static com.pholser.junit.quickcheck.generator.Lambdas.*; @@ -39,13 +41,21 @@ a copy of this software and associated documentation files (the * @param type of parameter of produced function */ public class ToLongFunctionGenerator extends ComponentizedGenerator { + private Generator generator; + public ToLongFunctionGenerator() { super(ToLongFunction.class); } + @Override + public void provide(Generators provided) { + super.provide(provided); + generator = gen().type(long.class); + } + @SuppressWarnings("unchecked") @Override public ToLongFunction generate(SourceOfRandomness random, GenerationStatus status) { - return makeLambda(ToLongFunction.class, gen().type(long.class), status); + return makeLambda(ToLongFunction.class, generator, status); } @Override public int numberOfNeededComponents() {