### Question:
EventRecorder { public Uri recordEvent(final AnalyticsEvent event) { if (event == null) { log.warn("Event cannot be null. Pass in a valid non-null event."); return null; } log.info(String.format("Event Recorded to database with EventType: %s", StringUtil.clipString(event.getEventType(), clippedEventLength, true))); long maxPendingSize = pinpointContext.getConfiguration().optLong(KEY_MAX_PENDING_SIZE, DEFAULT_MAX_PENDING_SIZE); if (maxPendingSize < MINIMUM_PENDING_SIZE) { maxPendingSize = MINIMUM_PENDING_SIZE; } final Uri uri = this.dbUtil.saveEvent(event); if (uri != null) { while (this.dbUtil.getTotalSize() > maxPendingSize) { Cursor cursor = null; try { cursor = this.dbUtil.queryOldestEvents(5); while (this.dbUtil.getTotalSize() > maxPendingSize && cursor.moveToNext()) { this.dbUtil.deleteEvent( cursor.getInt(EventTable.COLUMN_INDEX.ID.getValue()), cursor.getInt(EventTable.COLUMN_INDEX.SIZE.getValue())); } } finally { if (cursor != null) { cursor.close(); } } } return uri; } else { log.warn(String.format("Event: '%s' failed to record to local database.", StringUtil.clipString(event.getEventType(), clippedEventLength, true))); return null; } } EventRecorder(final PinpointContext pinpointContext,
                  final PinpointDBUtil dbUtil,
                  final ExecutorService submissionRunnableQueue); static EventRecorder newInstance(final PinpointContext pinpointContext); static EventRecorder newInstance(final PinpointContext pinpointContext, final PinpointDBUtil dbUtil); static void setClippedEventLength(final int clippedEventLength); void closeDB(); Uri recordEvent(final AnalyticsEvent event); void submitEvents(); List<JSONObject> getAllEvents();  }### Answer:
@Test public void testRecordEvent() throws JSONException { final Uri uri = eventRecorder.recordEvent(analyticsEvent); final int idInserted = Integer.parseInt(uri.getLastPathSegment()); assertNotEquals(idInserted, 0); final Cursor c = dbUtil.queryEventById(idInserted); assertNotNull(c); assertEquals(c.getCount(), 1); while (c.moveToNext()) { final JSONObject obj = eventRecorder.readEventFromCursor(c, null); assertEquals(obj.getInt("databaseId"), 1); obj.remove("databaseId"); assertEquals(obj.toString(), analyticsEvent.toJSONObject().toString()); dbUtil.deleteEvent(c.getInt(EventTable.COLUMN_INDEX.ID.getValue()), c.getInt(EventTable.COLUMN_INDEX.SIZE .getValue())); } c.close(); }
@Test public void testTrimming() { final List<Uri> uris = new ArrayList<Uri>(); for (int i = 0; i < 100; i++) { uris.add(eventRecorder.recordEvent(analyticsEvent)); assertTrue(dbUtil.getTotalSize() <= 16 * 1024); } Boolean existing = null; for (final Uri uri : uris) { final Cursor c = dbUtil.queryEventById(Integer.parseInt(uri.getLastPathSegment())); if (c.moveToNext()) { assertTrue(existing != null); dbUtil.deleteEvent(c.getInt(EventTable.COLUMN_INDEX.ID .getValue()), c.getInt(EventTable.COLUMN_INDEX.SIZE .getValue())); existing = true; } else { assertTrue(existing == null || !existing); existing = false; } } assertTrue(dbUtil.getTotalSize() == 0); }