Is there a clean method of mocking a class with generic parameters? Say I have to mock a class Foo
which I need to pass into a method that expects a <
As the other answers mentioned, there's not a great way to use the mock()
& spy()
methods directly without unsafe generics access and/or suppressing generics warnings.
There is currently an open issue in the Mockito project (#1531) to add support for using the mock()
& spy()
methods without generics warnings. The issue was opened in November 2018, but there aren't any indications whether it will be prioritized.