Remove wrapper class for NotificationGroup.

It's no longer needed as Robolectric can natively support framework
classes

Bug: 76167422
Test: robotests
Change-Id: If0ac597370240b8efaa8df8783a5c309a2322a3f
This commit is contained in:
Fan Zhang
2018-03-30 15:50:11 -07:00
parent 234854cb04
commit 1781cf2cef
13 changed files with 74 additions and 157 deletions

View File

@@ -46,7 +46,6 @@ import com.android.settings.R;
import com.android.settings.applications.LayoutPreference;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.widget.SwitchBar;
import com.android.settings.wrapper.NotificationChannelGroupWrapper;
import org.junit.Before;
import org.junit.Test;
@@ -113,7 +112,7 @@ public class BlockPreferenceControllerTest {
public void testIsAvailable_notIfGroupNotBlockable() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.systemApp = true;
mController.onResume(appRow, null, mock(NotificationChannelGroupWrapper.class), null);
mController.onResume(appRow, null, mock(NotificationChannelGroup.class), null);
assertFalse(mController.isAvailable());
}
@@ -166,8 +165,7 @@ public class BlockPreferenceControllerTest {
@Test
public void testUpdateState_group() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannelGroupWrapper group = mock(NotificationChannelGroupWrapper.class);
when(group.getGroup()).thenReturn(mock(NotificationChannelGroup.class));
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
when(group.isBlocked()).thenReturn(true);
mController.onResume(appRow, null, group, null);
mController.updateState(mPreference);

View File

@@ -26,13 +26,12 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.app.NotificationChannel;
import android.app.NotificationChannelGroup;
import android.app.NotificationManager;
import android.content.Context;
import android.os.UserManager;
import android.support.v7.preference.Preference;
import com.android.settings.wrapper.NotificationChannelGroupWrapper;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -82,7 +81,7 @@ public class DeletedChannelsPreferenceControllerTest {
@Test
public void isAvailable_groupScreen_never() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
mController.onResume(appRow, null, mock(NotificationChannelGroupWrapper.class), null);
mController.onResume(appRow, null, mock(NotificationChannelGroup.class), null);
assertFalse(mController.isAvailable());
}

View File

@@ -33,7 +33,6 @@ import android.os.UserManager;
import android.support.v7.preference.Preference;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.wrapper.NotificationChannelGroupWrapper;
import org.junit.Before;
import org.junit.Test;
@@ -79,8 +78,7 @@ public class DescriptionPreferenceControllerTest {
@Test
public void testIsAvailable_notIfChannelGroupBlocked() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannelGroupWrapper group = mock(NotificationChannelGroupWrapper.class);
when(group.isBlocked()).thenReturn(true);
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
mController.onResume(appRow, null, group, null);
assertFalse(mController.isAvailable());
}
@@ -106,8 +104,7 @@ public class DescriptionPreferenceControllerTest {
@Test
public void testIsAvailable_notIfNoChannelGroupDesc() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannelGroupWrapper group = mock(NotificationChannelGroupWrapper.class);
when(group.getGroup()).thenReturn(mock(NotificationChannelGroup.class));
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
mController.onResume(appRow, null, group, null);
assertFalse(mController.isAvailable());
}
@@ -125,8 +122,7 @@ public class DescriptionPreferenceControllerTest {
@Test
public void testIsAvailable_channelGroup() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannelGroupWrapper group = mock(NotificationChannelGroupWrapper.class);
when(group.getGroup()).thenReturn(mock(NotificationChannelGroup.class));
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
when(group.getDescription()).thenReturn("something");
when(group.isBlocked()).thenReturn(false);
mController.onResume(appRow, null, group, null);
@@ -152,8 +148,7 @@ public class DescriptionPreferenceControllerTest {
@Test
public void testUpdateState_channelGroup() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannelGroupWrapper group = mock(NotificationChannelGroupWrapper.class);
when(group.getGroup()).thenReturn(mock(NotificationChannelGroup.class));
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
when(group.getDescription()).thenReturn("something");
mController.onResume(appRow, null, group, null);

View File

@@ -36,7 +36,6 @@ import android.view.View;
import com.android.settings.applications.LayoutPreference;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.wrapper.NotificationChannelGroupWrapper;
import org.junit.Before;
import org.junit.Test;
@@ -104,12 +103,11 @@ public class HeaderPreferenceControllerTest {
assertEquals(appRow.label, mController.getLabel());
NotificationChannelGroup group = new NotificationChannelGroup("id", "name");
NotificationChannelGroupWrapper gWrapper = new NotificationChannelGroupWrapper(group);
mController.onResume(appRow, null, gWrapper, null);
mController.onResume(appRow, null, group, null);
assertEquals(group.getName(), mController.getLabel());
NotificationChannel channel = new NotificationChannel("cid", "cname", IMPORTANCE_NONE);
mController.onResume(appRow, channel, gWrapper, null);
mController.onResume(appRow, channel, group, null);
assertEquals(channel.getName(), mController.getLabel());
}
@@ -121,12 +119,11 @@ public class HeaderPreferenceControllerTest {
assertEquals("", mController.getSummary());
NotificationChannelGroup group = new NotificationChannelGroup("id", "name");
NotificationChannelGroupWrapper gWrapper = new NotificationChannelGroupWrapper(group);
mController.onResume(appRow, null, gWrapper, null);
mController.onResume(appRow, null, group, null);
assertEquals(appRow.label, mController.getSummary());
NotificationChannel channel = new NotificationChannel("cid", "cname", IMPORTANCE_NONE);
mController.onResume(appRow, channel, gWrapper, null);
mController.onResume(appRow, channel, group, null);
assertTrue(mController.getSummary().toString().contains(group.getName()));
assertTrue(mController.getSummary().toString().contains(appRow.label));

View File

@@ -40,7 +40,6 @@ import android.os.UserManager;
import android.support.v7.preference.Preference;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.wrapper.NotificationChannelGroupWrapper;
import com.android.settingslib.RestrictedLockUtils;
import org.junit.Before;
@@ -76,7 +75,7 @@ public class NotificationPreferenceControllerTest {
}
@Test
public void noCrashIfNoOnResume() throws Exception {
public void noCrashIfNoOnResume() {
mController.isAvailable();
mController.updateState(mock(Preference.class));
assertFalse(mController.checkCanBeVisible(IMPORTANCE_UNSPECIFIED));
@@ -87,22 +86,22 @@ public class NotificationPreferenceControllerTest {
}
@Test
public void isAvailable_notIfNull() throws Exception {
public void isAvailable_notIfNull() {
mController.onResume(null, null, null, null);
assertFalse(mController.isAvailable());
}
@Test
public void isAvailable_notIfAppBlocked() throws Exception {
public void isAvailable_notIfAppBlocked() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.banned = true;
mController.onResume(appRow, mock(NotificationChannel.class),
mock(NotificationChannelGroupWrapper.class), null);
mock(NotificationChannelGroup.class), null);
assertFalse(mController.isAvailable());
}
@Test
public void isAvailable_notIfChannelBlocked() throws Exception {
public void isAvailable_notIfChannelBlocked() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_NONE);
@@ -112,10 +111,10 @@ public class NotificationPreferenceControllerTest {
}
@Test
public void isAvailable_notIfChannelGroupBlocked() throws Exception {
public void isAvailable_notIfChannelGroupBlocked() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
NotificationChannelGroupWrapper group = mock(NotificationChannelGroupWrapper.class);
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
mController.onResume(appRow, channel, group, null);
when(group.isBlocked()).thenReturn(true);
@@ -123,11 +122,11 @@ public class NotificationPreferenceControllerTest {
}
@Test
public void isAvailable() throws Exception {
public void isAvailable() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_DEFAULT);
NotificationChannelGroupWrapper group = mock(NotificationChannelGroupWrapper.class);
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
when(group.isBlocked()).thenReturn(false);
mController.onResume(appRow, channel, group, null);
@@ -135,10 +134,10 @@ public class NotificationPreferenceControllerTest {
}
@Test
public void testOnResume() throws Exception {
public void testOnResume() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
NotificationChannelGroupWrapper group = mock(NotificationChannelGroupWrapper.class);
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
RestrictedLockUtils.EnforcedAdmin admin = mock(RestrictedLockUtils.EnforcedAdmin.class);
mController.onResume(appRow, channel, group, admin);
@@ -266,8 +265,7 @@ public class NotificationPreferenceControllerTest {
public void testIsChannelGroupBlockable_nonSystemBlockable() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.systemApp = false;
NotificationChannelGroupWrapper group = mock(NotificationChannelGroupWrapper.class);
when(group.getGroup()).thenReturn(mock(NotificationChannelGroup.class));
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
when(group.isBlocked()).thenReturn(false);
mController.onResume(appRow, null, group, null);
@@ -278,8 +276,7 @@ public class NotificationPreferenceControllerTest {
public void testIsChannelGroupBlockable_SystemNotBlockable() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.systemApp = true;
NotificationChannelGroupWrapper group = mock(NotificationChannelGroupWrapper.class);
when(group.getGroup()).thenReturn(mock(NotificationChannelGroup.class));
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
when(group.isBlocked()).thenReturn(false);
mController.onResume(appRow, null, group, null);
@@ -290,8 +287,7 @@ public class NotificationPreferenceControllerTest {
public void testIsChannelGroupBlockable_canUndoSystemBlock() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.systemApp = true;
NotificationChannelGroupWrapper group = mock(NotificationChannelGroupWrapper.class);
when(group.getGroup()).thenReturn(mock(NotificationChannelGroup.class));
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
when(group.isBlocked()).thenReturn(true);
mController.onResume(appRow, null, group, null);

View File

@@ -17,20 +17,19 @@
package com.android.settings.notification;
import static android.app.NotificationManager.IMPORTANCE_NONE;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertTrue;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import android.app.NotificationChannel;
import android.app.NotificationChannelGroup;
import android.app.NotificationManager;
import android.content.Context;
import android.os.UserManager;
import android.support.v7.preference.Preference;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.wrapper.NotificationChannelGroupWrapper;
import org.junit.Before;
import org.junit.Test;
@@ -70,16 +69,16 @@ public class NotificationsOffPreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.banned = true;
mController.onResume(appRow, null, null, null);
assertTrue(mController.isAvailable());
assertThat(mController.isAvailable()).isTrue();
}
@Test
public void testIsAvailable_yesIfChannelGroupBlocked() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannelGroupWrapper group = mock(NotificationChannelGroupWrapper.class);
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
when(group.isBlocked()).thenReturn(true);
mController.onResume(appRow, null, group, null);
assertTrue(mController.isAvailable());
assertThat(mController.isAvailable()).isTrue();
}
@Test
@@ -88,7 +87,7 @@ public class NotificationsOffPreferenceControllerTest {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_NONE);
mController.onResume(appRow, channel, null, null);
assertTrue(mController.isAvailable());
assertThat(mController.isAvailable()).isTrue();
}
@Test
@@ -101,22 +100,22 @@ public class NotificationsOffPreferenceControllerTest {
Preference pref = new Preference(RuntimeEnvironment.application);
mController.updateState(pref);
assertTrue(pref.getTitle().toString().contains("category"));
assertFalse(pref.isSelectable());
assertThat(pref.getTitle().toString()).contains("category");
assertThat(pref.isSelectable()).isFalse();
}
@Test
public void testUpdateState_channelGroup() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannelGroupWrapper group = mock(NotificationChannelGroupWrapper.class);
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
when(group.isBlocked()).thenReturn(true);
mController.onResume(appRow, null, group, null);
Preference pref = new Preference(RuntimeEnvironment.application);
mController.updateState(pref);
assertTrue(pref.getTitle().toString().contains("group"));
assertFalse(pref.isSelectable());
assertThat(pref.getTitle().toString()).contains("group");
assertThat(pref.isSelectable()).isFalse();
}
@Test
@@ -128,7 +127,7 @@ public class NotificationsOffPreferenceControllerTest {
Preference pref = new Preference(RuntimeEnvironment.application);
mController.updateState(pref);
assertTrue(pref.getTitle().toString().contains("app"));
assertFalse(pref.isSelectable());
assertThat(pref.getTitle().toString()).contains("app");
assertThat(pref.isSelectable()).isFalse();
}
}