I have a test where I want to test a specific result to be of a kind of a class. Asserting this with the instanceof keyword. Sadly I did not figured out how to actually provide a data value expectedClass in the data table without having a Problem to actually call it with instanceof. I think the keyword instanceof is the issue here because it only accepts class/interface names. Any idea how I can test what I want to test in another way?
class BattleResolverFactoryTest extends Specification {
def uut = new BattleResolverFactory()
@Unroll
def "should return proper BattleResolver for given ConflictType"(Conflict.ConflictType conflictType, Class<? extends BattleResolver> expectedInstance) {
when:
def battleResolver = BattleResolverFactory.getResolver(conflictType)
then:
battleResolver instanceof expectedClass
where:
conflictType | expectedClass
Conflict.ConflictType.INFANTRY_CONFLICT | TestInfantryResolver
Conflict.ConflictType.ARMOR_CONFLICT | TestArmorResolver
}
}
in
keyword, the usage would be reversed. It would actually bebattleResolver in expectedClass
– Allfired