This library contains some small utilities for generating random values in a testable way.
If you need to generate a UUID value you can of course just call UUID.randomUUID()
and this works fine.
However, when you are testing you cannot easily determine what the value will be. This library aims to help with
that by providing the UuidGenerator
interface, in normal execution the RandomUuidGenerator
can
be used to provide a random UUID, this is ultimately just calls UUID.randomUUID()
. when testing you
can use NonRandomUuidGenerator
instead, by default it will cycle around 5 fixed UUID values each time
it is called, if you require more than 5 distinct values you can pass in your own list of fixed UUID values
instead if you wish.
For generic string values a similar NumericStringGenerator
interface has been created, the generate method
takes a single argument which determines the length of the numeric string to be returned. If you do not need to
vary the length of the string value you can wrap the generated inside the FixedLengthNumericStringGenerator
class. There are two implementations of NumericStringGenerator
the first is RandomNumericStringGenerator
which unsurprisingly will generate a string containing random digits of the specified length. When testing you
can use IncrementingNumericStringGenerator
this will return predictable results by returning an incrementing
value starting from 1. So if you pass a length of 5, the first 3 calls would return "00001", "00002", "00003".
The unit tests for each of the classes listed above demonstrate each of the classes above and how they can be used.
// cleans build directories
// prints currentVersion
// formats code
// builds code
// runs tests
// checks for gradle issues
// checks dependency versions
./gradlew clean currentVersion dependencyUpdates lintGradle spotlessApply build