Connectivity { public Type getType() { NetworkInfo network = mConnectivityManager.getActiveNetworkInfo(); if (network == null) return NONE; if (network.getType() == ConnectivityManager.TYPE_WIFI) { return WIFI; } else return MOBILE; } Connectivity(Context context); boolean isConnected(); Type getType();  }
@Test public void testGetType_none() { Connectivity connectivity = new Connectivity(mContext); assertEquals(Connectivity.Type.NONE, connectivity.getType()); verify(mConnectivityManager).getActiveNetworkInfo(); }
@Test public void testGetType_wifi() { Connectivity connectivity = new Connectivity(mContext); when(mConnectivityManager.getActiveNetworkInfo()).thenReturn(mNetworkInfo); when(mNetworkInfo.getType()).thenReturn(ConnectivityManager.TYPE_WIFI); assertEquals(Connectivity.Type.WIFI, connectivity.getType()); verify(mConnectivityManager).getActiveNetworkInfo(); }
@Test public void testGetType_else() { Connectivity connectivity = new Connectivity(mContext); when(mConnectivityManager.getActiveNetworkInfo()).thenReturn(mNetworkInfo); when(mNetworkInfo.getType()).thenReturn(ConnectivityManager.TYPE_WIMAX); assertEquals(Connectivity.Type.MOBILE, connectivity.getType()); verify(mConnectivityManager).getActiveNetworkInfo(); }