### Question:
CpuUsage { @VisibleForTesting static int parseCPUIndex(String line) { if (line.contains("CPU")) { String[] titles = line.split("\\s+"); for (int i = 0; i < titles.length; i++) { if (titles[i].contains("CPU")) { return i; } } } return -1; }  static CpuInfo getCpuInfo();  }### Answer:
@Test public void parseCPUIndex() { 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"; Assert.assertEquals(-1, CpuUsage.parseCPUIndex(line0)); Assert.assertEquals(-1, CpuUsage.parseCPUIndex(line1)); Assert.assertEquals(-1, CpuUsage.parseCPUIndex(line2)); Assert.assertEquals(8, CpuUsage.parseCPUIndex(line3)); }