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 17package androidx.core.content 18 19import androidx.testutils.assertThrows 20import org.junit.Assert.assertArrayEquals 21import org.junit.Assert.assertEquals 22import org.junit.Assert.assertNull 23import org.junit.Test 24import java.util.concurrent.atomic.AtomicInteger 25 26class ContentValuesTest { 27 @Test fun valuesOfValid() { 28 val values = contentValuesOf( 29 "null" to null, 30 "string" to "string", 31 "byte" to 1.toByte(), 32 "short" to 1.toShort(), 33 "int" to 1, 34 "long" to 1L, 35 "float" to 1f, 36 "double" to 1.0, 37 "boolean" to true, 38 "byteArray" to byteArrayOf() 39 ) 40 assertEquals(10, values.size()) 41 assertNull(values.get("null")) 42 assertEquals("string", values.get("string")) 43 assertEquals(1.toByte(), values.get("byte")) 44 assertEquals(1.toShort(), values.get("short")) 45 assertEquals(1, values.get("int")) 46 assertEquals(1L, values.get("long")) 47 assertEquals(1f, values.get("float")) 48 assertEquals(1.0, values.get("double")) 49 assertEquals(true, values.get("boolean")) 50 assertArrayEquals(byteArrayOf(), values.get("byteArray") as ByteArray) 51 } 52 53 @Test fun valuesOfInvalid() { 54 assertThrows<IllegalArgumentException> { 55 contentValuesOf("nope" to AtomicInteger(1)) 56 }.hasMessageThat().isEqualTo( 57 "Illegal value type java.util.concurrent.atomic.AtomicInteger for key \"nope\"") 58 } 59} 60