4
I have a class of services that will receive a dependency injection from an object responsible for the persistence layer. In this service class are all my methods that will answer the web service’s REST call.
The problem is:
I would need to test the service class by calling the REST web service path’s, but I would need to mock the persistence part dependency injection, because right now I just want to test the service layer. All this using junit and mockito, at most using something like spring. I would like to know from colleagues if this is possible? If yes, an idea of what I should do?
Below an example:
@Path("/servico")
public class Servico() {
Persistencia persistencia;
@GET
@Path("/get")
@Produces("application/json")
public Response get(long id) {
Entidade entidade = persistencia.get(id);
return Response.ok().entity(entidade).build();
}
}
Thanks Joshua Eduardo for the explanation and the frameworks tips, I’ll take a look at them.
– erms