Merge "Add new SpaLibTestUtils"
This commit is contained in:
@@ -32,4 +32,5 @@ dependencyResolutionManagement {
|
||||
rootProject.name = "SpaLib"
|
||||
include ':spa'
|
||||
include ':gallery'
|
||||
include ':testutils'
|
||||
include ':tests'
|
||||
|
||||
@@ -26,6 +26,7 @@ android_test {
|
||||
|
||||
static_libs: [
|
||||
"SpaLib",
|
||||
"SpaLibTestUtils",
|
||||
"androidx.test.runner",
|
||||
"androidx.test.ext.junit",
|
||||
"androidx.compose.runtime_runtime",
|
||||
|
||||
@@ -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"
|
||||
|
||||
33
packages/SettingsLib/Spa/testutils/Android.bp
Normal file
33
packages/SettingsLib/Spa/testutils/Android.bp
Normal file
@@ -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",
|
||||
}
|
||||
20
packages/SettingsLib/Spa/testutils/AndroidManifest.xml
Normal file
20
packages/SettingsLib/Spa/testutils/AndroidManifest.xml
Normal file
@@ -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>
|
||||
50
packages/SettingsLib/Spa/testutils/build.gradle
Normal file
50
packages/SettingsLib/Spa/testutils/build.gradle
Normal file
@@ -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"
|
||||
}
|
||||
29
packages/SettingsLib/Spa/testutils/src/MockitoHelper.kt
Normal file
29
packages/SettingsLib/Spa/testutils/src/MockitoHelper.kt
Normal file
@@ -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)
|
||||
Reference in New Issue
Block a user