I use the Mockito framework to mock the general class in Java. Using structure seems to be pretty clear from the documentation; I have not found an example for mocking general classes. The layout structure contains the following method:
public static <T> T mock(Class<T> classToMock) {
...
}
I have a generic type IState<StateId, Event>, and I want to create it using the method described above. I tried the following:
IState<StateId, Event> mockState = Mockito.mock(IState.class);
I get the following warning for this code:
Type safety: The expression of type IState needs unchecked conversion to conform to IState<StateId,Event>
I think I know what the problem is. The method mockreturns a type IState, but the variable that I assign is a specialized type IState<StateId, Event>, so for some reason I need to say that the class that I create is special IState<StateId, Event>, but I do not know what the syntax for this is. I tried the following, but they all gave syntax errors.
IState<StateId, Event> mockState = Mockito.mock(IState<StateId, Event>.class);
IState<StateId, Event> mockState = Mockito.mock(IState.class<StateId, Event>);