Make Long and Double test factories return unique vals

Random was returning the same value multiple times,
causing issues with Set tests
This commit is contained in:
Jennifer Hickey
2013-07-31 16:25:52 -07:00
parent 28c8dca650
commit ce76ad1841
4 changed files with 17 additions and 19 deletions

View File

@@ -15,20 +15,21 @@
*/
package org.springframework.data.redis;
import java.util.Random;
import java.util.concurrent.atomic.AtomicLong;
/**
*
* Implementation of {@link ObjectFactory that returns random Doubles as Strings
* Implementation of {@link ObjectFactory} that returns unique Doubles as Strings,
* incrementing by 1 each time
* @author Jennifer Hickey
*
*/
public class DoubleAsStringObjectFactory implements ObjectFactory<String> {
private Random random = new Random(System.currentTimeMillis());
private AtomicLong counter = new AtomicLong();
public String instance() {
return String.valueOf(random.nextDouble());
return String.valueOf(Double.valueOf(counter.getAndIncrement()));
}
}

View File

@@ -15,23 +15,20 @@
*/
package org.springframework.data.redis;
import java.text.DecimalFormat;
import java.util.Random;
import java.util.concurrent.atomic.AtomicLong;
/**
* Returns random Doubles
* Returns unique Doubles, incrementing by 1 each time
*
* @author Jennifer Hickey
*
*/
public class DoubleObjectFactory implements ObjectFactory<Double> {
private Random random = new Random(System.currentTimeMillis());
private static final DecimalFormat TWO_D_FORM = new DecimalFormat("#.##");
private AtomicLong counter = new AtomicLong();
public Double instance() {
return Double.valueOf(TWO_D_FORM.format(random.nextDouble()));
return Double.valueOf(counter.getAndIncrement());
}
}

View File

@@ -15,20 +15,20 @@
*/
package org.springframework.data.redis;
import java.util.Random;
import java.util.concurrent.atomic.AtomicLong;
/**
*
* Implementation of {@link ObjectFactory that returns random Longs as Strings
* Implementation of {@link ObjectFactory} that returns unique incremented Longs as Strings
* @author Jennifer Hickey
*
*/
public class LongAsStringObjectFactory implements ObjectFactory<String> {
private Random random = new Random(System.currentTimeMillis());
private AtomicLong counter = new AtomicLong();
public String instance() {
return String.valueOf(random.nextLong());
return String.valueOf(counter.getAndIncrement());
}
}

View File

@@ -15,20 +15,20 @@
*/
package org.springframework.data.redis;
import java.util.Random;
import java.util.concurrent.atomic.AtomicLong;
/**
* Returns random Longs
* Returns unique Longs by incrementing a counter each time
*
* @author Jennifer Hickey
*
*/
public class LongObjectFactory implements ObjectFactory<Long> {
private Random random = new Random(System.currentTimeMillis());
private AtomicLong counter = new AtomicLong();
public Long instance() {
return random.nextLong();
return counter.getAndIncrement();
}
}