aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorDanesh M <danesh@cyngn.com>2016-06-14 15:00:10 -0700
committerDanesh M <daneshm90@gmail.com>2016-06-15 13:38:03 -0700
commit912410f27d44ea616ca32f0d424ee648acf08fbc (patch)
treed8462812db9d33a7af75244227c045850a17debf /tests
parentb6e71bc544f1ccf75b805fc2242226a3e6e566c2 (diff)
downloadvendor_cmsdk-912410f27d44ea616ca32f0d424ee648acf08fbc.zip
vendor_cmsdk-912410f27d44ea616ca32f0d424ee648acf08fbc.tar.gz
vendor_cmsdk-912410f27d44ea616ca32f0d424ee648acf08fbc.tar.bz2
CMSDK : Add LiveLockScreenManager tests
CYNGNOS-3048 Change-Id: I5a372d23028c43a3952199b8ad70854bec2dc7a1
Diffstat (limited to 'tests')
-rw-r--r--tests/src/org/cyanogenmod/tests/livelockscreen/unit/LiveLockScreenManagerTest.java131
1 files changed, 131 insertions, 0 deletions
diff --git a/tests/src/org/cyanogenmod/tests/livelockscreen/unit/LiveLockScreenManagerTest.java b/tests/src/org/cyanogenmod/tests/livelockscreen/unit/LiveLockScreenManagerTest.java
new file mode 100644
index 0000000..30ddb21
--- /dev/null
+++ b/tests/src/org/cyanogenmod/tests/livelockscreen/unit/LiveLockScreenManagerTest.java
@@ -0,0 +1,131 @@
+/*
+ * Copyright (C) 2016 The CyanogenMod 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 org.cyanogenmod.tests.livelockscreen.unit;
+
+import android.content.Context;
+import android.content.pm.PackageManager;
+import android.os.RemoteException;
+import android.os.UserHandle;
+import android.test.AndroidTestCase;
+import android.test.mock.MockPackageManager;
+import cyanogenmod.app.CMContextConstants;
+import cyanogenmod.app.ILiveLockScreenManager;
+import cyanogenmod.app.LiveLockScreenInfo;
+import cyanogenmod.app.LiveLockScreenManager;
+import org.cyanogenmod.tests.common.MockIBinderStubForInterface;
+import org.mockito.Mockito;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
+
+import java.lang.reflect.Field;
+
+public class LiveLockScreenManagerTest extends AndroidTestCase {
+ private LiveLockScreenManager mManager;
+ private ILiveLockScreenManager mManagerInterface;
+ private Context mMockContext;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ PackageManager packageManager = Mockito.mock(MockPackageManager.class);
+ Mockito.doReturn(true).when(packageManager).hasSystemFeature(
+ CMContextConstants.Features.LIVE_LOCK_SCREEN);
+
+ // Something else is initializing the manager
+ Field f = LiveLockScreenManager.class.getDeclaredField("sInstance");
+ f.setAccessible(true);
+ f.set(null, null);
+
+ mMockContext = Mockito.mock(Context.class);
+ Mockito.doReturn(packageManager).when(mMockContext).getPackageManager();
+ mManager = LiveLockScreenManager.getInstance(mMockContext);
+ f = LiveLockScreenManager.class.getDeclaredField("sService");
+ f.setAccessible(true);
+
+ mManagerInterface = MockIBinderStubForInterface
+ .getMockInterface(ILiveLockScreenManager.Stub.class);
+ f.set(mManager, mManagerInterface);
+
+ Mockito.verify(mMockContext, Mockito.times(1)).getPackageManager();
+ Mockito.verify(packageManager, Mockito.times(1)).hasSystemFeature(
+ Mockito.eq(CMContextConstants.Features.LIVE_LOCK_SCREEN));
+ assertNotNull (mManager);
+ }
+
+ public void testGetDefaultLiveLockScreen() throws RemoteException {
+ mManager.getDefaultLiveLockScreen();
+
+ Mockito.verify(mManagerInterface, Mockito.times(1))
+ .getDefaultLiveLockScreen();
+ Mockito.verifyNoMoreInteractions(mManagerInterface);
+ }
+
+ public void testSetDefaultLiveLockScreen() throws RemoteException {
+ LiveLockScreenInfo liveLockScreenInfo = Mockito.mock(LiveLockScreenInfo.class);
+ mManager.setDefaultLiveLockScreen(liveLockScreenInfo);
+
+ Mockito.verify(mManagerInterface, Mockito.times(1))
+ .setDefaultLiveLockScreen(Mockito.eq(liveLockScreenInfo));
+ Mockito.verifyNoMoreInteractions(mManagerInterface);
+ }
+
+ private boolean testEnqueue(boolean success) throws Exception {
+ String testPackage = "com.testpackage";
+ Mockito.doReturn(testPackage).when(mMockContext).getPackageName();
+
+ if (!success) {
+ Mockito.doAnswer(new Answer() {
+ @Override
+ public Object answer(InvocationOnMock invocation) throws Throwable {
+ int[] idOut = (int[]) invocation.getArguments()[3];
+ idOut[0] = 1;
+ return invocation;
+ }
+ }).when(mManagerInterface).enqueueLiveLockScreen(Mockito.anyString(),
+ Mockito.anyInt(), Mockito.any(LiveLockScreenInfo.class),
+ Mockito.any(int[].class), Mockito.anyInt());
+ }
+
+ LiveLockScreenInfo liveLockScreenInfo = Mockito.mock(LiveLockScreenInfo.class);
+ boolean result = mManager.show(0, liveLockScreenInfo);
+
+ Mockito.verify(mManagerInterface, Mockito.times(1)).enqueueLiveLockScreen(Mockito.eq(testPackage),
+ Mockito.eq(0), Mockito.eq(liveLockScreenInfo), Mockito.any(int[].class),
+ Mockito.eq(UserHandle.myUserId()));
+ Mockito.verifyNoMoreInteractions(mManagerInterface);
+
+ return result;
+ }
+
+ public void testShowLockscreen() throws Exception {
+ assertEquals(testEnqueue(true), true);
+ assertEquals(testEnqueue(false), false);
+ }
+
+ public void testCancel() throws Exception {
+ String testPackage = "com.testpackage";
+ Mockito.doReturn(testPackage).when(mMockContext).getPackageName();
+
+ LiveLockScreenInfo liveLockScreenInfo = Mockito.mock(LiveLockScreenInfo.class);
+ mManager.cancel(0);
+
+ Mockito.verify(mManagerInterface, Mockito.times(1)).cancelLiveLockScreen(
+ Mockito.eq(testPackage), Mockito.eq(0), Mockito.eq(UserHandle.myUserId()));
+ Mockito.verifyNoMoreInteractions(mManagerInterface);
+ }
+}