### Question:
WearProxyNetworkAgent { public boolean isProxyConnected() { return mIsProxyConnected; } WearProxyNetworkAgent(ConnectivityManager connectivityManager); void addListener(Listener listener); boolean isProxyConnected();  }### Answer:
@Test public void testNotifyProxyChanges() { Assert.assertTrue(mAgent.isProxyConnected()); mNetworkCallback.onLost(mockProxyNetwork); verify(mockListener).onProxyConnectionChange(false); Assert.assertFalse(mAgent.isProxyConnected()); reset(mockListener); mNetworkCallback.onAvailable(mockProxyNetwork); verify(mockListener).onProxyConnectionChange(true); Assert.assertTrue(mAgent.isProxyConnected()); }
@Test public void testConstructorWithDifferentTransportConnected() { when(mockProxyNetworkInfo.isConnected()).thenReturn(true); when(mockProxyNetworkInfo.getType()).thenReturn(ConnectivityManager.TYPE_WIFI); WearProxyNetworkAgent agent = new WearProxyNetworkAgent(mockConnectivityMgr); Assert.assertFalse(agent.isProxyConnected()); }
@Test public void testConstructorWithProxyDisconnected() { when(mockProxyNetworkInfo.isConnected()).thenReturn(false); when(mockProxyNetworkInfo.getType()).thenReturn(ConnectivityManager.TYPE_PROXY); WearProxyNetworkAgent agent = new WearProxyNetworkAgent(mockConnectivityMgr); Assert.assertFalse(agent.isProxyConnected()); }
@Test public void testConstructorWithNoNetworks() { when(mockConnectivityMgr.getAllNetworks()).thenReturn(new Network[0]); when(mockConnectivityMgr.getNetworkInfo(mockProxyNetwork)).thenReturn(null); WearProxyNetworkAgent agent = new WearProxyNetworkAgent(mockConnectivityMgr); Assert.assertFalse(agent.isProxyConnected()); }
@Test public void testNotifyProxyChanges() { assertTrue(mAgent.isProxyConnected()); mNetworkCallback.onLost(mockProxyNetwork); verify(mockListener).onProxyConnectionChange(false); assertFalse(mAgent.isProxyConnected()); reset(mockListener); mNetworkCallback.onAvailable(mockProxyNetwork); verify(mockListener).onProxyConnectionChange(true); assertTrue(mAgent.isProxyConnected()); }
@Test public void testConstructorWithDifferentTransportConnected() { when(mockProxyNetworkInfo.isConnected()).thenReturn(true); when(mockProxyNetworkInfo.getType()).thenReturn(ConnectivityManager.TYPE_WIFI); WearProxyNetworkAgent agent = new WearProxyNetworkAgent(mockConnectivityMgr); assertFalse(agent.isProxyConnected()); }
@Test public void testConstructorWithProxyDisconnected() { when(mockProxyNetworkInfo.isConnected()).thenReturn(false); when(mockProxyNetworkInfo.getType()).thenReturn(ConnectivityManager.TYPE_PROXY); WearProxyNetworkAgent agent = new WearProxyNetworkAgent(mockConnectivityMgr); assertFalse(agent.isProxyConnected()); }
@Test public void testConstructorWithNoNetworks() { when(mockConnectivityMgr.getAllNetworks()).thenReturn(new Network[0]); when(mockConnectivityMgr.getNetworkInfo(mockProxyNetwork)).thenReturn(null); WearProxyNetworkAgent agent = new WearProxyNetworkAgent(mockConnectivityMgr); assertFalse(agent.isProxyConnected()); }