Only write network stats when already loaded.

Bug: 5584564
Change-Id: Ife2a68804bf3691e9bccdc167807204bce8a85b2
diff --git a/services/tests/servicestests/src/com/android/server/NetworkPolicyManagerServiceTest.java b/services/tests/servicestests/src/com/android/server/NetworkPolicyManagerServiceTest.java
index 0618374..7c61e9a 100644
--- a/services/tests/servicestests/src/com/android/server/NetworkPolicyManagerServiceTest.java
+++ b/services/tests/servicestests/src/com/android/server/NetworkPolicyManagerServiceTest.java
@@ -693,12 +693,13 @@
             expectSetInterfaceQuota(TEST_IFACE, Long.MAX_VALUE);
             expectMeteredIfacesChanged(TEST_IFACE);
 
-            expectClearNotifications();
+            future = expectClearNotifications();
             tagFuture = expectEnqueueNotification();
 
             replay();
             mService.snoozePolicy(sTemplateWifi);
             assertNotificationType(TYPE_LIMIT_SNOOZED, tagFuture.get());
+            future.get();
             verifyAndReset();
         }
     }
@@ -734,9 +735,11 @@
         expectLastCall().atLeastOnce();
     }
 
-    private void expectClearNotifications() throws Exception {
+    private Future<Void> expectClearNotifications() throws Exception {
+        final FutureAnswer future = new FutureAnswer();
         mNotifManager.cancelNotificationWithTag(isA(String.class), isA(String.class), anyInt());
-        expectLastCall().anyTimes();
+        expectLastCall().andAnswer(future).anyTimes();
+        return future;
     }
 
     private Future<String> expectEnqueueNotification() throws Exception {