diff options
| -rw-r--r-- | packages/SettingsLib/Spa/settings.gradle | 1 | ||||
| -rw-r--r-- | packages/SettingsLib/Spa/tests/Android.bp | 1 | ||||
| -rw-r--r-- | packages/SettingsLib/Spa/tests/build.gradle | 1 | ||||
| -rw-r--r-- | packages/SettingsLib/Spa/testutils/Android.bp | 33 | ||||
| -rw-r--r-- | packages/SettingsLib/Spa/testutils/AndroidManifest.xml | 20 | ||||
| -rw-r--r-- | packages/SettingsLib/Spa/testutils/build.gradle | 50 | ||||
| -rw-r--r-- | packages/SettingsLib/Spa/testutils/src/MockitoHelper.kt | 29 |
7 files changed, 135 insertions, 0 deletions
diff --git a/packages/SettingsLib/Spa/settings.gradle b/packages/SettingsLib/Spa/settings.gradle index cef79c16b38a..b627a7036f66 100644 --- a/packages/SettingsLib/Spa/settings.gradle +++ b/packages/SettingsLib/Spa/settings.gradle @@ -32,4 +32,5 @@ dependencyResolutionManagement { rootProject.name = "SpaLib" include ':spa' include ':gallery' +include ':testutils' include ':tests' diff --git a/packages/SettingsLib/Spa/tests/Android.bp b/packages/SettingsLib/Spa/tests/Android.bp index 2449dec36d26..dcfc171dad0c 100644 --- a/packages/SettingsLib/Spa/tests/Android.bp +++ b/packages/SettingsLib/Spa/tests/Android.bp @@ -26,6 +26,7 @@ android_test { static_libs: [ "SpaLib", + "SpaLibTestUtils", "androidx.test.runner", "androidx.test.ext.junit", "androidx.compose.runtime_runtime", diff --git a/packages/SettingsLib/Spa/tests/build.gradle b/packages/SettingsLib/Spa/tests/build.gradle index 52610919699b..529a20156e46 100644 --- a/packages/SettingsLib/Spa/tests/build.gradle +++ b/packages/SettingsLib/Spa/tests/build.gradle @@ -59,6 +59,7 @@ android { dependencies { androidTestImplementation project(":spa") + androidTestImplementation project(":testutils") androidTestImplementation "androidx.test.ext:junit-ktx:1.1.3" androidTestImplementation "androidx.compose.ui:ui-test-junit4:$jetpack_compose_version" androidTestImplementation "com.google.truth:truth:1.1.3" diff --git a/packages/SettingsLib/Spa/testutils/Android.bp b/packages/SettingsLib/Spa/testutils/Android.bp new file mode 100644 index 000000000000..68ad41452bd1 --- /dev/null +++ b/packages/SettingsLib/Spa/testutils/Android.bp @@ -0,0 +1,33 @@ +// +// Copyright (C) 2022 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +package { + default_applicable_licenses: ["frameworks_base_license"], +} + +android_library { + name: "SpaLibTestUtils", + + srcs: ["src/**/*.kt"], + + static_libs: [ + "mockito-target-minus-junit4", + ], + kotlincflags: [ + "-Xjvm-default=all", + ], + min_sdk_version: "31", +} diff --git a/packages/SettingsLib/Spa/testutils/AndroidManifest.xml b/packages/SettingsLib/Spa/testutils/AndroidManifest.xml new file mode 100644 index 000000000000..1aa7782364b5 --- /dev/null +++ b/packages/SettingsLib/Spa/testutils/AndroidManifest.xml @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="utf-8"?><!-- + Copyright (C) 2022 The Android Open Source Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + --> + +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="com.android.settingslib.spa.testutils"> + <uses-sdk android:minSdkVersion="21"/> +</manifest> diff --git a/packages/SettingsLib/Spa/testutils/build.gradle b/packages/SettingsLib/Spa/testutils/build.gradle new file mode 100644 index 000000000000..71d7d8a89c54 --- /dev/null +++ b/packages/SettingsLib/Spa/testutils/build.gradle @@ -0,0 +1,50 @@ +/* + * Copyright 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +plugins { + id 'com.android.library' + id 'kotlin-android' +} + +android { + compileSdk spa_target_sdk + + defaultConfig { + minSdk spa_min_sdk + targetSdk spa_target_sdk + } + + sourceSets { + main { + kotlin { + srcDir "src" + } + manifest.srcFile "AndroidManifest.xml" + } + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + kotlinOptions { + jvmTarget = '1.8' + freeCompilerArgs = ["-Xjvm-default=all", "-opt-in=kotlin.RequiresOptIn"] + } +} + +dependencies { + api "org.mockito:mockito-android:3.4.6" +} diff --git a/packages/SettingsLib/Spa/testutils/src/MockitoHelper.kt b/packages/SettingsLib/Spa/testutils/src/MockitoHelper.kt new file mode 100644 index 000000000000..5ba54c12b0d0 --- /dev/null +++ b/packages/SettingsLib/Spa/testutils/src/MockitoHelper.kt @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.settingslib.spa.testutils + +import org.mockito.Mockito + +/** + * Returns Mockito.any() as nullable type to avoid java.lang.IllegalStateException when null is + * returned. + * + * Generic T is nullable because implicitly bounded by Any?. + */ +fun <T> any(type: Class<T>): T = Mockito.any(type) + +inline fun <reified T> any(): T = any(T::class.java) |