SQLiteUtils { public static void safeCloseCursor(@Nullable Cursor cursor) { if (cursor == null || cursor.isClosed()) { return; } try { cursor.close(); } catch (Exception ignored) { } } private  SQLiteUtils(); static boolean isTableEmpty(@NonNull Table<T> table); static boolean isEmptyCursor(@Nullable Cursor cursor); static void safeCloseCursor(@Nullable Cursor cursor);  }
@Test public void testCloseNullCursor() throws Exception { SQLiteUtils.safeCloseCursor(null); }
@Test public void testClosedCursor() throws Exception { Cursor cursor = mock(Cursor.class); when(cursor.isClosed()).thenReturn(true); SQLiteUtils.safeCloseCursor(cursor); verify(cursor, never()).close(); }
@Test public void testExceptionCursor() throws Exception { Cursor cursor = mock(Cursor.class); when(cursor.isClosed()).thenReturn(false); doThrow(new RuntimeException()).when(cursor).close(); SQLiteUtils.safeCloseCursor(cursor); }
@Test public void testCloseCursor() throws Exception { Cursor cursor = mock(Cursor.class); when(cursor.isClosed()).thenReturn(false); doNothing().when(cursor).close(); SQLiteUtils.safeCloseCursor(cursor); verify(cursor).close(); }