Details
-
Bug
-
Status: Open
-
Major
-
Resolution: Unresolved
-
2.5.7
-
None
-
None
Description
When defining a mockFor on a class with static methods, if you ignore a method which invokes a demand mocked method. The demand is not intercepted.
Here is an example modified from the MockFor documentation:
import groovy.mock.interceptor.MockFor class Person { static def ignoreMe(foo) { foo } static def ignoreMeToo() { ignoreMe('foo') } static def ignoreMeThree() { ignoreMe('foo') } } def mock = new MockFor(Person) mock.ignore('ignoreMeToo') mock.ignore('ignoreMeThree') mock.demand.ignoreMe { s -> 'baz' } mock.use { assert Person.ignoreMe('foo') == 'baz' assert Person.ignoreMeToo() == 'baz' assert Person.ignoreMeThree() == 'baz' }
Running this will result in a failure as Person.ignoreMeToo() returns `foo` instead of `baz`.
Use Case: Mocking nested static method calls. I want to test a particular method. I know/expect that method to invoke another static method on the same class, but I want to mock that one, and return an expected value.