Source:
public void onCapabilitiesChanged_callsRefreshIfNecessary() { NetworkCapabilities nc = makeNetworkCapabilities(); when(mockConnectivityManager.getNetworkCapabilities(mockNetwork)) .thenReturn(new NetworkCapabilities(nc)); String summary = "Connected, no Internet"; when(mockAccessPoint.getSettingsSummary()).thenReturn(summary); InOrder inOrder = inOrder(mockHeaderController); displayAndResume(); inOrder.verify(mockHeaderController).setSummary(summary); summary = "Connected"; when(mockAccessPoint.getSettingsSummary()).thenReturn(summary); updateNetworkCapabilities(nc); inOrder.verify(mockHeaderController, never()).setSummary(any(CharSequence.class)); nc.addCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED); updateNetworkCapabilities(nc); inOrder.verify(mockHeaderController).setSummary(summary); summary = "Connected, no Internet"; when(mockAccessPoint.getSettingsSummary()).thenReturn(summary); updateNetworkCapabilities(nc); inOrder.verify(mockHeaderController, never()).setSummary(any(CharSequence.class)); nc.removeCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED); updateNetworkCapabilities(nc); inOrder.verify(mockHeaderController).setSummary(summary); summary = "Private DNS server can't be accessed"; when(mockAccessPoint.getSettingsSummary(true )) .thenReturn(summary); nc.setPrivateDnsBroken(true); updateNetworkCapabilities(nc); inOrder.verify(mockHeaderController).setSummary(summary); summary = "Limited connection"; when(mockAccessPoint.getSettingsSummary()).thenReturn(summary); nc.addCapability(NetworkCapabilities.NET_CAPABILITY_PARTIAL_CONNECTIVITY); updateNetworkCapabilities(nc); inOrder.verify(mockHeaderController).setSummary(summary); nc.addCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED); updateNetworkCapabilities(nc); inOrder.verify(mockHeaderController).setSummary(summary); }

Target:
public void onCapabilitiesChanged_callsRefreshIfNecessary() { NetworkCapabilities nc = makeNetworkCapabilities(); when(mockConnectivityManager.getNetworkCapabilities(mockNetwork)) .thenReturn(new NetworkCapabilities(nc)); String summary = "Connected, no Internet"; when(mockAccessPoint.getSettingsSummary()).thenReturn(summary); InOrder inOrder = inOrder(mockHeaderController); displayAndResume(); inOrder.verify(mockHeaderController).setSummary(summary); summary = "Connected"; when(mockAccessPoint.getSettingsSummary()).thenReturn(summary); updateNetworkCapabilities(nc); inOrder.verify(mockHeaderController, never()).setSummary(any(CharSequence.class)); nc.addCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED); updateNetworkCapabilities(nc); inOrder.verify(mockHeaderController).setSummary(summary); summary = "Connected, no Internet"; when(mockAccessPoint.getSettingsSummary()).thenReturn(summary); updateNetworkCapabilities(nc); inOrder.verify(mockHeaderController, never()).setSummary(any(CharSequence.class)); nc.removeCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED); updateNetworkCapabilities(nc); inOrder.verify(mockHeaderController).setSummary(summary); summary = "Private DNS server can't be accessed"; when(mockAccessPoint.getSettingsSummary()).thenReturn(summary); nc.setPrivateDnsBroken(true); updateNetworkCapabilities(nc); inOrder.verify(mockHeaderController).setSummary(summary); summary = "Limited connection"; when(mockAccessPoint.getSettingsSummary()).thenReturn(summary); nc.addCapability(NetworkCapabilities.NET_CAPABILITY_PARTIAL_CONNECTIVITY); updateNetworkCapabilities(nc); inOrder.verify(mockHeaderController).setSummary(summary); nc.addCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED); updateNetworkCapabilities(nc); inOrder.verify(mockHeaderController).setSummary(summary); }