I'd like to generate unique, repeatable, simple values by Class. This is part of something I'm writing to validate Java beans, i.e. the firePropertyChange() is implemented correctly.
I've started implementing something along the lines of
class TestValueGenerator {
private int counter;
public Object getNextValue(Class<?> type) {
counter++;
if (type == byte.class) {
return (byte)counter;
} else if (type == short.class) {
return (short)counter;
} ...
// int, long, float, double, String, Date etc...
}
}
I'm building on top of openpojo, this does have existing generation functions, however they are implemented using random number generation seeded on current time, which I personally think is unwise for unit testing... e.g.
value = com.openpojo.random.RandomFactory.getRandomValue(fieldEntry);
Question
- Is there any built-in Java method or external library to do this - am I reinventing the wheel?
Aucun commentaire:
Enregistrer un commentaire