### Question:
ProxyNetworkAgent { @MainThread protected void setUpNetworkAgent( @Nullable final String reason, @Nullable final String companionName, @Nullable final Listener listener) { DebugAssert.isMainThread(); doSetUpNetworkAgent(reason, companionName, mCurrentNetworkScore, listener, ProxyNetworkAgent.ALWAYS_CREATE_AGENT); } protected  ProxyNetworkAgent(
            @NonNull final Context context,
            @NonNull final NetworkCapabilities capabilities,
            @NonNull final ProxyLinkProperties proxyLinkProperties); @AnyThread void dump(@NonNull final IndentingPrintWriter ipw);  }### Answer:
@Test public void testSetUpNetworkAgent_NoAgent() { mProxyNetworkAgent.mCurrentNetworkAgent = null; mProxyNetworkAgent.setUpNetworkAgent(REASON, COMPANION_NAME, null); assertEquals(1, mProxyNetworkAgent.mNetworkAgents.size()); }
@Test public void testSetUpNetworkAgent_ExistingAgentReUse() { setupNetworkAgent(); mProxyNetworkAgent.setUpNetworkAgent(REASON, COMPANION_NAME, null); assertEquals(2, mProxyNetworkAgent.mNetworkAgents.size()); assertNotEquals(mockNetworkAgent, mProxyNetworkAgent.mCurrentNetworkAgent); }
@Test public void testSetUpNetworkAgent_ExistingAgentForceNew() { setupNetworkAgent(); mProxyNetworkAgent.setUpNetworkAgent(REASON, COMPANION_NAME, null); assertEquals(2, mProxyNetworkAgent.mNetworkAgents.size()); assertNotEquals(mockNetworkAgent, mProxyNetworkAgent.mCurrentNetworkAgent); }
@Test public void testTearDownNetworkAgent_NoAgentForceNew() { mProxyNetworkAgent.mCurrentNetworkAgent = null; mProxyNetworkAgent.setUpNetworkAgent(REASON, COMPANION_NAME, null); assertEquals(1, mProxyNetworkAgent.mNetworkAgents.size()); assertNotNull(mProxyNetworkAgent.mCurrentNetworkAgent); NetworkAgentHelper.callUnwanted(mProxyNetworkAgent.mCurrentNetworkAgent); assertTrue(mProxyNetworkAgent.mNetworkAgents.isEmpty()); assertNull(mProxyNetworkAgent.mCurrentNetworkAgent); }
@Test public void testTearDownNetworkAgent_ExistingAgentForceNew() { mProxyNetworkAgent.setUpNetworkAgent(REASON, COMPANION_NAME, null); assertEquals(1, mProxyNetworkAgent.mNetworkAgents.size()); assertNotNull(mProxyNetworkAgent.mCurrentNetworkAgent); NetworkAgent unwantedAgent = mProxyNetworkAgent.mCurrentNetworkAgent; mProxyNetworkAgent.setUpNetworkAgent(REASON, COMPANION_NAME, null); assertEquals(2, mProxyNetworkAgent.mNetworkAgents.size()); NetworkAgentHelper.callUnwanted(unwantedAgent); assertEquals(1, mProxyNetworkAgent.mNetworkAgents.size()); }
@Test public void testTearDownNetworkAgent_ExistingAgentForceNewButMissingFromHash() { mProxyNetworkAgent.setUpNetworkAgent(REASON, COMPANION_NAME, null); assertEquals(1, mProxyNetworkAgent.mNetworkAgents.size()); assertNotNull(mProxyNetworkAgent.mCurrentNetworkAgent); NetworkAgent unwantedAgent = mProxyNetworkAgent.mCurrentNetworkAgent; mProxyNetworkAgent.setUpNetworkAgent(REASON, COMPANION_NAME, null); assertEquals(2, mProxyNetworkAgent.mNetworkAgents.size()); mProxyNetworkAgent.mNetworkAgents.remove(unwantedAgent); NetworkAgentHelper.callUnwanted(unwantedAgent); assertEquals(1, mProxyNetworkAgent.mNetworkAgents.size()); }