diff options
author | Jason Monk <jmonk@google.com> | 2017-12-14 13:22:58 -0500 |
---|---|---|
committer | Jason Monk <jmonk@google.com> | 2018-02-18 13:02:25 -0500 |
commit | 1fc931a38a9335b3b4b498c7cc31d37a777c7a5a (patch) | |
tree | 910234f60264e0a10f14106ce23f3e9f6f874751 | |
parent | 700448e4b480b7315d781c92c4a8f5538a02a745 (diff) |
Switch to inline mockito for a bunch of tests
So we can mock final stuff
Test: The tests
Change-Id: Ia3a47c6655c4b0b9af0aea0ee6f8f6cb9ebaab09
15 files changed, 56 insertions, 19 deletions
diff --git a/packages/SystemUI/shared/tests/Android.mk b/packages/SystemUI/shared/tests/Android.mk index 1715983d3650..d01160d95e9d 100644 --- a/packages/SystemUI/shared/tests/Android.mk +++ b/packages/SystemUI/shared/tests/Android.mk @@ -35,12 +35,18 @@ LOCAL_SRC_FILES := $(call all-java-files-under, src) \ LOCAL_STATIC_JAVA_LIBRARIES := \ metrics-helper-lib \ android-support-test \ - mockito-target-minus-junit4 \ + mockito-target-inline-minus-junit4 \ SystemUI-proto \ SystemUI-tags \ testables \ truth-prebuilt \ +LOCAL_MULTILIB := both + +LOCAL_JNI_SHARED_LIBRARIES := \ + libdexmakerjvmtiagent \ + libmultiplejvmtiagentsinterferenceagent + LOCAL_JAVA_LIBRARIES := android.test.runner telephony-common # sign this with platform cert, so this test is allowed to inject key events into diff --git a/packages/SystemUI/shared/tests/AndroidManifest.xml b/packages/SystemUI/shared/tests/AndroidManifest.xml index 3e1de499c801..5974b76c6c5c 100644 --- a/packages/SystemUI/shared/tests/AndroidManifest.xml +++ b/packages/SystemUI/shared/tests/AndroidManifest.xml @@ -19,7 +19,7 @@ <uses-permission android:name="android.permission.READ_FRAME_BUFFER" /> - <application> + <application android:debuggable="true"> <uses-library android:name="android.test.runner" /> </application> diff --git a/packages/SystemUI/tests/Android.mk b/packages/SystemUI/tests/Android.mk index 59a7da68dd31..552784aa88db 100644 --- a/packages/SystemUI/tests/Android.mk +++ b/packages/SystemUI/tests/Android.mk @@ -56,12 +56,19 @@ LOCAL_STATIC_ANDROID_LIBRARIES := \ LOCAL_STATIC_JAVA_LIBRARIES := \ metrics-helper-lib \ android-support-test \ - mockito-target-minus-junit4 \ + mockito-target-inline-minus-junit4 \ SystemUI-proto \ SystemUI-tags \ testables \ truth-prebuilt \ +LOCAL_MULTILIB := both + +LOCAL_JNI_SHARED_LIBRARIES := \ + libdexmakerjvmtiagent \ + libmultiplejvmtiagentsinterferenceagent + + LOCAL_JAVA_LIBRARIES := \ android.test.runner \ telephony-common \ diff --git a/packages/SystemUI/tests/AndroidManifest.xml b/packages/SystemUI/tests/AndroidManifest.xml index f5e079ca9d61..767a24a27a26 100644 --- a/packages/SystemUI/tests/AndroidManifest.xml +++ b/packages/SystemUI/tests/AndroidManifest.xml @@ -48,8 +48,9 @@ <uses-permission android:name="android.permission.REAL_GET_TASKS" /> <uses-permission android:name="android.permission.INTERNAL_SYSTEM_WINDOW" /> <uses-permission android:name="android.permission.NETWORK_SETTINGS" /> + <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> - <application> + <application android:debuggable="true"> <uses-library android:name="android.test.runner" /> <activity android:name="com.android.systemui.screenshot.ScreenshotStubActivity" /> diff --git a/packages/SystemUI/tests/src/com/android/systemui/qs/SlashImageViewTest.java b/packages/SystemUI/tests/src/com/android/systemui/qs/SlashImageViewTest.java index 98ca1b4fc799..e2159d24ad85 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/qs/SlashImageViewTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/qs/SlashImageViewTest.java @@ -27,8 +27,14 @@ import com.android.systemui.qs.tileimpl.SlashImageView; import org.junit.Test; import org.junit.runner.RunWith; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; @SmallTest @@ -80,13 +86,12 @@ public class SlashImageViewTest extends SysuiTestCase { public void testSetImageDrawableUsesDrawableLevel() { SlashImageView iv = new SlashImageView(mContext); Drawable mockDrawable = mock(Drawable.class); - mockDrawable.setLevel(2); - assertTrue(mockDrawable.getLevel() == 2); + when(mockDrawable.getLevel()).thenReturn(2); iv.setImageDrawable(mockDrawable); // Make sure setting the drawable didn't reset its level to 0 - assertTrue(mockDrawable.getLevel() == 2); + verify(mockDrawable).setLevel(eq(2)); } // Expose getSlashDrawable diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/NavigationBarFragmentTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/NavigationBarFragmentTest.java index 4cc83f632426..17df8003dfa9 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/NavigationBarFragmentTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/NavigationBarFragmentTest.java @@ -27,6 +27,7 @@ import android.view.WindowManager; import com.android.systemui.Dependency; +import com.android.systemui.OverviewProxyService; import com.android.systemui.SysuiBaseFragmentTest; import com.android.systemui.recents.Recents; import com.android.systemui.stackdivider.Divider; @@ -61,6 +62,7 @@ public class NavigationBarFragmentTest extends SysuiBaseFragmentTest { mSysuiContext.putComponent(Recents.class, mock(Recents.class)); mSysuiContext.putComponent(Divider.class, mock(Divider.class)); injectLeakCheckedDependencies(ALL_SUPPORTED_CLASSES); + mDependency.injectMockDependency(OverviewProxyService.class); WindowManager windowManager = mock(WindowManager.class); Display defaultDisplay = mContext.getSystemService(WindowManager.class).getDefaultDisplay(); when(windowManager.getDefaultDisplay()).thenReturn( diff --git a/packages/SystemUI/tests/src/com/android/systemui/tuner/TunablePaddingTest.java b/packages/SystemUI/tests/src/com/android/systemui/tuner/TunablePaddingTest.java index 9fd8cc346341..3bfefe7b4d9b 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/tuner/TunablePaddingTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/tuner/TunablePaddingTest.java @@ -45,7 +45,8 @@ public class TunablePaddingTest extends LeakCheckedTest { @Before public void setup() { injectLeakCheckedDependencies(ALL_SUPPORTED_CLASSES); - mView = mock(View.class, withSettings().spiedInstance(new View(mContext))); + mView = mock(View.class); + when(mView.getContext()).thenReturn(mContext); mTunerService = mDependency.injectMockDependency(TunerService.class); Tracker tracker = mLeakCheck.getTracker("tuner"); diff --git a/services/tests/uiservicestests/Android.mk b/services/tests/uiservicestests/Android.mk index d8e14ecab1cd..d7c3f7f68fd3 100644 --- a/services/tests/uiservicestests/Android.mk +++ b/services/tests/uiservicestests/Android.mk @@ -14,7 +14,6 @@ LOCAL_SRC_FILES := $(call all-java-files-under, src) \ $(call all-java-files-under, ../../core/java/com/android/server/slice) \ LOCAL_STATIC_JAVA_LIBRARIES := \ - frameworks-base-testutils \ services.accessibility \ services.core \ services.devicepolicy \ @@ -22,7 +21,7 @@ LOCAL_STATIC_JAVA_LIBRARIES := \ services.usage \ guava \ android-support-test \ - mockito-target-minus-junit4 \ + mockito-target-inline-minus-junit4 \ platform-test-annotations \ testables @@ -36,8 +35,12 @@ LOCAL_COMPATIBILITY_SUITE := device-tests LOCAL_CERTIFICATE := platform +LOCAL_MULTILIB := both + # These are not normally accessible from apps so they must be explicitly included. LOCAL_JNI_SHARED_LIBRARIES := \ + libdexmakerjvmtiagent \ + libmultiplejvmtiagentsinterferenceagent \ libbacktrace \ libbase \ libbinder \ diff --git a/services/tests/uiservicestests/AndroidManifest.xml b/services/tests/uiservicestests/AndroidManifest.xml index aabf9eab3c1f..fc459a0fc5b8 100644 --- a/services/tests/uiservicestests/AndroidManifest.xml +++ b/services/tests/uiservicestests/AndroidManifest.xml @@ -28,7 +28,7 @@ <uses-permission android:name="android.permission.ACCESS_VOICE_INTERACTION_SERVICE" /> <uses-permission android:name="android.permission.DEVICE_POWER" /> - <application> + <application android:debuggable="true"> <uses-library android:name="android.test.runner" /> <provider android:name=".DummyProvider" diff --git a/services/tests/uiservicestests/src/com/android/server/notification/ScheduleConditionProviderTest.java b/services/tests/uiservicestests/src/com/android/server/notification/ScheduleConditionProviderTest.java index 17fed83c4b02..efa70e7204f1 100644 --- a/services/tests/uiservicestests/src/com/android/server/notification/ScheduleConditionProviderTest.java +++ b/services/tests/uiservicestests/src/com/android/server/notification/ScheduleConditionProviderTest.java @@ -12,6 +12,8 @@ import android.service.notification.ScheduleCalendar; import android.service.notification.ZenModeConfig; import android.support.test.filters.SmallTest; import android.support.test.runner.AndroidJUnit4; +import android.testing.AndroidTestingRunner; +import android.testing.TestableLooper.RunWithLooper; import com.android.server.UiServiceTestCase; @@ -23,8 +25,9 @@ import org.mockito.MockitoAnnotations; import java.util.Calendar; import java.util.GregorianCalendar; -@RunWith(AndroidJUnit4.class) +@RunWith(AndroidTestingRunner.class) @SmallTest +@RunWithLooper public class ScheduleConditionProviderTest extends UiServiceTestCase { ScheduleConditionProvider mService; diff --git a/tests/testables/Android.mk b/tests/testables/Android.mk index 4c4d2b4186dc..f3cbac05d1cb 100644 --- a/tests/testables/Android.mk +++ b/tests/testables/Android.mk @@ -23,10 +23,9 @@ LOCAL_MODULE_TAG := tests LOCAL_SRC_FILES := $(call all-java-files-under,src) -LOCAL_STATIC_JAVA_LIBRARIES := \ - android-support-test - -LOCAL_JAVA_LIBRARIES := android.test.runner android.test.mock mockito-target-minus-junit4 +LOCAL_JAVA_LIBRARIES := android.test.runner android.test.mock \ + android-support-test \ + mockito-target-inline-minus-junit4 include $(BUILD_STATIC_JAVA_LIBRARY) diff --git a/tests/testables/src/android/testing/TestableContext.java b/tests/testables/src/android/testing/TestableContext.java index ffe721993a37..cf84c7926549 100644 --- a/tests/testables/src/android/testing/TestableContext.java +++ b/tests/testables/src/android/testing/TestableContext.java @@ -83,6 +83,7 @@ public class TestableContext extends ContextWrapper implements TestRule { .acquireContentProviderClient(Settings.AUTHORITY); mSettingsProvider = TestableSettingsProvider.getFakeSettingsProvider(settings); mTestableContentResolver.addProvider(Settings.AUTHORITY, mSettingsProvider); + mSettingsProvider.clearValuesAndCheck(TestableContext.this); mReceiver = check != null ? check.getTracker("receiver") : null; mService = check != null ? check.getTracker("service") : null; mComponent = check != null ? check.getTracker("component") : null; diff --git a/tests/testables/src/android/testing/TestableSettingsProvider.java b/tests/testables/src/android/testing/TestableSettingsProvider.java index 5f2a2244b841..b158476bd438 100644 --- a/tests/testables/src/android/testing/TestableSettingsProvider.java +++ b/tests/testables/src/android/testing/TestableSettingsProvider.java @@ -36,7 +36,7 @@ import static org.junit.Assert.*; public class TestableSettingsProvider extends MockContentProvider { private static final String TAG = "TestableSettingsProvider"; - private static final boolean DEBUG = true; + private static final boolean DEBUG = false; private static final String MY_UNIQUE_KEY = "Key_" + TestableSettingsProvider.class.getName(); private static TestableSettingsProvider sInstance; @@ -54,6 +54,9 @@ public class TestableSettingsProvider extends MockContentProvider { mValues.put(key("secure", MY_UNIQUE_KEY, userId), MY_UNIQUE_KEY); mValues.put(key("system", MY_UNIQUE_KEY, userId), MY_UNIQUE_KEY); + Settings.Global.clearProviderForTest(); + Settings.Secure.clearProviderForTest(); + Settings.System.clearProviderForTest(); // Verify that if any test is using TestableContext, they all have the correct settings // provider. assertEquals("Incorrect settings provider, test using incorrect Context?", MY_UNIQUE_KEY, diff --git a/tests/testables/tests/Android.mk b/tests/testables/tests/Android.mk index 6e20d797fb5d..f9b3ce423e93 100644 --- a/tests/testables/tests/Android.mk +++ b/tests/testables/tests/Android.mk @@ -27,9 +27,15 @@ LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res LOCAL_STATIC_JAVA_LIBRARIES := \ android-support-test \ - mockito-target-minus-junit4 \ + mockito-target-inline-minus-junit4 \ testables +LOCAL_MULTILIB := both + +LOCAL_JNI_SHARED_LIBRARIES := \ + libdexmakerjvmtiagent \ + libmultiplejvmtiagentsinterferenceagent + LOCAL_JAVA_LIBRARIES := android.test.runner android.test.base android.test.mock LOCAL_CERTIFICATE := platform diff --git a/tests/testables/tests/AndroidManifest.xml b/tests/testables/tests/AndroidManifest.xml index 6435ad971476..61f0be613afe 100644 --- a/tests/testables/tests/AndroidManifest.xml +++ b/tests/testables/tests/AndroidManifest.xml @@ -21,7 +21,7 @@ <uses-permission android:name="android.permission.INTERACT_ACROSS_USERS_FULL" /> <uses-permission android:name="android.permission.MANAGE_USERS" /> - <application> + <application android:debuggable="true"> <uses-library android:name="android.test.runner" /> </application> |