@Test public void readData_IOException() throws IOException { reader = (CpuActivityReaderImpl)context.getBean(ICpuActivityReader.class); IFileManager filereader = Mockito.mock(IFileManager.class); Mockito.when(filereader.fileExist(Mockito.anyString())).thenReturn(true); Mockito.when(filereader.readAllLine(Mockito.anyString())).thenThrow(new IOException("test exception")); reader.setFileReader(filereader); CpuActivityList info = reader.readData("/", 0.0); assertTrue(info.getCpuActivities().size() == 0); }
@Override public CpuActivityList readData(String directory, double startTime) { String cpuFileName = TraceDataConst.FileName.CPU_FILE; CpuActivityList cpuActivityList = new CpuActivityList(); LOGGER.debug("Reading CPU file..."); String filepath = directory + Util.FILE_SEPARATOR + cpuFileName; if (!filereader.fileExist(filepath)) { LOGGER.warn("cpu file not found: " + cpuFileName); return cpuActivityList; } String[] lines; try { lines = filereader.readAllLine(filepath); } catch (IOException e) { LOGGER.error("Failed to read CPU activity file: " + filepath); return cpuActivityList; } for (String line : lines) { if (!line.trim().isEmpty()) { CpuActivity cpuact = cpuActivityParser.parseCpuLine(line, startTime); cpuActivityList.add(cpuact); } } return cpuActivityList; }
CpuActivityReaderImpl extends PeripheralBase implements ICpuActivityReader { @Override public CpuActivityList readData(String directory, double startTime) { String cpuFileName = TraceDataConst.FileName.CPU_FILE; CpuActivityList cpuActivityList = new CpuActivityList(); LOGGER.debug("Reading CPU file..."); String filepath = directory + Util.FILE_SEPARATOR + cpuFileName; if (!filereader.fileExist(filepath)) { LOGGER.warn("cpu file not found: " + cpuFileName); return cpuActivityList; } String[] lines; try { lines = filereader.readAllLine(filepath); } catch (IOException e) { LOGGER.error("Failed to read CPU activity file: " + filepath); return cpuActivityList; } for (String line : lines) { if (!line.trim().isEmpty()) { CpuActivity cpuact = cpuActivityParser.parseCpuLine(line, startTime); cpuActivityList.add(cpuact); } } return cpuActivityList; } }
CpuActivityReaderImpl extends PeripheralBase implements ICpuActivityReader { @Override public CpuActivityList readData(String directory, double startTime) { String cpuFileName = TraceDataConst.FileName.CPU_FILE; CpuActivityList cpuActivityList = new CpuActivityList(); LOGGER.debug("Reading CPU file..."); String filepath = directory + Util.FILE_SEPARATOR + cpuFileName; if (!filereader.fileExist(filepath)) { LOGGER.warn("cpu file not found: " + cpuFileName); return cpuActivityList; } String[] lines; try { lines = filereader.readAllLine(filepath); } catch (IOException e) { LOGGER.error("Failed to read CPU activity file: " + filepath); return cpuActivityList; } for (String line : lines) { if (!line.trim().isEmpty()) { CpuActivity cpuact = cpuActivityParser.parseCpuLine(line, startTime); cpuActivityList.add(cpuact); } } return cpuActivityList; }  }
CpuActivityReaderImpl extends PeripheralBase implements ICpuActivityReader { @Override public CpuActivityList readData(String directory, double startTime) { String cpuFileName = TraceDataConst.FileName.CPU_FILE; CpuActivityList cpuActivityList = new CpuActivityList(); LOGGER.debug("Reading CPU file..."); String filepath = directory + Util.FILE_SEPARATOR + cpuFileName; if (!filereader.fileExist(filepath)) { LOGGER.warn("cpu file not found: " + cpuFileName); return cpuActivityList; } String[] lines; try { lines = filereader.readAllLine(filepath); } catch (IOException e) { LOGGER.error("Failed to read CPU activity file: " + filepath); return cpuActivityList; } for (String line : lines) { if (!line.trim().isEmpty()) { CpuActivity cpuact = cpuActivityParser.parseCpuLine(line, startTime); cpuActivityList.add(cpuact); } } return cpuActivityList; }  @Override CpuActivityList readData(String directory, double startTime); }
CpuActivityReaderImpl extends PeripheralBase implements ICpuActivityReader { @Override public CpuActivityList readData(String directory, double startTime) { String cpuFileName = TraceDataConst.FileName.CPU_FILE; CpuActivityList cpuActivityList = new CpuActivityList(); LOGGER.debug("Reading CPU file..."); String filepath = directory + Util.FILE_SEPARATOR + cpuFileName; if (!filereader.fileExist(filepath)) { LOGGER.warn("cpu file not found: " + cpuFileName); return cpuActivityList; } String[] lines; try { lines = filereader.readAllLine(filepath); } catch (IOException e) { LOGGER.error("Failed to read CPU activity file: " + filepath); return cpuActivityList; } for (String line : lines) { if (!line.trim().isEmpty()) { CpuActivity cpuact = cpuActivityParser.parseCpuLine(line, startTime); cpuActivityList.add(cpuact); } } return cpuActivityList; }  @Override CpuActivityList readData(String directory, double startTime);  }