I am trying to get used Mockito.
I have a class
@Provider
public class SessionProvider implements InjectableProvider<Bind, Type>{
@Override
public ComponentScope getScope() {
return ComponentScope.PerRequest;
}
@Override
public Injectable getInjectable(ComponentContext ic, Bind bind, Type parameter) {
return new SessionInjectable();
}
}
And trying to return null when getInjectable is called.
My use case is like so
public void addProvider(Class<?> klass) {
providers.add(klass);
}
addProvider(SessionProvider.class);
How can I successfully mock SessionProvider.class?
Thanks
Edit:
My class is like so:
@Path("message")
@Produces(MediaType.APPLICATION_JSON)
public class MessageResource {
@POST
@Path("post")
public String testPostMessage(@Bind Session session, Message message) {
return "posted";
}
}
Bind annotation is using my provider. But my current framework does not accept instances of SessionProvider. It is utilizing Class instances.
By the way this is a web service. It is called by my client implementation. I would like to test my message with a mocked session. And for each request it is requested a new one. That is the reason the method is accepting Session Class instead of Session Instance.
I really started to feel that there is something wrong but at where?
Thanks
By default a mock return
null:For a unit test, you can test
MessageResourceby invokingtestPostMessagewith mocks :or, you could create a mock
SessionProviderclass returning a mockSession:and then register it on the framework :