### Question:
CpuUsage { @VisibleForTesting static Map<String, Float> parseCpuRateOfDeviceAndTotalByShell(String line) { if (line.matches("^\\d+%\\w+.+\\d+%\\w+")) { String lineLowerCase = line.toLowerCase(Locale.US); String[] cpuList = lineLowerCase.split("\\s+"); Map<String, Float> cpuMap = new HashMap<>(); for (String s : cpuList) { String[] cpuItem = s.split("%"); if (cpuItem.length != 2) { throw new IllegalStateException("parseCpuRateOfDeviceAndTotalByShell but cpuItem.length != 2"); } try { cpuMap.put(cpuItem[1], Float.parseFloat(cpuItem[0])); } catch (Throwable e) { throw new IllegalStateException("parseCpuRateOfDeviceAndTotalByShell but " + e); } } return cpuMap; } return null; }  static CpuInfo getCpuInfo();  }### Answer:
@Test public void parseCpuRateOfDeviceAndTotalByShell() { String line0 = "[s\u001B[999C\u001B[999B\u001B[6n\u001B[u\u001B[H\u001B[J\u001B[?25l\u001B[H\u001B[J\u001B[s\u001B[999C\u001B[999B\u001B[6n\u001B[uTasks: 2 total, 1 running, 1 sleeping, 0 stopped, 0 zombie"; String line1 = "Mem: 7.2G total, 7.0G used, 266M free, 98M buffers"; String line2 = "800%cpu 0%user 0%nice 0%sys 800%idle 0%iow 0%irq 0%sirq 0%host"; String line3 = "[7m PID USER PR NI VIRT RES SHR S[%CPU] %MEM TIME+ ARGS \u001B[0m"; Map<String, Float> tempCpuDevice0 = CpuUsage.parseCpuRateOfDeviceAndTotalByShell(line0); Map<String, Float> tempCpuDevice1 = CpuUsage.parseCpuRateOfDeviceAndTotalByShell(line1); Map<String, Float> tempCpuDevice2 = CpuUsage.parseCpuRateOfDeviceAndTotalByShell(line2); Map<String, Float> tempCpuDevice3 = CpuUsage.parseCpuRateOfDeviceAndTotalByShell(line3); Assert.assertNull(tempCpuDevice0); Assert.assertNull(tempCpuDevice1); Assert.assertNull(tempCpuDevice3); Assert.assertEquals(800, tempCpuDevice2.get("cpu"), 0); Assert.assertEquals(0, tempCpuDevice2.get("sys"), 0); Assert.assertEquals(800, tempCpuDevice2.get("idle"), 0); }