Avoid use of TimeZoneDistro.equals() method

The TimeZoneDistro method is going away.

make -j30 FrameworksServicesTests
adb install -r -g \
    "out/target/product/angler/data/app/FrameworksServicesTests/FrameworksServicesTests.apk"
adb shell am instrument -e package com.android.server.timezone -w \
    com.android.frameworks.servicestests \
    "com.android.frameworks.servicestests/android.support.test.runner.AndroidJUnitRunner"

Test: See above
Test: Manual
Bug: 31008728

Change-Id: Id90cf7ce534b888bf6df1bf1dc9d497608dcdbe9
This commit is contained in:
Neil Fuller
2017-06-22 14:10:29 +01:00
parent a634b38c8e
commit 9c90dc06a3

View File

@@ -17,8 +17,8 @@
package com.android.server.timezone;
import com.android.timezone.distro.DistroVersion;
import com.android.timezone.distro.TimeZoneDistro;
import com.android.timezone.distro.StagedDistroOperation;
import com.android.timezone.distro.TimeZoneDistro;
import org.junit.Before;
import org.junit.Test;
@@ -42,7 +42,7 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.Matchers.eq;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.doThrow;
@@ -284,12 +284,14 @@ public class RulesManagerServiceTest {
mRulesManagerService.requestInstall(parcelFileDescriptor, tokenBytes, callback);
// Request the rules state while the async operation is "happening".
RulesState actualRulesState = mRulesManagerService.getRulesState();
RulesState expectedRuleState = new RulesState(
systemRulesVersion, RulesManagerService.DISTRO_FORMAT_VERSION_SUPPORTED,
true /* operationInProgress */,
RulesState.STAGED_OPERATION_UNKNOWN, null /* stagedDistroRulesVersion */,
RulesState.DISTRO_STATUS_UNKNOWN, null /* installedDistroRulesVersion */);
assertEquals(expectedRuleState, mRulesManagerService.getRulesState());
assertEquals(expectedRuleState, actualRulesState);
}
@Test
@@ -407,13 +409,13 @@ public class RulesManagerServiceTest {
TimeZoneDistro expectedDistro = new TimeZoneDistro(expectedContent);
// Set up the installer.
configureStageInstallExpectation(expectedDistro, TimeZoneDistroInstaller.INSTALL_SUCCESS);
configureStageInstallExpectation(TimeZoneDistroInstaller.INSTALL_SUCCESS);
// Simulate the async execution.
mFakeExecutor.simulateAsyncExecutionOfLastCommand();
// Verify the expected calls were made to other components.
verifyStageInstallCalled(expectedDistro);
verifyStageInstallCalled();
verifyPackageTrackerCalled(token, true /* success */);
// Check the callback was called.
@@ -439,16 +441,14 @@ public class RulesManagerServiceTest {
verifyNoInstallerCallsMade();
callback.assertNoResultReceived();
TimeZoneDistro expectedDistro = new TimeZoneDistro(expectedContent);
// Set up the installer.
configureStageInstallExpectation(expectedDistro, TimeZoneDistroInstaller.INSTALL_SUCCESS);
configureStageInstallExpectation(TimeZoneDistroInstaller.INSTALL_SUCCESS);
// Simulate the async execution.
mFakeExecutor.simulateAsyncExecutionOfLastCommand();
// Verify the expected calls were made to other components.
verifyStageInstallCalled(expectedDistro);
verifyStageInstallCalled();
verifyPackageTrackerCalled(null /* expectedToken */, true /* success */);
// Check the callback was received.
@@ -476,17 +476,14 @@ public class RulesManagerServiceTest {
verifyNoInstallerCallsMade();
callback.assertNoResultReceived();
TimeZoneDistro expectedDistro = new TimeZoneDistro(expectedContent);
// Set up the installer.
configureStageInstallExpectation(
expectedDistro, TimeZoneDistroInstaller.INSTALL_FAIL_VALIDATION_ERROR);
configureStageInstallExpectation(TimeZoneDistroInstaller.INSTALL_FAIL_VALIDATION_ERROR);
// Simulate the async execution.
mFakeExecutor.simulateAsyncExecutionOfLastCommand();
// Verify the expected calls were made to other components.
verifyStageInstallCalled(expectedDistro);
verifyStageInstallCalled();
// Validation failure is treated like a successful check: repeating it won't improve things.
boolean expectedSuccess = true;
@@ -787,9 +784,9 @@ public class RulesManagerServiceTest {
.thenThrow(new IOException("Simulated failure"));
}
private void configureStageInstallExpectation(TimeZoneDistro expected, int resultCode)
private void configureStageInstallExpectation(int resultCode)
throws Exception {
when(mMockTimeZoneDistroInstaller.stageInstallWithErrorCode(eq(expected)))
when(mMockTimeZoneDistroInstaller.stageInstallWithErrorCode(any(TimeZoneDistro.class)))
.thenReturn(resultCode);
}
@@ -797,8 +794,8 @@ public class RulesManagerServiceTest {
doReturn(success).when(mMockTimeZoneDistroInstaller).stageUninstall();
}
private void verifyStageInstallCalled(TimeZoneDistro expected) throws Exception {
verify(mMockTimeZoneDistroInstaller).stageInstallWithErrorCode(eq(expected));
private void verifyStageInstallCalled() throws Exception {
verify(mMockTimeZoneDistroInstaller).stageInstallWithErrorCode(any(TimeZoneDistro.class));
verifyNoMoreInteractions(mMockTimeZoneDistroInstaller);
reset(mMockTimeZoneDistroInstaller);
}