Merge "Add new test module for system service with static / final mocking"

am: 4247a85cdb

Change-Id: I29d5aca15124a910a765d45412a27e2817222703
This commit is contained in:
Ian Kasprzak
2018-10-29 16:29:14 -07:00
committed by android-build-merger
4 changed files with 117 additions and 11 deletions

View File

@@ -0,0 +1,45 @@
# Copyright (C) 2018 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.
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := tests
LOCAL_SRC_FILES := $(call all-java-files-under, src)
LOCAL_STATIC_JAVA_LIBRARIES := \
services.core \
services.devicepolicy \
frameworks-base-testutils \
androidx-test \
mockito-target-extended-minus-junit4 \
ShortcutManagerTestUtils \
compatibility-device-util \
truth-prebuilt
LOCAL_JAVA_LIBRARIES := \
android.test.mock
LOCAL_JNI_SHARED_LIBRARIES := \
libdexmakerjvmtiagent \
libstaticjvmtiagent
LOCAL_PACKAGE_NAME := FrameworksMockingServicesTests
LOCAL_PRIVATE_PLATFORM_APIS := true
LOCAL_COMPATIBILITY_SUITE := device-tests
LOCAL_PROGUARD_ENABLED := disabled
include $(BUILD_PACKAGE)

View File

@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2018 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.frameworks.mockingservicestests">
<application android:debuggable="true">
<uses-library android:name="android.test.runner" />
</application>
<instrumentation
android:name="androidx.test.runner.AndroidJUnitRunner"
android:targetPackage="com.android.frameworks.mockingservicestests"
android:label="Frameworks Mocking Services Tests" />
</manifest>

View File

@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2018 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.
-->
<configuration description="Runs Frameworks Services Tests.">
<option name="test-suite-tag" value="apct" />
<option name="test-suite-tag" value="apct-instrumentation" />
<target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
<option name="cleanup-apks" value="true" />
<option name="test-file-name" value="FrameworksMockingServicesTests.apk" />
</target_preparer>
<option name="test-tag" value="FrameworksMockingServicesTests" />
<test class="com.android.tradefed.testtype.AndroidJUnitTest" >
<option name="package" value="com.android.frameworks.mockingservicestests" />
<option name="runner" value="androidx.test.runner.AndroidJUnitRunner" />
<option name="hidden-api-checks" value="false"/>
</test>
</configuration>

View File

@@ -60,8 +60,6 @@ import android.os.Process;
import android.os.RemoteException; import android.os.RemoteException;
import android.os.UserHandle; import android.os.UserHandle;
import android.provider.Settings.Global; import android.provider.Settings.Global;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
import android.test.mock.MockContentResolver; import android.test.mock.MockContentResolver;
import android.util.ArraySet; import android.util.ArraySet;
import android.util.Pair; import android.util.Pair;
@@ -87,11 +85,14 @@ import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.function.Consumer; import java.util.function.Consumer;
import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;
/** /**
* Tests for {@link AppStateTracker} * Tests for {@link AppStateTracker}
* *
* Run with: * Run with:
atest $ANDROID_BUILD_TOP/frameworks/base/services/tests/servicestests/src/com/android/server/AppStateTrackerTest.java atest $ANDROID_BUILD_TOP/frameworks/base/services/tests/mockingservicestests/src/com/android/server/AppStateTrackerTest.java
*/ */
@SmallTest @SmallTest
@RunWith(AndroidJUnit4.class) @RunWith(AndroidJUnit4.class)
@@ -682,10 +683,10 @@ public class AppStateTrackerTest {
//-------------------------------------------------- //--------------------------------------------------
List<OpEntry> entries = new ArrayList<>(); List<OpEntry> entries = new ArrayList<>();
entries.add(new AppOpsManager.OpEntry( entries.add(new OpEntry(
AppOpsManager.OP_ACCESS_NOTIFICATIONS, AppOpsManager.OP_ACCESS_NOTIFICATIONS,
AppOpsManager.MODE_IGNORED, 0, 0, 0, 0, null)); AppOpsManager.MODE_IGNORED, 0, 0, 0, 0, null));
entries.add(new AppOpsManager.OpEntry( entries.add(new OpEntry(
AppStateTracker.TARGET_OP, AppStateTracker.TARGET_OP,
AppOpsManager.MODE_IGNORED, 0, 0, 0, 0, null)); AppOpsManager.MODE_IGNORED, 0, 0, 0, 0, null));
@@ -693,7 +694,7 @@ public class AppStateTrackerTest {
//-------------------------------------------------- //--------------------------------------------------
entries = new ArrayList<>(); entries = new ArrayList<>();
entries.add(new AppOpsManager.OpEntry( entries.add(new OpEntry(
AppStateTracker.TARGET_OP, AppStateTracker.TARGET_OP,
AppOpsManager.MODE_IGNORED, 0, 0, 0, 0, null)); AppOpsManager.MODE_IGNORED, 0, 0, 0, 0, null));
@@ -701,7 +702,7 @@ public class AppStateTrackerTest {
//-------------------------------------------------- //--------------------------------------------------
entries = new ArrayList<>(); entries = new ArrayList<>();
entries.add(new AppOpsManager.OpEntry( entries.add(new OpEntry(
AppStateTracker.TARGET_OP, AppStateTracker.TARGET_OP,
AppOpsManager.MODE_ALLOWED, 0, 0, 0, 0, null)); AppOpsManager.MODE_ALLOWED, 0, 0, 0, 0, null));
@@ -709,10 +710,10 @@ public class AppStateTrackerTest {
//-------------------------------------------------- //--------------------------------------------------
entries = new ArrayList<>(); entries = new ArrayList<>();
entries.add(new AppOpsManager.OpEntry( entries.add(new OpEntry(
AppStateTracker.TARGET_OP, AppStateTracker.TARGET_OP,
AppOpsManager.MODE_IGNORED, 0, 0, 0, 0, null)); AppOpsManager.MODE_IGNORED, 0, 0, 0, 0, null));
entries.add(new AppOpsManager.OpEntry( entries.add(new OpEntry(
AppOpsManager.OP_ACCESS_NOTIFICATIONS, AppOpsManager.OP_ACCESS_NOTIFICATIONS,
AppOpsManager.MODE_IGNORED, 0, 0, 0, 0, null)); AppOpsManager.MODE_IGNORED, 0, 0, 0, 0, null));
@@ -753,7 +754,7 @@ public class AppStateTrackerTest {
final AppStateTrackerTestable instance = newInstance(); final AppStateTrackerTestable instance = newInstance();
callStart(instance); callStart(instance);
AppStateTracker.Listener l = mock(AppStateTracker.Listener.class); Listener l = mock(Listener.class);
instance.addListener(l); instance.addListener(l);
// Power save on. // Power save on.
@@ -796,7 +797,7 @@ public class AppStateTrackerTest {
final AppStateTrackerTestable instance = newInstance(); final AppStateTrackerTestable instance = newInstance();
callStart(instance); callStart(instance);
AppStateTracker.Listener l = mock(AppStateTracker.Listener.class); Listener l = mock(Listener.class);
instance.addListener(l); instance.addListener(l);
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------