How to mock generic method in Java with Mockito?
问题 How can we mock the IRouteHandlerRegistry ? The error is Cannot resolve method thenReturn(IHandleRoute<TestRoute>) public interface RouteDefinition { } public class TestRoute implements RouteDefinition { } public interface IHandleRoute<TRoute extends RouteDefinition> { Route getHandlerFor(TRoute route); } public interface IRouteHandlerRegistry { <TRoute extends RouteDefinition> IHandleRoute<TRoute> getHandlerFor(TRoute route); } @Test @SuppressWarnings("unchecked") public void test() { // in