Skip to content

Commit

Permalink
#6 -- using AtomicInteger instead of primitive int to track invocatio…
Browse files Browse the repository at this point in the history
…ns of the BooleanGenerator, just in case the generators are not thread-safe -- not entirely sure, but not a bad way to think anyhow IMHO.
  • Loading branch information
pholser committed Jun 13, 2012
1 parent 5764ce1 commit 93d4a90
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ a copy of this software and associated documentation files (the

package com.pholser.junit.quickcheck.generator;

import java.util.concurrent.atomic.AtomicInteger;

import com.pholser.junit.quickcheck.internal.random.SourceOfRandomness;

import static java.util.Arrays.*;

public class BooleanGenerator extends Generator<Boolean> {
private int invocations;
private final AtomicInteger invocations = new AtomicInteger(0);

@SuppressWarnings("unchecked")
public BooleanGenerator() {
Expand All @@ -39,6 +41,6 @@ public BooleanGenerator() {

@Override
public Boolean generate(SourceOfRandomness random, int size) {
return ++invocations % 2 == 0;
return invocations.incrementAndGet() % 2 == 0;
}
}

0 comments on commit 93d4a90

Please sign in to comment.