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
This commit is contained in:
Kevin Han
2021-03-09 12:38:46 -08:00
parent 6abae19241
commit fcc5accda1
2 changed files with 6 additions and 0 deletions

View File

@@ -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());

View File

@@ -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 =