@@ -294,6 +294,22 @@ public void testWithoutUid() throws Exception {
294294 assertValues (after , 1 , TEST_IFACE , 101 , SET_DEFAULT , 0xF00D , 128L , 8L , 0L , 0L , 0L );
295295 }
296296
297+ public void testClone () throws Exception {
298+ final NetworkStats original = new NetworkStats (TEST_START , 5 )
299+ .addValues (TEST_IFACE , 100 , SET_DEFAULT , TAG_NONE , 128L , 8L , 0L , 2L , 20L )
300+ .addValues (TEST_IFACE2 , 100 , SET_DEFAULT , TAG_NONE , 512L , 32L , 0L , 0L , 0L );
301+
302+ // make clone and mutate original
303+ final NetworkStats clone = original .clone ();
304+ original .addValues (TEST_IFACE , 101 , SET_DEFAULT , TAG_NONE , 128L , 8L , 0L , 0L , 0L );
305+
306+ assertEquals (3 , original .size ());
307+ assertEquals (2 , clone .size ());
308+
309+ assertEquals (128L + 512L + 128L , original .getTotalBytes ());
310+ assertEquals (128L + 512L , clone .getTotalBytes ());
311+ }
312+
297313 private static void assertValues (NetworkStats stats , int index , String iface , int uid , int set ,
298314 int tag , long rxBytes , long rxPackets , long txBytes , long txPackets , long operations ) {
299315 final NetworkStats .Entry entry = stats .getValues (index , null );
0 commit comments