Using Mockito to mock classes with generic parameters

后端 未结 7 1901
不知归路
不知归路 2020-11-30 19:37

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 <

7条回答
  •  情话喂你
    2020-11-30 19:51

    I agree that one shouldn't suppress warnings in classes or methods as one could overlook other, accidentally suppressed warnings. But IMHO it's absolutely reasonable to suppress a warning that affects only a single line of code.

    @SuppressWarnings("unchecked")
    Foo mockFoo = mock(Foo.class);
    

提交回复
热议问题