summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Wenhao Wang <wenhaowang@google.com> 2022-04-21 16:58:08 -0700
committer Wenhao Wang <wenhaowang@google.com> 2022-04-22 08:03:45 -0700
commit7355fc7a80042495f79b656da899dda82afeb1af (patch)
treebb843b1f0d6dbefd068d0cccf3a9776e48088ad5
parent6584dbb6e6026a2698f31cea41f8e66698f67a54 (diff)
BinaryTransparencyServiceTest: Avoid schedule()
To fix the testing breakage, we avoid the JobScheduler.schedule() by leveraging a context spy to stub the getSystemService(). Bug: 230008604 Test: BinaryTransparencyServiceTest Change-Id: I8243d3afd66243f145eccdb6a6ab97596d11c7f3
-rw-r--r--services/tests/servicestests/src/com/android/server/BinaryTransparencyServiceTest.java8
1 files changed, 7 insertions, 1 deletions
diff --git a/services/tests/servicestests/src/com/android/server/BinaryTransparencyServiceTest.java b/services/tests/servicestests/src/com/android/server/BinaryTransparencyServiceTest.java
index 0e84e044e44b..42c4129513d0 100644
--- a/services/tests/servicestests/src/com/android/server/BinaryTransparencyServiceTest.java
+++ b/services/tests/servicestests/src/com/android/server/BinaryTransparencyServiceTest.java
@@ -16,6 +16,10 @@
package com.android.server;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.spy;
+
+import android.app.job.JobScheduler;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
@@ -43,13 +47,15 @@ public class BinaryTransparencyServiceTest {
@Before
public void setUp() {
- mContext = ApplicationProvider.getApplicationContext();
+ mContext = spy(ApplicationProvider.getApplicationContext());
mBinaryTransparencyService = new BinaryTransparencyService(mContext);
mTestInterface = mBinaryTransparencyService.new BinaryTransparencyServiceImpl();
}
private void prepSignedInfo() {
// simulate what happens on boot completed phase
+ // but we avoid calling JobScheduler.schedule by returning a null.
+ doReturn(null).when(mContext).getSystemService(JobScheduler.class);
mBinaryTransparencyService.onBootPhase(SystemService.PHASE_BOOT_COMPLETED);
}