SQLiteUtils { public static boolean isEmptyCursor(@Nullable Cursor cursor) { if (cursor == null) { return true; } if (cursor.isClosed()) { return true; } return !cursor.moveToFirst(); } private  SQLiteUtils(); static boolean isTableEmpty(@NonNull Table<T> table); static boolean isEmptyCursor(@Nullable Cursor cursor); static void safeCloseCursor(@Nullable Cursor cursor);  }
@Test public void testCursorEmptyNull() throws Exception { boolean isEmpty = SQLiteUtils.isEmptyCursor(null); assertTrue(isEmpty); }
@Test public void testCursorEmptyClosed() throws Exception { Cursor cursor = mock(Cursor.class); when(cursor.isClosed()).thenReturn(true); boolean isEmpty = SQLiteUtils.isEmptyCursor(cursor); assertTrue(isEmpty); }
@Test public void testCursorEmpty() throws Exception { Cursor cursor = mock(Cursor.class); when(cursor.isClosed()).thenReturn(true); when(cursor.moveToFirst()).thenReturn(false); boolean isEmpty = SQLiteUtils.isEmptyCursor(cursor); assertTrue(isEmpty); }
@Test public void testCursorNotEmpty() throws Exception { Cursor cursor = mock(Cursor.class); when(cursor.isClosed()).thenReturn(false); when(cursor.moveToFirst()).thenReturn(true); boolean isEmpty = SQLiteUtils.isEmptyCursor(cursor); assertFalse(isEmpty); }