1 /* 2 * Copyright (C) 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package androidx.core.database 18 19 import android.database.Cursor 20 import android.database.MatrixCursor 21 import androidx.test.filters.SmallTest 22 import org.junit.Assert.assertNull 23 import org.junit.Test 24 25 @SmallTest 26 class CursorTest { 27 @Test blobOrNullByIndexnull28 fun blobOrNullByIndex() { 29 val cursor = scalarCursor(null) 30 val blob = cursor.getBlobOrNull(0) 31 assertNull(blob) 32 } 33 34 @Test doubleOrNullByIndexnull35 fun doubleOrNullByIndex() { 36 val cursor = scalarCursor(null) 37 val double = cursor.getDoubleOrNull(0) 38 assertNull(double) 39 } 40 41 @Test floatOrNullByIndexnull42 fun floatOrNullByIndex() { 43 val cursor = scalarCursor(null) 44 val float = cursor.getFloatOrNull(0) 45 assertNull(float) 46 } 47 48 @Test intOrNullByIndexnull49 fun intOrNullByIndex() { 50 val cursor = scalarCursor(null) 51 val int = cursor.getIntOrNull(0) 52 assertNull(int) 53 } 54 55 @Test longOrNullByIndexnull56 fun longOrNullByIndex() { 57 val cursor = scalarCursor(null) 58 val long = cursor.getLongOrNull(0) 59 assertNull(long) 60 } 61 62 @Test shortOrNullByIndexnull63 fun shortOrNullByIndex() { 64 val cursor = scalarCursor(null) 65 val short = cursor.getShortOrNull(0) 66 assertNull(short) 67 } 68 69 @Test stringOrNullByIndexnull70 fun stringOrNullByIndex() { 71 val cursor = scalarCursor(null) 72 val string = cursor.getStringOrNull(0) 73 assertNull(string) 74 } 75 scalarCursornull76 private fun scalarCursor(item: Any?): Cursor = 77 MatrixCursor(arrayOf("data")).apply { 78 addRow(arrayOf(item)) 79 moveToFirst() // Prepare for consumers to read. 80 } 81 } 82