@Test(expected = EmptySession.class) public void listAllThrowsEmpySession() throws EmptySession, EmptyUsername, EmptyResponse, InvalidFormat, InvalidResponse, APIError, RequestFailed, InvalidUsername { Task task = setUp(); task.storage.purgeSession(); replay(task); task.listAll(); }
@Test(expected = EmptyUsername.class) public void detailsThrowsEmptyUsername() throws EmptySession, EmptyUsername, EmptyResponse, InvalidFormat, InvalidResponse, APIError, RequestFailed, InvalidUsername { Task task = setUp(); task.storage.setUsername(""); replay(task); task.details(123); }
public Task setUp() { Task task = EasyMock.createMockBuilder(Task.class) .addMockedMethod("fetch", String.class, String.class) .createMock(); task.storage = new Storage(); task.storage.purgeSession(); task.storage.setSessionToken("token"); task.storage.setUsername("username"); return task; }
@Test public void detailsReturnsJson() throws ParseException, EmptyResponse, InvalidFormat, InvalidResponse, APIError, RequestFailed, EmptySession, EmptyUsername, InvalidUsername { Task task = setUp(); JSONParser parser = new JSONParser(); JSONObject json = (JSONObject) parser.parse("{\"info\":{\"info\":\"info\"}}"); expect(task.fetch(isA(String.class), isA(String.class))).andReturn(json); replay(task); JSONObject obj = (JSONObject) parser.parse("{\"info\":\"info\"}"); assertEquals(obj, task.details(123)); }
@Test public void listAllReturnsArray() throws ParseException, EmptyResponse, InvalidFormat, InvalidResponse, APIError, RequestFailed, EmptySession, EmptyUsername, InvalidUsername { Task task = setUp(); JSONParser parser = new JSONParser(); JSONObject json = (JSONObject) parser.parse("{\"list\":[\"response\"]}"); expect(task.fetch(isA(String.class), isA(String.class))).andReturn(json); replay(task); JSONArray array = new JSONArray(); array.add("response"); assertEquals(array, task.listAll()); }