### Question:
CloudantStore implements ToDoStore { @Override public ToDo persist(ToDo td) throws ToDoStoreException { Response newdoc = target.request(MediaType.APPLICATION_JSON).post(Entity.entity(td, MediaType.APPLICATION_JSON)); int status = newdoc.getStatus(); if(status == HttpURLConnection.HTTP_CREATED) { CloudantPostResponse post = newdoc.readEntity(CloudantPostResponse.class); td.setId(post.getId()); return td; } else { throw new ToDoStoreException("There was an error POSTing the ToDo to Cloudant. Error " + status); } } CloudantStore(WebTarget target); @Override Collection<ToDo> getAll(); @Override ToDo get(String id); @Override ToDo persist(ToDo td); @Override ToDo update(String id, ToDo td); @Override void delete(String id); @Override int count();  }### Answer:
@Test public void testPersist() throws Exception { IMocksControl control = createControl(); Response resp = control.createMock(Response.class); expect(resp.getStatus()).andReturn(200).times(2); expect(resp.getStatus()).andReturn(201); CloudantPostResponse postResp = new CloudantPostResponse(); postResp.setId("123"); postResp.setOk(true); postResp.setRev("abc"); Capture<Class<CloudantPostResponse>> classCapture = new Capture<Class<CloudantPostResponse>>(); expect(resp.readEntity(capture(classCapture))).andReturn(postResp); replay(resp); WebTarget wt = createMockWebTarget(); Invocation.Builder builder = createBuilder(); ToDo td = new ToDo(); td.setTitle("this is a test"); expect(builder.post(isA(Entity.class))).andReturn(resp); expect(builder.get()).andReturn(resp).times(2); replay(builder); expect(wt.path(eq("bluemix-todo"))).andReturn(wt).times(2); expect(wt.path(eq("todos"))).andReturn(wt); expect(wt.path(eq("_design"))).andReturn(wt).times(1); expect(wt.request(eq("application/json"))).andReturn(builder).anyTimes(); replay(wt); CloudantStore store = new CloudantStore(wt); ToDo testTd = new ToDo(); testTd.setTitle("this is a test"); testTd.setId("123"); assertEquals(testTd, store.persist(td)); assertEquals(CloudantPostResponse.class, classCapture.getValue()); verify(resp); verify(wt); verify(builder); }