### Question:
CassandraInstanceResource { @GET @Path("{id}") public CassandraInstance findById(@PathParam("id") int id) { return getByIdIfFound(id); } @Inject  CassandraInstanceResource(CassandraInstanceService service, @Assisted CassandraRing ring); @GET Set<CassandraInstance> findAll(); @POST Response createInstance(@Valid CassandraInstance instance); @GET @Path("{id}") CassandraInstance findById(@PathParam("id") int id); @DELETE @Path("{id}") Response deleteInstance(@PathParam("id") int id);  }### Answer:
@Test public void findById() throws Exception { CassandraInstance instance = createMock(CassandraInstance.class); expect(service.findById(RING_NAME, CASSANDRA_ID)).andReturn(instance); replayAll(); assertEquals(instance, resource.findById(CASSANDRA_ID)); }
@Test public void findById_notFound() throws Exception { expect(service.findById(RING_NAME, CASSANDRA_ID)).andReturn(null); replayAll(); try { resource.findById(CASSANDRA_ID); fail("Expected NotFoundException"); } catch (NotFoundException e) { assertEquals(Status.NOT_FOUND.getStatusCode(), e.getResponse().getStatus()); assertEquals("No instance found with id: " + CASSANDRA_ID, e.getResponse().getEntity()); } }