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 com.android.sdkparcelables
18
19 import junit.framework.TestCase.assertEquals
20 import org.junit.Test
21
22 class ParcelableDetectorTest {
23 @Test
detect implementsnull24 fun `detect implements`() {
25 val ancestorMap = mapOf(
26 testAncestors("android/test/Parcelable",null, "android/os/Parcelable"),
27 testAncestors("android/os/Parcelable", null))
28
29 val parcelables = ParcelableDetector.ancestorsToParcelables(ancestorMap)
30
31 assertEquals(parcelables, listOf("android/test/Parcelable"))
32 }
33
34 @Test
detect implements in reverse ordernull35 fun `detect implements in reverse order`() {
36 val ancestorMap = mapOf(
37 testAncestors("android/os/Parcelable", null),
38 testAncestors("android/test/Parcelable",null, "android/os/Parcelable"))
39
40 val parcelables = ParcelableDetector.ancestorsToParcelables(ancestorMap)
41
42 assertEquals(parcelables, listOf("android/test/Parcelable"))
43 }
44
45 @Test
detect super implementsnull46 fun `detect super implements`() {
47 val ancestorMap = mapOf(
48 testAncestors("android/test/SuperParcelable",null, "android/os/Parcelable"),
49 testAncestors("android/test/Parcelable","android/test/SuperParcelable"),
50 testAncestors("android/os/Parcelable", null))
51
52 val parcelables = ParcelableDetector.ancestorsToParcelables(ancestorMap)
53
54 assertEquals(parcelables, listOf("android/test/Parcelable", "android/test/SuperParcelable"))
55 }
56
57 @Test
detect super interfacenull58 fun `detect super interface`() {
59 val ancestorMap = mapOf(
60 testAncestors("android/test/IParcelable",null, "android/os/Parcelable"),
61 testAncestors("android/test/Parcelable",null, "android/test/IParcelable"),
62 testAncestors("android/os/Parcelable", null))
63
64 val parcelables = ParcelableDetector.ancestorsToParcelables(ancestorMap)
65
66 assertEquals(parcelables, listOf("android/test/IParcelable", "android/test/Parcelable"))
67 }
68
69 }
70
testAncestorsnull71 private fun testAncestors(name: String, superName: String?, vararg interfaces: String): Pair<String, Ancestors> {
72 return Pair(name, Ancestors(superName, interfaces.toList()))
73 }
74