Merge "[Settings] enhancing data saver config control"

This commit is contained in:
Bonian Chen
2022-11-10 11:21:20 +00:00
committed by Android (Google) Code Review
4 changed files with 34 additions and 1 deletions

View File

@@ -18,9 +18,13 @@ package com.android.settings.applications.specialaccess;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.spy;
import android.content.Context;
import android.content.res.Resources;
import com.android.settings.R;
import org.junit.Before;
import org.junit.Test;
@@ -34,23 +38,35 @@ import org.robolectric.annotation.Config;
public class DataSaverControllerTest {
private Context mContext;
private Resources mResources;
private DataSaverController mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application.getApplicationContext());
mResources = spy(mContext.getResources());
when(mContext.getResources()).thenReturn(mResources);
mController = new DataSaverController(mContext, "key");
}
@Test
public void testDataSaver_byDefault_shouldBeShown() {
when(mResources.getBoolean(R.bool.config_show_data_saver)).thenReturn(true);
assertThat(mController.isAvailable()).isTrue();
}
@Test
@Config(qualifiers = "mcc999")
public void testDataSaver_ifDisabledByCarrier_shouldNotBeShown() {
assertThat(mController.isAvailable()).isFalse();
}
@Test
public void testDataSaver_ifDisabled_shouldNotBeShown() {
when(mResources.getBoolean(R.bool.config_show_data_saver)).thenReturn(false);
assertThat(mController.isAvailable()).isFalse();
}
}