NetworkUtils { public static boolean isMeteredConnection(Context context) { ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); assert manager != null; return manager.isActiveNetworkMetered(); }  static boolean isConnected(Context context); static boolean isMeteredConnection(Context context); static void maybeLaunchBrowser(Context context, String url); static void maybeLaunchIntent(Context context, Intent intent);  }
@Test public void testMeteredConnection() { Context context = mock(Context.class); ConnectivityManager manager = mock(ConnectivityManager.class); when(context.getSystemService(Context.CONNECTIVITY_SERVICE)).thenReturn(manager); when(manager.isActiveNetworkMetered()).thenReturn(true); assertTrue(NetworkUtils.isMeteredConnection(context)); when(manager.isActiveNetworkMetered()).thenReturn(false); assertFalse(NetworkUtils.isMeteredConnection(context)); }