### Question:
TrafficStatsNetworkBytesCollector extends NetworkBytesCollector { @Override public synchronized boolean getTotalBytes(long[] bytes) { if (!mIsValid) { return false; } updateTotalBytes(); System.arraycopy(mTotalBytes, 0, bytes, 0, bytes.length); return true; } TrafficStatsNetworkBytesCollector(Context context); @Override boolean supportsBgDistinction(); @Override synchronized boolean getTotalBytes(long[] bytes);  }### Answer:
@Test public void testEmpty() throws Exception { TrafficStatsNetworkBytesCollector collector = new TrafficStatsNetworkBytesCollector(RuntimeEnvironment.application); collector.getTotalBytes(mBytes); assertThat(mBytes).isEqualTo(new long[8]); }
@Test public void testInitialValues() throws Exception { ShadowTrafficStats.setUidRxBytes(10000); ShadowTrafficStats.setUidTxBytes(20000); TrafficStatsNetworkBytesCollector collector = new TrafficStatsNetworkBytesCollector(RuntimeEnvironment.application); assertThat(collector.getTotalBytes(mBytes)).isTrue(); assertThat(mBytes).isEqualTo(new long[] {0, 0, 10000, 20000, 0, 0, 0, 0}); }
@Test public void testUnsupportedValues() throws Exception { ShadowTrafficStats.setUidRxBytes(UNSUPPORTED); ShadowTrafficStats.setUidTxBytes(UNSUPPORTED); TrafficStatsNetworkBytesCollector collector = new TrafficStatsNetworkBytesCollector(RuntimeEnvironment.application); assertThat(collector.getTotalBytes(mBytes)).isFalse(); }
@Test public void testBroadcastNetworkChanges() throws Exception { ShadowTrafficStats.setUidRxBytes(10000); ShadowTrafficStats.setUidTxBytes(20000); TrafficStatsNetworkBytesCollector collector = new TrafficStatsNetworkBytesCollector(RuntimeEnvironment.application); assertThat(collector.getTotalBytes(mBytes)).isTrue(); ShadowTrafficStats.setUidRxBytes(11000); ShadowTrafficStats.setUidTxBytes(22000); ConnectivityManager connectivityManager = (ConnectivityManager) RuntimeEnvironment.application.getSystemService(Context.CONNECTIVITY_SERVICE); ShadowConnectivityManager shadowConnectivityManager = Shadows.shadowOf(connectivityManager); NetworkInfo networkInfo = ShadowNetworkInfo.newInstance(null, ConnectivityManager.TYPE_WIFI, 0, true, true); shadowConnectivityManager.setActiveNetworkInfo(networkInfo); collector.mReceiver.onReceive(null, null); ShadowTrafficStats.setUidRxBytes(11100); ShadowTrafficStats.setUidTxBytes(22200); assertThat(collector.getTotalBytes(mBytes)).isTrue(); assertThat(mBytes[RX | MOBILE]).isEqualTo(11000); assertThat(mBytes[TX | MOBILE]).isEqualTo(22000); assertThat(mBytes[RX | WIFI]).isEqualTo(100); assertThat(mBytes[TX | WIFI]).isEqualTo(200); }