AppStoreController { @POST @Path("register") @Produces(MediaType.APPLICATION_JSON) public Response register(Application app) { try { if (app.getName()==null) { throw new IOException("Application name can not be empty."); } if (app.getOrganization()==null) { throw new IOException("Application organization can not be empty."); } if (app.getDescription()==null) { throw new IOException("Application description can not be empty."); } AppCatalogSolrClient sc = new AppCatalogSolrClient(); sc.register(app); } catch (IOException e) { return Response.status(Status.BAD_REQUEST).entity(e.getMessage()).build(); } return Response.status(Status.ACCEPTED).build(); } AppStoreController(); @GET @Path("recommended") @Produces(MediaType.APPLICATION_JSON) List<AppStoreEntry> get(); @GET @Path("search") @Produces(MediaType.APPLICATION_JSON) List<AppStoreEntry> search(@QueryParam("q") String keyword); @GET @Path("get/{id}") @Produces(MediaType.APPLICATION_JSON) AppStoreEntry get(@PathParam("id") String id); @POST @Path("register") @Produces(MediaType.APPLICATION_JSON) Response register(Application app);  }
@Test public void testRegister() throws Exception { AppStoreController ac = Mockito.mock(AppStoreController.class); Application app = new Application(); app.setName("jenkins"); app.setOrganization("jenkins.org"); app.setDescription("This is a description"); app.setIcon("/css/img/feather.png"); Response expected = Response.ok().build(); when(ac.register(app)).thenReturn(Response.ok().build()); final Response actual = ac.register(app); assertEquals(expected.getStatus(), actual.getStatus()); }