### Question:
EventRecorder { JSONObject readEventFromCursor(final Cursor cursor, final HashMap<Integer, Integer> idsAndSizeToDelete) { Integer rowId = null; Integer size = null; try { if (cursor.isNull(ID_COLUMN_INDEX)) { log.error("Column 'ID' for event was NULL."); return null; } else { rowId = cursor.getInt(ID_COLUMN_INDEX); } if (cursor.isNull(SIZE_COLUMN_INDEX)) { log.error("Column 'SIZE' for event was NULL."); } else { size = cursor.getInt(SIZE_COLUMN_INDEX); } JSONObject jsonObject = null; if (cursor.isNull(JSON_COLUMN_INDEX)) { log.error(String.format(Locale.US, "Event from DB with ID=%d and SiZE=%d contained a NULL message.", rowId, size)); } else { final String message = cursor.getString(JSON_COLUMN_INDEX); try { jsonObject = new JSONObject(message); jsonObject.put(DATABASE_ID_KEY,rowId); } catch (final JSONException e) { log.error(String.format(Locale.US, "Unable to deserialize event JSON for event with ID=%d.", rowId)); } if (size != null && message.length() != size) { log.warn(String.format(Locale.US, "Message with ID=%d has a size mismatch. DBMsgSize=%d DBSizeCol=%d", rowId, message.length(), size)); size = null; } } return jsonObject; } catch (final Exception ex) { log.error("Failed accessing cursor to get next event.", ex); } finally { if (rowId != null && idsAndSizeToDelete != null) { idsAndSizeToDelete.put(rowId, size); } } 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 (expected=IllegalStateException.class) public void testReadEventFromCursorThrowsException() throws Exception { final Log mockLog = mock(Log.class); Mockito.doThrow(new IllegalStateException()).when(mockLog) .error(Mockito.anyObject(), any(IllegalStateException.class)); final Field field = EventRecorder.class.getDeclaredField("log"); field.setAccessible(true); Field modifiersField = Field.class.getDeclaredField("modifiers"); modifiersField.setAccessible(true); modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL); field.set(null, mockLog); final Cursor mockCursor = mock(Cursor.class); when(mockCursor.getString(Mockito.anyInt())) .thenThrow(new IllegalStateException( "Couldn't read row 794, col 2 from CursorWindow. Make sure the Cursor" + " is initialized correctly before accessing data from it.")); eventRecorder.readEventFromCursor(mockCursor, null); }