Test Class
Class TestClass{
@Autowired
AnyClass anyClass
boolean testMethod() {
boolean result = anyClass.method()
if(result) {
return !result
}
else {
return !result
}
}
}
My Spock
class TestClassSpec implements Specification {
AnyClass anyClass = Mock()
TestClass testClass = new TestClass(anyClass: anyClass)
def "check if opposite of result is returned"() {
given:
anyClass.method >> {return true}
when:
boolean result = testClass.testMethod()
then:
result == false
}
}
The result variable is always null when I try to debug. Is there anyway I can inject values into result variable without changing the original Test class?