Modern-Apps.git
Publicgit clone https://git.maproj.org/Modern-Apps.gitModern-Apps.git / library / aosp-stubs / src / test / java / android / service / euicc / EuiccServiceStubShapeTest.kt
EuiccServiceStubShapeTest.kt45 lines · 1.9 KiBRaw
| 1 | package android.service.euicc |
| 2 | |
| 3 | import java.lang.reflect.Modifier |
| 4 | import kotlin.test.Test |
| 5 | import kotlin.test.assertEquals |
| 6 | import kotlin.test.assertFalse |
| 7 | import kotlin.test.assertTrue |
| 8 | |
| 9 | /** |
| 10 | * Plain-JVM (no Robolectric): Robolectric loads the framework's real |
| 11 | * `android.service.euicc` classes from android-all, which would shadow this |
| 12 | * module's stub. On a plain classpath the module class wins, so the stub's |
| 13 | * shape is directly observable here (same reasoning as locationprovider's |
| 14 | * GeocoderParamsJvmTest). |
| 15 | * |
| 16 | * The framework's `EuiccService.OtaStatusChangedCallback` is an abstract |
| 17 | * class, not an interface (euicc's ServicesTest documents this from the |
| 18 | * runtime class). A stub interface makes consumers emit `invokeinterface` |
| 19 | * for `onOtaStatusChanged`, which the real abstract class rejects with |
| 20 | * IncompatibleClassChangeError on the OTA path. |
| 21 | */ |
| 22 | class EuiccServiceStubShapeTest { |
| 23 | |
| 24 | @Test |
| 25 | fun otaStatusChangedCallbackIsAbstractClassNotInterface() { |
| 26 | val callback = EuiccService.OtaStatusChangedCallback::class.java |
| 27 | assertFalse(callback.isInterface, "OtaStatusChangedCallback must not be an interface") |
| 28 | assertTrue(Modifier.isAbstract(callback.modifiers), "OtaStatusChangedCallback must be abstract") |
| 29 | val method = callback.getDeclaredMethod("onOtaStatusChanged", Int::class.javaPrimitiveType) |
| 30 | assertTrue(Modifier.isAbstract(method.modifiers), "onOtaStatusChanged must be abstract") |
| 31 | assertTrue(Modifier.isPublic(method.modifiers), "onOtaStatusChanged must be public") |
| 32 | } |
| 33 | |
| 34 | @Test |
| 35 | fun otaStatusChangedCallbackSubclassDispatches() { |
| 36 | var received = -1 |
| 37 | val callback = object : EuiccService.OtaStatusChangedCallback() { |
| 38 | override fun onOtaStatusChanged(status: Int) { |
| 39 | received = status |
| 40 | } |
| 41 | } |
| 42 | callback.onOtaStatusChanged(EuiccService.OTA_STATUS_NOT_UPDATED) |
| 43 | assertEquals(EuiccService.OTA_STATUS_NOT_UPDATED, received) |
| 44 | } |
| 45 | } |