Remove LooperMode.LEGACY usage from settings/notification
Bug: 333808868 Test: atest Change-Id: I11d68462adf60a02224306e848f9280cd1bdad4f
This commit is contained in:
@@ -44,26 +44,27 @@ import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||
import com.google.common.base.Strings;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.mockito.junit.MockitoJUnit;
|
||||
import org.mockito.junit.MockitoRule;
|
||||
import org.mockito.stubbing.Answer;
|
||||
import org.robolectric.Robolectric;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.annotation.LooperMode;
|
||||
import org.robolectric.shadows.ShadowApplication;
|
||||
import org.robolectric.shadows.ShadowLooper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@LooperMode(LooperMode.Mode.LEGACY)
|
||||
@Config(shadows = {ShadowBluetoothUtils.class})
|
||||
public class NotificationAccessSettingsTest {
|
||||
@Rule
|
||||
public final MockitoRule mMockitoRule = MockitoJUnit.rule();
|
||||
|
||||
private Context mContext;
|
||||
private NotificationAccessSettings mAccessSettings;
|
||||
@Mock
|
||||
private NotificationManager mNotificationManager;
|
||||
@@ -72,9 +73,6 @@ public class NotificationAccessSettingsTest {
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
mContext = RuntimeEnvironment.application;
|
||||
ShadowApplication shadowApp = ShadowApplication.getInstance();
|
||||
shadowApp.setSystemService(Context.NOTIFICATION_SERVICE, mNotificationManager);
|
||||
|
||||
@@ -92,6 +90,7 @@ public class NotificationAccessSettingsTest {
|
||||
mAccessSettings.mNm = mNotificationManager;
|
||||
mAccessSettings.mPm = mPackageManager;
|
||||
ShadowBluetoothUtils.sLocalBluetoothManager = mock(LocalBluetoothManager.class);
|
||||
ShadowLooper.idleMainLooper();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -42,21 +42,25 @@ import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.mockito.junit.MockitoJUnit;
|
||||
import org.mockito.junit.MockitoRule;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.annotation.LooperMode;
|
||||
import org.robolectric.shadows.ShadowApplication;
|
||||
import org.robolectric.android.util.concurrent.PausedExecutorService;
|
||||
import org.robolectric.shadows.ShadowLooper;
|
||||
import org.robolectric.shadows.ShadowPausedAsyncTask;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@LooperMode(LooperMode.Mode.LEGACY)
|
||||
public class AppChannelsBypassingDndPreferenceControllerTest {
|
||||
|
||||
@Rule
|
||||
public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
|
||||
|
||||
@Rule
|
||||
public final MockitoRule mMockitoRule = MockitoJUnit.rule();
|
||||
|
||||
@Mock
|
||||
private NotificationBackend mBackend;
|
||||
|
||||
@@ -65,11 +69,13 @@ public class AppChannelsBypassingDndPreferenceControllerTest {
|
||||
|
||||
private PreferenceScreen mPreferenceScreen;
|
||||
private PreferenceCategory mCategory;
|
||||
private PausedExecutorService mExecutorService;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
Context context = ApplicationProvider.getApplicationContext();
|
||||
mExecutorService = new PausedExecutorService();
|
||||
ShadowPausedAsyncTask.overrideExecutor(mExecutorService);
|
||||
|
||||
mAppRow = new NotificationBackend.AppRow();
|
||||
mAppRow.uid = 42;
|
||||
@@ -91,7 +97,8 @@ public class AppChannelsBypassingDndPreferenceControllerTest {
|
||||
buildGroupList(true, true, false));
|
||||
|
||||
mController.displayPreference(mPreferenceScreen);
|
||||
ShadowApplication.runBackgroundTasks();
|
||||
mExecutorService.runAll();
|
||||
ShadowLooper.idleMainLooper();
|
||||
|
||||
assertThat(mCategory.getPreferenceCount()).isEqualTo(4); // "All" + 3 channels
|
||||
assertThat(mCategory.getPreference(0).getTitle().toString()).isEqualTo(
|
||||
@@ -107,7 +114,8 @@ public class AppChannelsBypassingDndPreferenceControllerTest {
|
||||
buildGroupList(true, true, false));
|
||||
|
||||
mController.displayPreference(mPreferenceScreen);
|
||||
ShadowApplication.runBackgroundTasks();
|
||||
mExecutorService.runAll();
|
||||
ShadowLooper.idleMainLooper();
|
||||
|
||||
assertThat(mCategory.getPreference(0).isEnabled()).isTrue();
|
||||
}
|
||||
@@ -118,7 +126,8 @@ public class AppChannelsBypassingDndPreferenceControllerTest {
|
||||
buildGroupList(true, false, true));
|
||||
|
||||
mController.displayPreference(mPreferenceScreen);
|
||||
ShadowApplication.runBackgroundTasks();
|
||||
mExecutorService.runAll();
|
||||
ShadowLooper.idleMainLooper();
|
||||
|
||||
assertThat(((PrimarySwitchPreference) mCategory.getPreference(
|
||||
1)).isSwitchEnabled()).isTrue();
|
||||
@@ -135,7 +144,8 @@ public class AppChannelsBypassingDndPreferenceControllerTest {
|
||||
buildGroupList(true, false, true));
|
||||
|
||||
mController.displayPreference(mPreferenceScreen);
|
||||
ShadowApplication.runBackgroundTasks();
|
||||
mExecutorService.runAll();
|
||||
ShadowLooper.idleMainLooper();
|
||||
|
||||
assertThat(mCategory.getPreference(0).isEnabled()).isFalse();
|
||||
assertThat(((PrimarySwitchPreference) mCategory.getPreference(
|
||||
@@ -185,7 +195,9 @@ public class AppChannelsBypassingDndPreferenceControllerTest {
|
||||
|
||||
when(mBackend.getGroups(eq(mAppRow.pkg), eq(mAppRow.uid))).thenReturn(groups);
|
||||
mController.displayPreference(mPreferenceScreen);
|
||||
ShadowApplication.runBackgroundTasks();
|
||||
mExecutorService.runAll();
|
||||
ShadowLooper.idleMainLooper();
|
||||
|
||||
// Check that we've added the group name as a summary to channels that have identical names.
|
||||
// Channels are also alphabetized.
|
||||
assertThat(mCategory.getPreference(1).getTitle().toString()).isEqualTo("Mail");
|
||||
|
@@ -37,20 +37,24 @@ import androidx.test.core.app.ApplicationProvider;
|
||||
import com.android.settings.notification.NotificationBackend;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.mockito.junit.MockitoJUnit;
|
||||
import org.mockito.junit.MockitoRule;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.annotation.LooperMode;
|
||||
import org.robolectric.shadows.ShadowApplication;
|
||||
import org.robolectric.android.util.concurrent.PausedExecutorService;
|
||||
import org.robolectric.shadows.ShadowLooper;
|
||||
import org.robolectric.shadows.ShadowPausedAsyncTask;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@LooperMode(LooperMode.Mode.LEGACY)
|
||||
public class AppConversationListPreferenceControllerTest {
|
||||
@Rule
|
||||
public final MockitoRule mMockitoRule = MockitoJUnit.rule();
|
||||
|
||||
private Context mContext;
|
||||
|
||||
@@ -60,11 +64,13 @@ public class AppConversationListPreferenceControllerTest {
|
||||
private AppConversationListPreferenceController mController;
|
||||
private NotificationBackend.AppRow mAppRow;
|
||||
private PreferenceCategory mPreference;
|
||||
private PausedExecutorService mExecutorService;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = ApplicationProvider.getApplicationContext();
|
||||
mExecutorService = new PausedExecutorService();
|
||||
ShadowPausedAsyncTask.overrideExecutor(mExecutorService);
|
||||
|
||||
mAppRow = new NotificationBackend.AppRow();
|
||||
mAppRow.uid = 42;
|
||||
@@ -88,7 +94,8 @@ public class AppConversationListPreferenceControllerTest {
|
||||
));
|
||||
|
||||
mController.updateState(mPreference);
|
||||
ShadowApplication.runBackgroundTasks();
|
||||
mExecutorService.runAll();
|
||||
ShadowLooper.idleMainLooper();
|
||||
|
||||
assertThat(mPreference.isVisible()).isTrue();
|
||||
assertThat(mPreference.getPreferenceCount()).isEqualTo(2);
|
||||
@@ -107,7 +114,8 @@ public class AppConversationListPreferenceControllerTest {
|
||||
));
|
||||
|
||||
mController.updateState(mPreference);
|
||||
ShadowApplication.runBackgroundTasks();
|
||||
mExecutorService.runAll();
|
||||
ShadowLooper.idleMainLooper();
|
||||
|
||||
assertThat(mPreference.isVisible()).isTrue();
|
||||
assertThat(mPreference.getPreferenceCount()).isEqualTo(1);
|
||||
@@ -120,6 +128,8 @@ public class AppConversationListPreferenceControllerTest {
|
||||
.thenReturn(conversationList());
|
||||
|
||||
mController.updateState(mPreference);
|
||||
mExecutorService.runAll();
|
||||
ShadowLooper.idleMainLooper();
|
||||
|
||||
assertThat(mPreference.isVisible()).isFalse();
|
||||
assertThat(mPreference.getPreferenceCount()).isEqualTo(0);
|
||||
@@ -130,6 +140,9 @@ public class AppConversationListPreferenceControllerTest {
|
||||
when(mBackend.getConversations(eq(mAppRow.pkg), eq(mAppRow.uid)))
|
||||
.thenReturn(conversationList());
|
||||
mController.updateState(mPreference);
|
||||
mExecutorService.runAll();
|
||||
ShadowLooper.idleMainLooper();
|
||||
|
||||
assertThat(mPreference.isVisible()).isFalse();
|
||||
|
||||
// Empty -> present
|
||||
@@ -138,6 +151,9 @@ public class AppConversationListPreferenceControllerTest {
|
||||
conversationChannel("1", "msg", "Mario", "Messages", "M", false)
|
||||
));
|
||||
mController.updateState(mPreference);
|
||||
mExecutorService.runAll();
|
||||
ShadowLooper.idleMainLooper();
|
||||
|
||||
assertThat(mPreference.isVisible()).isTrue();
|
||||
assertThat(mPreference.getPreferenceCount()).isEqualTo(1);
|
||||
|
||||
@@ -145,6 +161,9 @@ public class AppConversationListPreferenceControllerTest {
|
||||
when(mBackend.getConversations(eq(mAppRow.pkg), eq(mAppRow.uid)))
|
||||
.thenReturn(conversationList());
|
||||
mController.updateState(mPreference);
|
||||
mExecutorService.runAll();
|
||||
ShadowLooper.idleMainLooper();
|
||||
|
||||
assertThat(mPreference.isVisible()).isFalse();
|
||||
assertThat(mPreference.getPreferenceCount()).isEqualTo(0);
|
||||
}
|
||||
|
Reference in New Issue
Block a user