summaryrefslogtreecommitdiff
path: root/services/tests
diff options
context:
space:
mode:
authorKevin Han <kevhan@google.com>2021-03-09 12:38:46 -0800
committerKevin Han <kevhan@google.com>2021-03-10 13:09:26 -0800
commitfcc5accda1a7d4aa2c88b151a8aaeaefd8a2b022 (patch)
treefad824e38304e0d23b6a9f1326e44df66dd25679 /services/tests
parent6abae19241c8f44409755bc379797dd0f9ef8c75 (diff)
Fix local service binding in tests.
AppHibernationServiceTest failed because every set up would instantiate AppHibernationService which would try to add to the static LocalServices registry. We now remove any registered local services before each test. Also, add @Presubmit label so that these tests actually run in presubmit. Bug: 175829330 Test: atest AppHibernationServiceTest Test: check that test actually runs in presubmit Change-Id: I5510f7e862d608cacaf12d8a561af7ac74774782
Diffstat (limited to 'services/tests')
-rw-r--r--services/tests/servicestests/src/com/android/server/apphibernation/AppHibernationServiceTest.java4
-rw-r--r--services/tests/servicestests/src/com/android/server/apphibernation/HibernationStateDiskStoreTest.java2
2 files changed, 6 insertions, 0 deletions
diff --git a/services/tests/servicestests/src/com/android/server/apphibernation/AppHibernationServiceTest.java b/services/tests/servicestests/src/com/android/server/apphibernation/AppHibernationServiceTest.java
index 07f67327b2bf..1c9683803857 100644
--- a/services/tests/servicestests/src/com/android/server/apphibernation/AppHibernationServiceTest.java
+++ b/services/tests/servicestests/src/com/android/server/apphibernation/AppHibernationServiceTest.java
@@ -40,9 +40,11 @@ import android.content.pm.UserInfo;
import android.net.Uri;
import android.os.RemoteException;
import android.os.UserManager;
+import android.platform.test.annotations.Presubmit;
import androidx.test.filters.SmallTest;
+import com.android.server.LocalServices;
import com.android.server.SystemService;
import org.junit.Before;
@@ -60,6 +62,7 @@ import java.util.List;
* Tests for {@link com.android.server.apphibernation.AppHibernationService}
*/
@SmallTest
+@Presubmit
public final class AppHibernationServiceTest {
private static final String PACKAGE_SCHEME = "package";
private static final String PACKAGE_NAME_1 = "package1";
@@ -91,6 +94,7 @@ public final class AppHibernationServiceTest {
MockitoAnnotations.initMocks(this);
doReturn(mContext).when(mContext).createContextAsUser(any(), anyInt());
+ LocalServices.removeServiceForTest(AppHibernationManagerInternal.class);
mAppHibernationService = new AppHibernationService(new MockInjector(mContext));
verify(mContext).registerReceiver(mReceiverCaptor.capture(), any());
diff --git a/services/tests/servicestests/src/com/android/server/apphibernation/HibernationStateDiskStoreTest.java b/services/tests/servicestests/src/com/android/server/apphibernation/HibernationStateDiskStoreTest.java
index 59f3c35f2137..2237c845cde7 100644
--- a/services/tests/servicestests/src/com/android/server/apphibernation/HibernationStateDiskStoreTest.java
+++ b/services/tests/servicestests/src/com/android/server/apphibernation/HibernationStateDiskStoreTest.java
@@ -19,6 +19,7 @@ package com.android.server.apphibernation;
import static org.junit.Assert.assertEquals;
import android.os.FileUtils;
+import android.platform.test.annotations.Presubmit;
import android.util.proto.ProtoInputStream;
import android.util.proto.ProtoOutputStream;
@@ -48,6 +49,7 @@ import java.util.concurrent.TimeoutException;
@SmallTest
+@Presubmit
public class HibernationStateDiskStoreTest {
private static final String STATES_FILE_NAME = "states";
private final MockScheduledExecutorService mMockScheduledExecutorService =