Open zbynek opened 3 years ago
@ekuefler could you please check this PR?
Thanks for the PR. I see the value of this but am hesitant to expose any API in StubGenerator - like the javadoc in that class mentions, that class (and the rest of the impl package) is intended to be called only by generated code and not invoked by users directly. There might also be some unexpected behavior since StubGenerator is invoked only in certain circumstances: https://github.com/google/gwtmockito/blob/06b21bbcff700f791984e1d271ec21fa7ab13c0a/gwtmockito/src/main/java/com/google/gwtmockito/GwtMockitoTestRunner.java#L449
Do you think it would be possible to expose this API via a protected method on GwtMockitoTestRunner that users could override? Something like getMethodsToReplace
that returns a collection of ReplacementMethod
s, which each defines a class, name, and implementation function? GwtMockitoTestRunner could then consult that method before going through the internal stub generator.
When used with Elemental it's quite handy to be able to override
Js.asPropertyMap
and other static methods to return something remotely useful. Providing list of such methods is not in the scope of this PR, but by exposing the necessary API anyone can subclass GwtMockitoRunner and mock the methods in their implementation. The alternative -- mocking those methods using powermock or mockito inline -- is very cumbersome because of the different classsloaders.