я пытаюсь зарегистрировать и получить эти журналы в модульном тесте в Android, но внутри я получаю исключение ClassCastException
public Cursor rawQuery(String sql, String[] selectionArgs,
int initialRead, int maxRead) {
SQLiteCursor c = (SQLiteCursor)rawQueryWithFactory(
null, sql, selectionArgs, null);
c.setLoadStyle(initialRead, maxRead);
return c;
}
Что логично, потому что rawQueryWithFactory, как и другие методы rawquery, возвращает CrossProcessCursorWrapper (реализующий интерфейс Cursor).
public Cursor rawQueryWithFactory(CursorFactory cursorFactory, String sql, String[] selectionArgs, String editTable) {
//doing stuff
// CrossProcessCursorWrapper implements the Cursor interface as SQLiteCursor but is not of SQLiteCursor type.
return new CrossProcessCursorWrapper(cursor);
}
Этот код взят из net.sqlcipher.database.SQLiteDatabase (Commit: c2aa13e490499482ab38075994cad327d2561749 [c2aa13e]).
ОБНОВИТЬ :
Вот мой код:
dbHelper = new LoggingRecordDBHelper(context, null);
db = dbHelper.getWritableDatabase("pass");
Cursor cursor = db.rawQuery(dbHelper.SQL_LOGGINGRECORD_SELECT_ALL, null);
И журналы:
Выполнение тестов Тест запущен java.lang.ClassCastException: net.sqlcipher.CrossProcessCursorWrapper не может быть приведен к net.sqlcipher.database.SQLiteCursor
в сети.sqlcipher.database.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1485)
в com.eventmanagement.SQLCipherFetcher.getLogRecords(SQLCipherFetcher.java:31)
в com.eventmanagement.ApplicationTest.testReadLogs(ApplicationTest.java:64)
в java.lang.reflect.Method.invokeNative (собственный метод)
в android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:191)
в android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:176)
в android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:554)
в android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1738)