I need to mock a Cursor for some content provider unit tests, but the addRow method is not working for some strange reason. After adding a row, the count always remains 0.
What am I missing?
@Test
fun addCursorTest() {
val columns: Array<String> = arrayOf(
"name",
"age"
)
val matrixCursor : Cursor = MatrixCursor(columns).apply {
addRow(arrayOf("name1", 18))
addRow(arrayOf("name2", 26))
}
println("cursor count = ${matrixCursor.count}") //prints "cursor count = 0"
assertEquals(2, matrixCursor.count)
}
If you omit the
assertEqualsand the @Test then there is no issue.i.e. using:-
@SuppressLint("Range")added as for whatever reason the potential for a -1 (column not found result fromgetColumnIndex(the_column)results in a range error, of course just will not happen when traversing the columns in the actual Cursor unless the Cursor has been corrupted)results in the log including:-
You may wish to refer to assertEquals not working as expected with Set in Kotlin