Explicitly set other mocking URLConnections to deflake test

The testNotifyNetwork_WithforceReevaluation() interacts with
mock fallback probe URL object, but the URLConnection
initialization for the mocking object is not applied to the
fallback one which may cause test flaky. Also apply to other
URLConnection objects.

The getHeaderField() method should also be explicitly set.

Test: atest NetworkStackTests
Fix: 302851847
Change-Id: I4feedf7b46c0cbb4b903b221b2cc540473ea8052
diff --git a/tests/unit/src/com/android/server/connectivity/NetworkMonitorTest.java b/tests/unit/src/com/android/server/connectivity/NetworkMonitorTest.java
index 6cdc82e..9f02e1e 100644
--- a/tests/unit/src/com/android/server/connectivity/NetworkMonitorTest.java
+++ b/tests/unit/src/com/android/server/connectivity/NetworkMonitorTest.java
@@ -553,6 +553,14 @@
         }).when(mCleartextDnsNetwork).openConnection(any());
         initHttpConnection(mHttpConnection);
         initHttpConnection(mHttpsConnection);
+        initHttpConnection(mFallbackConnection);
+        initHttpConnection(mOtherHttpConnection1);
+        initHttpConnection(mOtherHttpsConnection1);
+        initHttpConnection(mOtherHttpsConnection2);
+        initHttpConnection(mOtherFallbackConnection);
+        initHttpConnection(mTestOverriddenUrlConnection);
+        initHttpConnection(mCapportApiConnection);
+        initHttpConnection(mSpeedTestConnection);
 
         mFakeDns = new FakeDns();
         mFakeDns.startMocking();
@@ -610,6 +618,7 @@
         // Explicitly set the HttpURLConnection methods so that these will not interact with real
         // methods to prevent threading issue in the test.
         doReturn(new HashMap<>()).when(connection).getHeaderFields();
+        doReturn(null).when(connection).getHeaderField(eq("location"));
         doNothing().when(connection).setInstanceFollowRedirects(anyBoolean());
         doNothing().when(connection).setConnectTimeout(anyInt());
         doNothing().when(connection).setReadTimeout(anyInt());