@Test
public void testSendQueuedEvents() throws Exception {

    // Mock the response from the server.
    Map<String, Integer> expectedResponse = new HashMap<String, Integer>();
    expectedResponse.put(TEST_COLLECTION, 3);
    setMockResponse(200, getPostEventsResponse(buildSuccessMap(expectedResponse)));
    // Queue some events.
    client.queueEvent(TEST_COLLECTION, TEST_EVENTS.get(0));
    client.queueEvent(TEST_COLLECTION, TEST_EVENTS.get(1));
    client.queueEvent(TEST_COLLECTION, TEST_EVENTS.get(2));
    // Check that the expected number of events are in the store.
    RamEventStore store = (RamEventStore) client.getEventStore();
    Map<String, List<Object>> handleMap = store.getHandles(TEST_PROJECT.getProjectId());
    assertEquals(1, handleMap.size());
    assertEquals(3, handleMap.get(TEST_COLLECTION).size());
    // Send the queued events.
    client.sendQueuedEvents();
    // Validate that the store is now empty.
    handleMap = store.getHandles(TEST_PROJECT.getProjectId());
    assertEquals(0, handleMap.size());
    // Try sending events again; this should be a no-op.
    setMockResponse(200, "{}");
    client.sendQueuedEvents();
    // Validate that the store is still empty.
    handleMap = store.getHandles(TEST_PROJECT.getProjectId());
    assertEquals(0, handleMap.size());
}