diff options
author | Treehugger Robot <android-test-infra-autosubmit@system.gserviceaccount.com> | 2024-01-06 02:14:51 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2024-01-06 02:14:51 +0000 |
commit | 2a12c14da76a815e408cea77982e9237d74dd305 (patch) | |
tree | e50d49ca7e97decff4ba7ac87fa4a0e042e89ab2 /adservices/tests/unittest/service-core | |
parent | 618fe9590628e3d1ed4234e54665503d8566cea0 (diff) | |
parent | a2b31f861e93dfb36be1e4f3ed24a781bc44b290 (diff) | |
download | AdServices-2a12c14da76a815e408cea77982e9237d74dd305.tar.gz |
Merge "Refactored DBCustomAudienceBackgroundFetchDataTest to not depend on DeviceConfig." into udc-mainline-prod
Diffstat (limited to 'adservices/tests/unittest/service-core')
-rw-r--r-- | adservices/tests/unittest/service-core/src/com/android/adservices/data/customaudience/DBCustomAudienceBackgroundFetchDataTest.java | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/adservices/tests/unittest/service-core/src/com/android/adservices/data/customaudience/DBCustomAudienceBackgroundFetchDataTest.java b/adservices/tests/unittest/service-core/src/com/android/adservices/data/customaudience/DBCustomAudienceBackgroundFetchDataTest.java index e9574eca6b..a078f13c0e 100644 --- a/adservices/tests/unittest/service-core/src/com/android/adservices/data/customaudience/DBCustomAudienceBackgroundFetchDataTest.java +++ b/adservices/tests/unittest/service-core/src/com/android/adservices/data/customaudience/DBCustomAudienceBackgroundFetchDataTest.java @@ -26,26 +26,21 @@ import static org.junit.Assert.assertThrows; import android.adservices.common.CommonFixture; import android.adservices.customaudience.CustomAudienceFixture; +import com.android.adservices.common.AdServicesExtendedMockitoTestCase; import com.android.adservices.customaudience.DBCustomAudienceBackgroundFetchDataFixture; import com.android.adservices.service.Flags; import com.android.adservices.service.FlagsFactory; -import com.android.adservices.service.PhFlagsFixture; import com.android.adservices.service.customaudience.BackgroundFetchRunner; import com.android.adservices.service.customaudience.CustomAudienceUpdatableData; import com.android.adservices.service.customaudience.CustomAudienceUpdatableDataFixture; -import com.android.modules.utils.testing.TestableDeviceConfig; +import com.android.modules.utils.testing.ExtendedMockitoRule.SpyStatic; -import org.json.JSONException; -import org.junit.Rule; import org.junit.Test; import java.time.Instant; -public class DBCustomAudienceBackgroundFetchDataTest { - // This rule is used for configuring P/H flags - @Rule - public final TestableDeviceConfig.TestableDeviceConfigRule mDeviceConfigRule = - new TestableDeviceConfig.TestableDeviceConfigRule(); +public final class DBCustomAudienceBackgroundFetchDataTest + extends AdServicesExtendedMockitoTestCase { @Test public void testBuildFetchDataSuccess() { @@ -179,22 +174,28 @@ public class DBCustomAudienceBackgroundFetchDataTest { @Test public void testComputeNextEligibleUpdateTimeWithPhFlags() { - long configuredBaseIntervalS = 100L; - PhFlagsFixture.configureFledgeBackgroundFetchEligibleUpdateBaseIntervalS( - configuredBaseIntervalS); + Flags flags = FlagsFactory.getFlagsForTest(); + long configuredBaseIntervalS = flags.getFledgeBackgroundFetchEligibleUpdateBaseIntervalS(); Instant expectedEligibleUpdateTime = CommonFixture.FIXED_NOW.plusSeconds(configuredBaseIntervalS); Instant actualEligibleUpdateTime = DBCustomAudienceBackgroundFetchData .computeNextEligibleUpdateTimeAfterSuccessfulUpdate( - CommonFixture.FIXED_NOW); + CommonFixture.FIXED_NOW, flags); assertEquals(expectedEligibleUpdateTime, actualEligibleUpdateTime); } @Test - public void testCopyWithFullSuccessfulUpdatableDataResetsFailureCounts() throws JSONException { + @SpyStatic(FlagsFactory.class) + public void testCopyWithFullSuccessfulUpdatableDataResetsFailureCounts() throws Exception { + // NOTE: copyWithUpdatableData() will eventually call the + // computeNextEligibleUpdateTimeAfterSuccessfulUpdate() method that calls + // FlagsFactory.getInstance(), so we need to mock that method (otherwise it would call + // DeviceConfig and fail due to lack of permissions) + extendedMockito.mockGetFlags(FlagsFactory.getFlagsForTest()); + DBCustomAudienceBackgroundFetchData originalFetchData = DBCustomAudienceBackgroundFetchDataFixture.getValidBuilderByBuyer( CommonFixture.VALID_BUYER_1) @@ -206,8 +207,7 @@ public class DBCustomAudienceBackgroundFetchDataTest { Instant attemptedUpdateTime = CommonFixture.FIXED_NOW.plusSeconds(10); Instant expectedEligibleUpdateTime = DBCustomAudienceBackgroundFetchData - .computeNextEligibleUpdateTimeAfterSuccessfulUpdate( - attemptedUpdateTime, FlagsFactory.getFlagsForTest()); + .computeNextEligibleUpdateTimeAfterSuccessfulUpdate(attemptedUpdateTime); CustomAudienceUpdatableData updatableData = CustomAudienceUpdatableDataFixture.getValidBuilderFullSuccessfulResponse() |