EventResolver extends UrbanAirshipResolver { @NonNull Map<String, String> getEvents(int count) { HashMap<String, String> events = new HashMap<>(count); String[] columns = new String[] { EventsStorage.Events.COLUMN_NAME_EVENT_ID, EventsStorage.Events.COLUMN_NAME_DATA }; Uri eventsUri = uri.buildUpon().appendQueryParameter(UrbanAirshipProvider.QUERY_PARAMETER_LIMIT, String.valueOf(count)).build(); Cursor cursor = query(eventsUri, columns, null, null, ASCENDING_SORT_ORDER); if (cursor == null) { return events; } cursor.moveToFirst(); while (!cursor.isAfterLast()) { events.put(cursor.getString(0), cursor.getString(1)); cursor.moveToNext(); } cursor.close(); return events; } EventResolver(@NonNull Context context);  @NonNull
    static final String ASCENDING_SORT_ORDER; }
@Test public void testGetEvents() { eventResolver.insertEvent(new TestEvent("oldest-id"), UUID.randomUUID().toString()); eventResolver.insertEvent(new TestEvent("older-id"), UUID.randomUUID().toString()); eventResolver.insertEvent(new TestEvent("newer-id"), UUID.randomUUID().toString()); assertEquals(3, eventResolver.getEventCount()); Map<String, String> eventData = eventResolver.getEvents(2); assertEquals(2, eventData.size()); assertTrue(eventData.containsKey("oldest-id")); assertTrue(eventData.containsKey("older-id")); }
@Test public void testGetEventsEmptyDatabase() { Map<String, String> eventData = eventResolver.getEvents(300); assertEquals(0, eventData.size()); }