Merge changes Ib497aca6,Ic6def54a into pi-dev am: 5e8a0e2436
am: fc6f4e05da
Change-Id: I44510b8dd49325b913d0d7ad82ceb844f3d98886
This commit is contained in:
@@ -18,10 +18,16 @@ package com.android.settings.fuelgauge.batterytip;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.robolectric.RuntimeEnvironment.application;
|
||||
|
||||
import android.app.job.JobInfo;
|
||||
import android.app.job.JobScheduler;
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
@@ -30,6 +36,7 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.Shadows;
|
||||
import org.robolectric.shadows.ShadowJobScheduler;
|
||||
|
||||
@@ -38,23 +45,39 @@ import java.util.concurrent.TimeUnit;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
public class AnomalyCleanupJobServiceTest {
|
||||
private Context mContext;
|
||||
private JobScheduler mJobScheduler;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
mJobScheduler = spy(mContext.getSystemService(JobScheduler.class));
|
||||
when(mContext.getSystemService(JobScheduler.class)).thenReturn(mJobScheduler);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testScheduleCleanUp() {
|
||||
AnomalyCleanupJobService.scheduleCleanUp(application);
|
||||
AnomalyCleanupJobService.scheduleCleanUp(mContext);
|
||||
|
||||
ShadowJobScheduler shadowJobScheduler =
|
||||
Shadows.shadowOf(application.getSystemService(JobScheduler.class));
|
||||
Shadows.shadowOf(mContext.getSystemService(JobScheduler.class));
|
||||
List<JobInfo> pendingJobs = shadowJobScheduler.getAllPendingJobs();
|
||||
assertEquals(1, pendingJobs.size());
|
||||
JobInfo pendingJob = pendingJobs.get(0);
|
||||
assertThat(pendingJob.getId()).isEqualTo(R.id.job_anomaly_clean_up);
|
||||
assertThat(pendingJob.getId()).isEqualTo(R.integer.job_anomaly_clean_up);
|
||||
assertThat(pendingJob.getIntervalMillis()).isEqualTo(TimeUnit.DAYS.toMillis(1));
|
||||
assertThat(pendingJob.isRequireDeviceIdle()).isTrue();
|
||||
assertThat(pendingJob.isRequireCharging()).isTrue();
|
||||
assertThat(pendingJob.isPersisted()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testScheduleCleanUp_invokeTwice_onlyScheduleOnce() {
|
||||
AnomalyCleanupJobService.scheduleCleanUp(mContext);
|
||||
AnomalyCleanupJobService.scheduleCleanUp(mContext);
|
||||
|
||||
verify(mJobScheduler, times(1)).schedule(any());
|
||||
}
|
||||
}
|
||||
|
@@ -25,7 +25,9 @@ import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.robolectric.RuntimeEnvironment.application;
|
||||
|
||||
import android.app.StatsManager;
|
||||
@@ -43,6 +45,7 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.Shadows;
|
||||
import org.robolectric.shadows.ShadowJobScheduler;
|
||||
|
||||
@@ -57,12 +60,18 @@ public class AnomalyConfigJobServiceTest {
|
||||
@Mock
|
||||
private StatsManager mStatsManager;
|
||||
|
||||
private Context mContext;
|
||||
private JobScheduler mJobScheduler;
|
||||
private AnomalyConfigJobService mJobService;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
mJobScheduler = spy(mContext.getSystemService(JobScheduler.class));
|
||||
when(mContext.getSystemService(JobScheduler.class)).thenReturn(mJobScheduler);
|
||||
|
||||
mJobService = spy(new AnomalyConfigJobService());
|
||||
doReturn(application.getSharedPreferences(AnomalyConfigJobService.PREF_DB,
|
||||
Context.MODE_PRIVATE)).when(mJobService).getSharedPreferences(anyString(),
|
||||
@@ -71,18 +80,27 @@ public class AnomalyConfigJobServiceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testScheduleCleanUp() {
|
||||
AnomalyConfigJobService.scheduleConfigUpdate(application);
|
||||
public void testScheduleConfigUpdate() {
|
||||
AnomalyConfigJobService.scheduleConfigUpdate(mContext);
|
||||
|
||||
ShadowJobScheduler shadowJobScheduler =
|
||||
Shadows.shadowOf(application.getSystemService(JobScheduler.class));
|
||||
Shadows.shadowOf(mContext.getSystemService(JobScheduler.class));
|
||||
List<JobInfo> pendingJobs = shadowJobScheduler.getAllPendingJobs();
|
||||
assertEquals(1, pendingJobs.size());
|
||||
JobInfo pendingJob = pendingJobs.get(0);
|
||||
assertThat(pendingJob.getId()).isEqualTo(R.id.job_anomaly_config_update);
|
||||
assertThat(pendingJob.getId()).isEqualTo(R.integer.job_anomaly_config_update);
|
||||
assertThat(pendingJob.getIntervalMillis()).isEqualTo(TimeUnit.DAYS.toMillis(1));
|
||||
assertThat(pendingJob.isRequireDeviceIdle()).isTrue();
|
||||
assertThat(pendingJob.isRequireCharging()).isTrue();
|
||||
assertThat(pendingJob.isPersisted()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testScheduleConfigUpdate_invokeTwice_onlyScheduleOnce() {
|
||||
AnomalyConfigJobService.scheduleConfigUpdate(mContext);
|
||||
AnomalyConfigJobService.scheduleConfigUpdate(mContext);
|
||||
|
||||
verify(mJobScheduler, times(1)).schedule(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -113,7 +113,7 @@ public class AnomalyDetectionJobServiceTest {
|
||||
assertThat(pendingJobs).hasSize(1);
|
||||
|
||||
JobInfo pendingJob = pendingJobs.get(0);
|
||||
assertThat(pendingJob.getId()).isEqualTo(R.id.job_anomaly_detection);
|
||||
assertThat(pendingJob.getId()).isEqualTo(R.integer.job_anomaly_detection);
|
||||
assertThat(pendingJob.getMaxExecutionDelayMillis())
|
||||
.isEqualTo(TimeUnit.MINUTES.toMillis(30));
|
||||
}
|
||||
|
Reference in New Issue
Block a user