Fix NetworkNotificationManagerTest

The testNotificationsShownAndCleared test was not doing anything
because the list of notification to show was always empty.

This patch fixes this issue and actually makes the test loop on
non-empty collections, and also fixes another ordering issue in
assertions themselves, hidden until now by the first issue.

Test: runtest -x frameworks/base/tests/net/java/com/android/server/connectivity/NetworkNotificationManagerTest.java
Change-Id: I4837b1175d7c9133e9156e33acaa1e7e3341cc62
This commit is contained in:
Hugo Benichi
2017-03-23 12:32:27 +09:00
parent 2dbe719d4f
commit 9eec272054

View File

@@ -91,7 +91,7 @@ public class NetworkNotificationManagerTest extends TestCase {
final int NETWORK_ID_BASE = 100; final int NETWORK_ID_BASE = 100;
List<NotificationType> types = Arrays.asList(NotificationType.values()); List<NotificationType> types = Arrays.asList(NotificationType.values());
List<Integer> ids = new ArrayList<>(types.size()); List<Integer> ids = new ArrayList<>(types.size());
for (int i = 0; i < ids.size(); i++) { for (int i = 0; i < types.size(); i++) {
ids.add(NETWORK_ID_BASE + i); ids.add(NETWORK_ID_BASE + i);
} }
Collections.shuffle(ids); Collections.shuffle(ids);
@@ -101,9 +101,10 @@ public class NetworkNotificationManagerTest extends TestCase {
mManager.showNotification(ids.get(i), types.get(i), mWifiNai, mCellNai, null, false); mManager.showNotification(ids.get(i), types.get(i), mWifiNai, mCellNai, null, false);
} }
Collections.shuffle(ids); List<Integer> idsToClear = new ArrayList<>(ids);
Collections.shuffle(idsToClear);
for (int i = 0; i < ids.size(); i++) { for (int i = 0; i < ids.size(); i++) {
mManager.clearNotification(ids.get(i)); mManager.clearNotification(idsToClear.get(i));
} }
for (int i = 0; i < ids.size(); i++) { for (int i = 0; i < ids.size(); i++) {