### Question:
CpuUsage { @VisibleForTesting static CpuSnapshot parse(String cpuRate, String pidCpuRate) { String[] cpuInfoArray = cpuRate.split("\\s+"); if (cpuInfoArray.length < 9) { throw new IllegalStateException("cpu info array size must great than 9"); } long user = Long.parseLong(cpuInfoArray[2]); long nice = Long.parseLong(cpuInfoArray[3]); long system = Long.parseLong(cpuInfoArray[4]); long idle = Long.parseLong(cpuInfoArray[5]); long ioWait = Long.parseLong(cpuInfoArray[6]); long total = user + nice + system + idle + ioWait + Long.parseLong(cpuInfoArray[7]) + Long.parseLong(cpuInfoArray[8]); String[] pidCpuInfoList = pidCpuRate.split(" "); if (pidCpuInfoList.length < 17) { throw new IllegalStateException("pid cpu info array size must great than 17"); } long appCpuTime = Long.parseLong(pidCpuInfoList[13]) + Long.parseLong(pidCpuInfoList[14]) + Long.parseLong(pidCpuInfoList[15]) + Long.parseLong(pidCpuInfoList[16]); return new CpuSnapshot(user, system, idle, ioWait, total, appCpuTime); }  static CpuInfo getCpuInfo();  }### Answer:
@Test public void parse() { String deviceCpu0 = "800%cpu 0%user 0%nice 0%sys 800%idle 0%iow 0%irq 0%sirq 0%host"; String appCpu0 = "[7m PID USER PR NI VIRT RES SHR S[%CPU] %MEM TIME+ ARGS \u001B[0m"; try { CpuSnapshot cpuSnapshot = CpuUsage.parse(deviceCpu0, appCpu0); Assert.fail(); } catch (NumberFormatException ignore) { } String deviceCpu1 = "cpu 4473 1068 4565 21155 559 0 29 0 0 0"; String appCpu1 = "3238 (d.godeye.sample) S 1189 1189 0 0 -1 1077961024 25948 0 3 0 94 111 0 0 20 0 35 0 4901 1332465664 16104 4294967295 3078545408 3078556388 3213513904 3213510820 3077933717 0 4612 0 1073779964 4294967295 0 0 17 3 0 0 1 0 0 3078561120 3078561772 3088125952 3213515788 3213515864 3213515864 3213516772 0"; CpuSnapshot cpuSnapshot = CpuUsage.parse(deviceCpu1, appCpu1); Assert.assertEquals(1068, cpuSnapshot.user); Assert.assertEquals(21155, cpuSnapshot.system); Assert.assertEquals(559, cpuSnapshot.idle); Assert.assertEquals(0, cpuSnapshot.ioWait); Assert.assertEquals(27376, cpuSnapshot.total); Assert.assertEquals(205, cpuSnapshot.app); }