FileViewer { @GET @Path("{filename}/json") @Produces(MediaType.APPLICATION_JSON) public Response json(@PathParam("filename") final String file) { try { String fileContents = read(file); JSONStringer json = new JSONStringer(); json.object().key(file).value(fileContents).endObject(); return Response.status(200).entity(json.toString()).build(); } catch (JSONException e) { return Response.status(500).entity("Internal error").build(); } }  @GET @Path("{filename}") @Produces(MediaType.TEXT_PLAIN) Response get(@PathParam("filename") final String file); @GET @Path("list") @Produces(MediaType.TEXT_PLAIN) Response list(); @GET @Path("{filename}/json") @Produces(MediaType.APPLICATION_JSON) Response json(@PathParam("filename") final String file);  }
@Test public void shouldGetFileAsJson() { Response response = fileViewer.json(getAvailableFile()); Assert.assertEquals(200, response.getStatus()); Assert.assertNotSame("", response.getEntity()); Assert.assertTrue(((String) response.getEntity()).startsWith("{")); Assert.assertTrue(((String) response.getEntity()).endsWith("}")); }