From 0a66e0791d128c10ad63beef92b1ff7852221482 Mon Sep 17 00:00:00 2001 From: Mady Mellor Date: Mon, 30 Jan 2017 13:57:58 -0800 Subject: [PATCH] Fix NotificationGuts tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - NPE’s ‘cause there was no interaction listener set in the tests, added this to test set up - Failures with saving importance because closeControls no longer saves any changes, it just closes the controls now. Updated those tests to use saveImportance instead. - Removed the test ensuring that closeControls wouldn’t save importance if it was passed save = false, since closeControls no longer does that. Test: NotificationGuts tests no longer fail (runtest systemui) Change-Id: I3251f4f379654f4cc9eb3a506b722e515c6fe971 --- .../statusbar/NotificationGutsTest.java | 35 +++++++------------ 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationGutsTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationGutsTest.java index 166fcb1e8a6a0..3e0d15d3cb69b 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationGutsTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationGutsTest.java @@ -63,6 +63,7 @@ public class NotificationGutsTest { private static final String TEST_CHANNEL = "test_channel"; private static final String TEST_CHANNEL_NAME = "TEST CHANNEL NAME"; + private NotificationGuts mNotificationGuts; private NotificationInfo mNotificationInfo; private final INotificationManager mMockINotificationManager = mock(INotificationManager.class); private final PackageManager mMockPackageManager = mock(PackageManager.class); @@ -78,6 +79,9 @@ public class NotificationGutsTest { LayoutInflater.from(InstrumentationRegistry.getTargetContext()); mNotificationInfo = (NotificationInfo) layoutInflater.inflate(R.layout.notification_info, null); + mNotificationGuts = (NotificationGuts) layoutInflater.inflate(R.layout.notification_guts, + null); + mNotificationInfo.setInteractionListener(mNotificationGuts); // PackageManager must return a packageInfo and applicationInfo. final PackageInfo packageInfo = new PackageInfo(); @@ -198,56 +202,43 @@ public class NotificationGutsTest { @Test @UiThreadTest - public void testCloseControls_DoesNotUpdateNotificationChannelIfUnchanged() throws Exception { + public void testSaveImportance_DoesNotUpdateNotificationChannelIfUnchanged() throws Exception { mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, mMockStatusBarNotification, mNotificationChannel, null, null, null); - mNotificationInfo.closeControls(); + mNotificationInfo.saveImportance(); verify(mMockINotificationManager, never()).updateNotificationChannelForPackage( anyString(), anyInt(), any()); } @Test @UiThreadTest - public void testCloseControls_DoesNotUpdateNotificationChannelIfUnspecified() throws Exception { + public void testSaveImportance_DoesNotUpdateNotificationChannelIfUnspecified() + throws Exception { mNotificationChannel.setImportance(NotificationManager.IMPORTANCE_UNSPECIFIED); mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, mMockStatusBarNotification, mNotificationChannel, null, null, null); - mNotificationInfo.closeControls(); + mNotificationInfo.saveImportance(); verify(mMockINotificationManager, never()).updateNotificationChannelForPackage( anyString(), anyInt(), any()); } @Test @UiThreadTest - public void testCloseControls_CallsUpdateNotificationChannelIfChanged() throws Exception { + public void testSaveImportance_CallsUpdateNotificationChannelIfChanged() throws Exception { mNotificationChannel.setImportance(NotificationManager.IMPORTANCE_LOW); mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, mMockStatusBarNotification, mNotificationChannel, null, null, null); RadioButton highButton = (RadioButton) mNotificationInfo.findViewById(R.id.high_importance); highButton.setChecked(true); - mNotificationInfo.closeControls(); + mNotificationInfo.saveImportance(); verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage( eq(TEST_PACKAGE_NAME), anyInt(), eq(mNotificationChannel)); assertEquals(NotificationManager.IMPORTANCE_HIGH, mNotificationChannel.getImportance()); } - @Test - @UiThreadTest - public void testCloseControls_DoesNotUpdateNotificationChannelIfSaveFalse() throws Exception { - mNotificationChannel.setImportance(NotificationManager.IMPORTANCE_LOW); - mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, - mMockStatusBarNotification, mNotificationChannel, null, null, null); - - RadioButton highButton = (RadioButton) mNotificationInfo.findViewById(R.id.high_importance); - highButton.setChecked(true); - mNotificationInfo.closeControls(); - verify(mMockINotificationManager, never()).updateNotificationChannelForPackage( - anyString(), anyInt(), any()); - } - @Test @UiThreadTest public void testEnabledSwitchOnByDefault() throws Exception { @@ -292,7 +283,7 @@ public class NotificationGutsTest { Switch enabledSwitch = (Switch) mNotificationInfo.findViewById(R.id.channel_enabled_switch); enabledSwitch.setChecked(false); - mNotificationInfo.closeControls(); + mNotificationInfo.saveImportance(); verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage( eq(TEST_PACKAGE_NAME), anyInt(), eq(mNotificationChannel)); } @@ -308,7 +299,7 @@ public class NotificationGutsTest { RadioButton lowButton = (RadioButton) mNotificationInfo.findViewById(R.id.low_importance); lowButton.setChecked(true); enabledSwitch.setChecked(false); - mNotificationInfo.closeControls(); + mNotificationInfo.saveImportance(); assertEquals(NotificationManager.IMPORTANCE_NONE, mNotificationChannel.getImportance()); } }