fixture-monkey
fixture-monkey copied to clipboard
Support for interface
It seems that FixtureMonkey always returns null for an interface arbitrary builder.
Is there any chance to support interface arbitrary builder?
If it is hard to scan implementation candidates automatically, you can just let users to give the candidates.
If we have an interface I and it's implementations A, B and C, it would be great to support this kind of feature.
(Please consider my code as a kotlin-like pseudo code.)
interface I
class A : I
class B : I
class C : I
val fixtureMonkey: FixtureMonkey
@Test
fun generateI() {
val sampled: I = fixtureMonkey.giveMeBuilder<I>()
.sample() // return null or throw an exception
}
@Test
fun generateAOrB() {
val builder: ArbitraryBuilder<I> = fixtureMonkey.giveMeBuilder<I>(A::class.java, B::class.java)
val sampled1: I = builder.sample() // return an instance of A or B
val sampled2: I = builder.sample() // return an instance of A or B
then(sampled1).is {
it is A || it is B
}
then(sampled2).is {
it is A || it is B
}
then(sampled1).isNotEqualTo(sampled2)
}
Thanks!