summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/au/id/zancanaro/javacheck/Generator.java2
-rw-r--r--src/main/java/au/id/zancanaro/javacheck/Generators.java4
-rw-r--r--src/main/java/au/id/zancanaro/javacheck/ShrinkTree.java20
-rw-r--r--src/main/java/au/id/zancanaro/javacheck/junit/Properties.java13
-rw-r--r--src/main/java/au/id/zancanaro/javacheck/object/CharType.java2
-rw-r--r--src/main/java/au/id/zancanaro/javacheck/object/GeneratorProvider.java5
-rw-r--r--src/main/java/au/id/zancanaro/javacheck/state/CommandValue.java4
-rw-r--r--src/main/java/au/id/zancanaro/javacheck/state/GeneratedCommand.java10
-rw-r--r--src/test/java/au/id/zancanaro/javacheck/state/queue/MyQueue.java1
9 files changed, 29 insertions, 32 deletions
diff --git a/src/main/java/au/id/zancanaro/javacheck/Generator.java b/src/main/java/au/id/zancanaro/javacheck/Generator.java
index ec7a16e..8642e8b 100644
--- a/src/main/java/au/id/zancanaro/javacheck/Generator.java
+++ b/src/main/java/au/id/zancanaro/javacheck/Generator.java
@@ -71,7 +71,7 @@ public interface Generator<T> {
ShrinkTree<T>[] result = (ShrinkTree<T>[]) new ShrinkTree[generators.length];
int index = 0;
for (Generator<? extends T> generator : generators) {
- result[index++] = generator.generate(random, size).map(x -> (T) x);
+ result[index++] = generator.generate(random, size).map(Function.identity());
}
return ShrinkTree.combine(result, ShrinkTree::promoteChildren);
};
diff --git a/src/main/java/au/id/zancanaro/javacheck/Generators.java b/src/main/java/au/id/zancanaro/javacheck/Generators.java
index 63d4ece..4c8e02e 100644
--- a/src/main/java/au/id/zancanaro/javacheck/Generators.java
+++ b/src/main/java/au/id/zancanaro/javacheck/Generators.java
@@ -41,7 +41,7 @@ public final class Generators {
@SafeVarargs
public static <T> Generator<T> oneOf(Generator<? extends T>... gens) {
- return integer(0, gens.length).flatMap(index -> gens[index].map(x -> (T) x));
+ return integer(0, gens.length).flatMap(index -> gens[index].map(Function.identity()));
}
@SafeVarargs
@@ -60,7 +60,7 @@ public final class Generators {
}
private static ShrinkStrategy<Boolean> boolShrinkStrategy() {
- return value -> (value ? Stream.of(false) : Stream.empty());
+ return value -> (value ? Stream.of(Boolean.FALSE) : Stream.empty());
}
public static Generator<Long> longInteger(long lower, long upper) {
diff --git a/src/main/java/au/id/zancanaro/javacheck/ShrinkTree.java b/src/main/java/au/id/zancanaro/javacheck/ShrinkTree.java
index 4f4eb62..6e21f27 100644
--- a/src/main/java/au/id/zancanaro/javacheck/ShrinkTree.java
+++ b/src/main/java/au/id/zancanaro/javacheck/ShrinkTree.java
@@ -52,7 +52,7 @@ public class ShrinkTree<T> {
return heads;
}
- @SuppressWarnings("unchecked")
+ @SuppressWarnings({"unchecked", "SuspiciousUninitializedArray"})
public static <T> Stream<ShrinkTree<T>[]> promoteChildren(ShrinkTree<? super T>[] trees) {
return IntStream.range(0, trees.length)
.mapToObj(index -> trees[index].getChildren().map(child ->
@@ -65,10 +65,11 @@ public class ShrinkTree<T> {
public static <T> Stream<ShrinkTree<T>[]> removeChildren(ShrinkTree<? super T>[] trees) {
return IntStream.range(0, trees.length)
- .mapToObj(index -> IntStream.range(0, trees.length)
- .filter(i -> i != index)
- .mapToObj(i -> trees[i])
- .toArray(ShrinkTree[]::new));
+ .mapToObj(index ->
+ IntStream.range(0, trees.length)
+ .filter(i -> i != index)
+ .mapToObj(i -> trees[i])
+ .toArray(ShrinkTree[]::new));
}
public static <T> Stream<ShrinkTree<T>[]> removeAndPromoteChildren(ShrinkTree<? super T>[] trees) {
@@ -90,14 +91,15 @@ public class ShrinkTree<T> {
() -> this.getChildren().map(tree -> tree.map(f)));
}
- public <R> ShrinkTree<R> flatMap(Function<?super T, ? extends ShrinkTree<R>> f) {
+ public <R> ShrinkTree<R> flatMap(Function<? super T, ? extends ShrinkTree<R>> f) {
return ShrinkTree.join(this.map(f));
}
public ShrinkTree<T> filter(Predicate<? super T> predicate) {
- if (predicate.test(this.getValue())) {
+ T value = this.getValue();
+ if (predicate.test(value)) {
return new ShrinkTree<>(
- this.getValue(),
+ value,
() -> this.getChildren()
.filter(tree -> predicate.test(tree.getValue()))
.map(tree -> tree.filter(predicate)));
@@ -112,7 +114,7 @@ public class ShrinkTree<T> {
private static <T> Stream<ShrinkTree<T>> strategyStream(final T value, final ShrinkStrategy<T> strategy) {
return strategy.shrink(value)
- .map(v -> new ShrinkTree<T>(v, () -> strategyStream(v, strategy)));
+ .map(v -> new ShrinkTree<>(v, () -> strategyStream(v, strategy)));
}
public void print(Writer output) throws IOException {
diff --git a/src/main/java/au/id/zancanaro/javacheck/junit/Properties.java b/src/main/java/au/id/zancanaro/javacheck/junit/Properties.java
index a7bf19b..c428edc 100644
--- a/src/main/java/au/id/zancanaro/javacheck/junit/Properties.java
+++ b/src/main/java/au/id/zancanaro/javacheck/junit/Properties.java
@@ -27,11 +27,6 @@ public class Properties extends BlockJUnit4ClassRunner {
}
@Override
- protected void collectInitializationErrors(List<Throwable> errors) {
- super.collectInitializationErrors(errors);
- }
-
- @Override
protected void validateConstructor(List<Throwable> errors) {
validateOnlyOneConstructor(errors);
}
@@ -109,7 +104,7 @@ public class Properties extends BlockJUnit4ClassRunner {
} catch (AssumptionViolatedException ex) {
numTests++;
if (assumptionsViolated++ == 50) {
- throw new Error("Violated 50 assumptions in a row: failing test");
+ throw new Error("Violated 50 assumptions in a row: failing test", ex);
}
} catch (Throwable ex) {
throw new PropertyError(method.getName(), seed, shrink(tree, ex));
@@ -130,9 +125,11 @@ public class Properties extends BlockJUnit4ClassRunner {
Iterator<ShrinkTree<List<Object>>> trees = failed.getChildren().iterator();
while (trees.hasNext()) {
ShrinkTree<List<Object>> tree = trees.next();
- if (seenArgs.add(Arrays.asList(tree.getValue()))) {
+ List<Object> value = tree.getValue();
+ boolean haveSeen = seenArgs.add(Arrays.asList(value));
+ if (haveSeen) {
try {
- runTest(tree.getValue().toArray());
+ runTest(value.toArray());
} catch (AssumptionViolatedException ex) {
// ignore, because it's not useful
} catch (Throwable ex) {
diff --git a/src/main/java/au/id/zancanaro/javacheck/object/CharType.java b/src/main/java/au/id/zancanaro/javacheck/object/CharType.java
index aa3049e..b53d211 100644
--- a/src/main/java/au/id/zancanaro/javacheck/object/CharType.java
+++ b/src/main/java/au/id/zancanaro/javacheck/object/CharType.java
@@ -10,6 +10,6 @@ import java.lang.annotation.Target;
public @interface CharType {
public static enum TYPE {
ALL, ASCII, ALPHA, ALPHA_NUMERIC
- };
+ }
TYPE value();
}
diff --git a/src/main/java/au/id/zancanaro/javacheck/object/GeneratorProvider.java b/src/main/java/au/id/zancanaro/javacheck/object/GeneratorProvider.java
index 67769b6..24b73d5 100644
--- a/src/main/java/au/id/zancanaro/javacheck/object/GeneratorProvider.java
+++ b/src/main/java/au/id/zancanaro/javacheck/object/GeneratorProvider.java
@@ -83,9 +83,10 @@ public interface GeneratorProvider {
provider));
} else if (type == Map.class) {
TypeVariable<?>[] params = Map.class.getTypeParameters();
+ TypeVariable<?> keyType = params[0], valueType = params[1];
return mapOf(
- provider.getGenerator(params[0], new Annotation[0], provider),
- provider.getGenerator(params[1], new Annotation[0], provider));
+ provider.getGenerator(keyType, new Annotation[0], provider),
+ provider.getGenerator(valueType, new Annotation[0], provider));
} else if (type instanceof Class) {
return ofType((Class<?>) type, provider);
} else if (type instanceof ParameterizedType) {
diff --git a/src/main/java/au/id/zancanaro/javacheck/state/CommandValue.java b/src/main/java/au/id/zancanaro/javacheck/state/CommandValue.java
index 1ca51a9..d2f3419 100644
--- a/src/main/java/au/id/zancanaro/javacheck/state/CommandValue.java
+++ b/src/main/java/au/id/zancanaro/javacheck/state/CommandValue.java
@@ -46,8 +46,8 @@ public class CommandValue<T> {
@SuppressWarnings("unchecked")
public T get() {
- if (values.containsKey(getId())) {
- return (T) values.get(getId());
+ if (values.containsKey(id)) {
+ return (T) values.get(id);
} else {
throw new NoSuchElementException("Concrete values cannot be supplied prior to being calculated");
}
diff --git a/src/main/java/au/id/zancanaro/javacheck/state/GeneratedCommand.java b/src/main/java/au/id/zancanaro/javacheck/state/GeneratedCommand.java
index 23f306b..92a90f9 100644
--- a/src/main/java/au/id/zancanaro/javacheck/state/GeneratedCommand.java
+++ b/src/main/java/au/id/zancanaro/javacheck/state/GeneratedCommand.java
@@ -30,19 +30,15 @@ public class GeneratedCommand<S, A, R> {
GeneratedCommand that = (GeneratedCommand) o;
- if (args != null ? !args.equals(that.args) : that.args != null)
- return false;
- if (command != null ? !command.equals(that.command) : that.command != null)
- return false;
+ return !(args != null ? !args.equals(that.args) : that.args != null)
+ && !(command != null ? !command.equals(that.command) : that.command != null);
- return true;
}
@Override
public int hashCode() {
int result = command != null ? command.hashCode() : 0;
- result = 31 * result + (args != null ? args.hashCode() : 0);
- return result;
+ return 31 * result + (args != null ? args.hashCode() : 0);
}
@Override
diff --git a/src/test/java/au/id/zancanaro/javacheck/state/queue/MyQueue.java b/src/test/java/au/id/zancanaro/javacheck/state/queue/MyQueue.java
index a820532..a8e04ee 100644
--- a/src/test/java/au/id/zancanaro/javacheck/state/queue/MyQueue.java
+++ b/src/test/java/au/id/zancanaro/javacheck/state/queue/MyQueue.java
@@ -11,6 +11,7 @@ public class MyQueue<T> extends AbstractQueue<T> {
this.list = new LinkedList<>();
}
+ @SuppressWarnings("NullableProblems")
@Override
public Iterator<T> iterator() {
return list.iterator();