Generating a UUID is nothing special, either.
12
val genUuid: Gen[UUID] = Gen.delay(UUID.randomUUID)
)
Generate UUID
We might be tempted to use Gen.const here, but we don’t because it will then become immutable.
Another option is using a list of randomly generated UUID values from which we then chose one. That would be sufficient for generators that only generate a single product, but if we want to generate lists of products, we would have duplicate IDs sooner or later.
ScalaCheck generate ProductName
xxxxxxxxxx
val DefaultProductName: ProductName = "I am a product name!"
val genProductName: Gen[ProductName] = for {
cs <- Gen.nonEmptyListOf(Gen.alphaNumChar)
name = RefType.applyRef[ProductName](cs.mkString)
.getOrElse(DefaultProductName)
} yield name