Test data generation produces input values or cases from defined rules, replacing hand-written examples with controlled randomized data. A single randomized function can feed Java streams indefinitely, while specialized generators keep business-relevant states visible. section 11.5.1 section 11.5.2
Useful generation patterns include:
- Generate specialized collections, such as accounts from one region or accounts fixed to a particular identifier. section 11.5.1
- Combine focused generators to cover meaningful partitions, such as values above, equal to, or below a threshold. section 11.5.2
- Generate a broad collection first, then filter or group it into interesting subsets. section 11.5.1
- Randomize collection sizes, including zero, and nest generators to produce structures such as lists of lists. section 11.5.1
- Adjust the amount of generated data to reuse one test for ordinary checks, load exploration, throughput, or service-duration questions. section 11.5.3
Testing threshold behavior
Choose a random threshold, generate accounts above, at, and below it, and combine those streams into one set. The test can then assert that accounts above the threshold in a region are excluded while the other generated states are processed. section 11.5.2
Listing 11.38 The Stream.generate function
public static<T> Stream<T> generate(Supplier<? extends T> s) {...} #AStream.generate accepts a supplier and creates the source stream used by the constrained, combined, and volume-controlled generation patterns. section 11.5.1

