Как мы можем издеваться над IRouteHandlerRegistry
? Ошибка Cannot resolve method thenReturn(IHandleRoute<TestRoute>)
Как обмануть общий метод в Java с помощью Mockito?
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 my test
RouteDefinition route = new TestRoute(); // TestRoute implements RouteDefinition
IRouteHandlerRegistry registry = mock(IRouteHandlerRegistry.class);
IHandleRoute<TestRoute> handler = mock(IHandleRoute.class);
// Error: Cannot resolve method 'thenReturn(IHandleRoute<TestRoute>)'
when(registry.getHandlerFor(route)).thenReturn(handler);
}
Что такое 'SutFactory'? –
Можете ли вы объяснить, что об этом не работает? Какая ошибка/предупреждение вы получаете? –