|
| 1 | +/* |
| 2 | + * Copyright 2022 Google LLC |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package com.google.devtools.mobileharness.platform.android.appcrawler; |
| 18 | + |
| 19 | +import static org.mockito.Mockito.verify; |
| 20 | + |
| 21 | +import com.google.devtools.mobileharness.platform.android.lightning.apkinstaller.ApkInstaller; |
| 22 | +import com.google.wireless.qa.mobileharness.shared.api.device.Device; |
| 23 | +import com.google.wireless.qa.mobileharness.shared.api.device.NoOpDevice; |
| 24 | +import com.google.wireless.qa.mobileharness.shared.model.job.JobInfo; |
| 25 | +import com.google.wireless.qa.mobileharness.shared.model.job.JobLocator; |
| 26 | +import com.google.wireless.qa.mobileharness.shared.model.job.TestInfo; |
| 27 | +import com.google.wireless.qa.mobileharness.shared.proto.Job.JobType; |
| 28 | +import com.google.wireless.qa.mobileharness.shared.proto.spec.driver.AndroidRoboTestSpec; |
| 29 | +import org.junit.Before; |
| 30 | +import org.junit.Rule; |
| 31 | +import org.junit.Test; |
| 32 | +import org.junit.runner.RunWith; |
| 33 | +import org.junit.runners.JUnit4; |
| 34 | +import org.mockito.Mock; |
| 35 | +import org.mockito.junit.MockitoJUnit; |
| 36 | +import org.mockito.junit.MockitoRule; |
| 37 | + |
| 38 | +@RunWith(JUnit4.class) |
| 39 | +public class PostProcessorTest { |
| 40 | + @Rule public final MockitoRule rule = MockitoJUnit.rule(); |
| 41 | + |
| 42 | + @Mock private ApkInstaller apkInstaller; |
| 43 | + |
| 44 | + private PostProcessor postProcessor; |
| 45 | + |
| 46 | + @Before |
| 47 | + public void setUp() throws Exception { |
| 48 | + postProcessor = new PostProcessor(apkInstaller); |
| 49 | + } |
| 50 | + |
| 51 | + @Test |
| 52 | + public void uninstallApks_completes() throws Exception { |
| 53 | + TestInfo testInfo = setUpJobInfo().tests().add("some test"); |
| 54 | + Device device = new NoOpDevice("device_name"); |
| 55 | + |
| 56 | + AndroidRoboTestSpec spec = |
| 57 | + AndroidRoboTestSpec.newBuilder() |
| 58 | + .setCrawlerPackageId("androidx.test.tools.crawler") |
| 59 | + .setStubAppPackageId("androidx.test.tools.crawler.stubapp") |
| 60 | + .build(); |
| 61 | + postProcessor.uninstallApks(testInfo, device, spec); |
| 62 | + |
| 63 | + verify(apkInstaller).uninstallApk(device, "androidx.test.tools.crawler", true, testInfo.log()); |
| 64 | + verify(apkInstaller) |
| 65 | + .uninstallApk(device, "androidx.test.tools.crawler.stubapp", true, testInfo.log()); |
| 66 | + } |
| 67 | + |
| 68 | + private JobInfo setUpJobInfo() { |
| 69 | + return JobInfo.newBuilder() |
| 70 | + .setLocator(new JobLocator("job_id", "job_name")) |
| 71 | + .setType(JobType.newBuilder().setDevice("device_type").setDriver("AndroidRoboTest").build()) |
| 72 | + .build(); |
| 73 | + } |
| 74 | +} |
0 commit comments