@Test public void testGet() throws Exception { IMocksControl control = createControl(); Response resp = control.createMock(Response.class); expect(resp.getStatus()).andReturn(200).times(3); Capture<Class<CloudantToDo>> classCapture = new Capture<Class<CloudantToDo>>(); expect(resp.readEntity(capture(classCapture))).andReturn(ctd1); replay(resp); WebTarget wt = createMockWebTarget(); Invocation.Builder builder = createBuilder(); expect(builder.get()).andReturn(resp).times(3); 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.path(eq("123"))).andReturn(wt); expect(wt.request(eq("application/json"))).andReturn(builder).anyTimes(); replay(wt); CloudantStore store = new CloudantStore(wt); assertEquals(ctd1.getToDo(), store.get("123")); assertEquals(CloudantToDo.class, classCapture.getValue()); verify(resp); verify(wt); verify(builder); }
@Override public ToDo get(String id) throws ToDoStoreException { Response docResp = getRequest(id); int status = docResp.getStatus(); if(status == HttpURLConnection.HTTP_OK) { CloudantToDo td = docResp.readEntity(CloudantToDo.class); return td.getToDo(); } else { throw new ToDoStoreException("There was an error retrieving the doc with id " + id + "from Cloudant. Error " + status); } }
CloudantStore implements ToDoStore { @Override public ToDo get(String id) throws ToDoStoreException { Response docResp = getRequest(id); int status = docResp.getStatus(); if(status == HttpURLConnection.HTTP_OK) { CloudantToDo td = docResp.readEntity(CloudantToDo.class); return td.getToDo(); } else { throw new ToDoStoreException("There was an error retrieving the doc with id " + id + "from Cloudant. Error " + status); } } }
CloudantStore implements ToDoStore { @Override public ToDo get(String id) throws ToDoStoreException { Response docResp = getRequest(id); int status = docResp.getStatus(); if(status == HttpURLConnection.HTTP_OK) { CloudantToDo td = docResp.readEntity(CloudantToDo.class); return td.getToDo(); } else { throw new ToDoStoreException("There was an error retrieving the doc with id " + id + "from Cloudant. Error " + status); } } CloudantStore(WebTarget target); }
CloudantStore implements ToDoStore { @Override public ToDo get(String id) throws ToDoStoreException { Response docResp = getRequest(id); int status = docResp.getStatus(); if(status == HttpURLConnection.HTTP_OK) { CloudantToDo td = docResp.readEntity(CloudantToDo.class); return td.getToDo(); } else { throw new ToDoStoreException("There was an error retrieving the doc with id " + id + "from 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(); }
CloudantStore implements ToDoStore { @Override public ToDo get(String id) throws ToDoStoreException { Response docResp = getRequest(id); int status = docResp.getStatus(); if(status == HttpURLConnection.HTTP_OK) { CloudantToDo td = docResp.readEntity(CloudantToDo.class); return td.getToDo(); } else { throw new ToDoStoreException("There was an error retrieving the doc with id " + id + "from 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();  }