Can Groovy/Spock mock both a method and the interface implementation at the same time in Kotlin?

Viewed 260

The mocked class is defined as follows:

interface SomeInterface {
    val somethingCommon: String
}
class SomeClass(val somethingSpecific: String) : SomeInterface {
    override val somethingCommon: String
      get() = somethingSpecific
}

The code under test mocks SomeClass and internally uses both the specific property, and the common interface. Unfortunately mocking just the specific property does not mock the associated interface method so it seems necessary to mock both:

def thing = Mock(SomeClass)
thing.somethingSpecific >> "blah"
thing.somethingCommon >> "blah"

Is there a way in Kotlin/Groovy/Spock to avoid having to stub both methods? The best I have come up with is to stub one with the other, which works, but is unfortunate:

def thing = Mock(SomeClass)
thing.somethingSpecific >> "blah"
thing.somethingCommon >> thing.somethingSpecific
1 Answers
Related