public void testQueryAccounts() throws PersistenceException, IOException { // Mock data accountStore.putAccount(ACCOUNT_JOE); accountStore.putAccount(ACCOUNT_TOM); accountStore.putAccount(ACCOUNT_MAT); when(sessionManager.getLoggedInUser((HttpSession) anyObject())).thenReturn(ACCOUNT_MAT.getId()); when(sessionManager.getLoggedInUser((HttpServletRequest) anyObject())).thenReturn( ACCOUNT_MAT.getId()); when(sessionManager.listLoggedInUsers((HttpServletRequest) anyObject())).thenReturn(CollectionUtils.immutableSet(ACCOUNT_MAT.getId())); // Test AccountServiceData requestData = new AccountServiceData(); ByteArrayOutputStream responseStream = new ByteArrayOutputStream(); executeService("/account", "GET", requestData, responseStream, HttpServletResponse.SC_OK, ImmutableMap.<String, String> of("p", "joe@example.com;tom@example.com;mike@example.com;mat@example.com")); AccountServiceData[] responseData = (AccountServiceData[]) ServiceData.arrayFromJson(responseStream.toString("UTF-8"), AccountServiceData[].class); assertEquals(4, responseData.length); // We expect results in the same order as query assertEqualsAccount(ACCOUNT_JOE, responseData[0]); assertEqualsAccount(ACCOUNT_TOM, responseData[1]); assertEqualsAccount(ACCOUNT_MIKE, responseData[2]); assertEqualsAccount(ACCOUNT_MAT, responseData[3]); }