@Test public void readData() throws IOException{ Mockito.when(filereader.fileExist(Mockito.anyString())).thenReturn(true); Mockito.when(filereader.readAllLine(Mockito.anyString())).thenReturn( new String[] { "1.389038277403E9 33 37 false", "1.389038308374E9 32 37 false", "1.389038365419E9 32 37 false" }); List<BatteryInfo> batteryInfos = batteryreader.readData("/", 0); assertTrue(batteryInfos.size() == 2); }
@Override public List<BatteryInfo> readData(String directory, double startTime) { List<BatteryInfo> batteryInfos = new ArrayList<BatteryInfo>(); int previousLevel = 0; int previousTemp = 0; boolean previousState = false; String filepath = directory + Util.FILE_SEPARATOR + TraceDataConst.FileName.BATTERY_FILE; if (!filereader.fileExist(filepath)) { return batteryInfos; } String[] lines = null; try { lines = filereader.readAllLine(filepath); } catch (IOException e1) { LOGGER.error("failed to open file for battery info: " + filepath); } if (lines != null) { for (String strLineBuf : lines) { String strFields[] = strLineBuf.split(" "); if (strFields.length == 4) { try { double bTimeStamp = Util.normalizeTime(Double.parseDouble(strFields[0]), startTime); int bLevel = Integer.parseInt(strFields[1]); int bTemp = Integer.parseInt(strFields[2]); boolean bState = Boolean.valueOf(strFields[3]); if ((bLevel != previousLevel) || (bTemp != previousTemp) || (bState != previousState)) { batteryInfos.add(new BatteryInfo(bTimeStamp, bState, bLevel, bTemp)); } previousLevel = Integer.parseInt(strFields[1]); previousTemp = Integer.parseInt(strFields[2]); previousState = Boolean.valueOf(strFields[3]); } catch (Exception e) { LOGGER.warn("Unexpected error parsing battery event: " + strLineBuf, e); } } else { LOGGER.warn("Invalid battery_events entry: " + strLineBuf); } } } return batteryInfos; }
BatteryInfoReaderImpl extends PeripheralBase implements IBatteryInfoReader { @Override public List<BatteryInfo> readData(String directory, double startTime) { List<BatteryInfo> batteryInfos = new ArrayList<BatteryInfo>(); int previousLevel = 0; int previousTemp = 0; boolean previousState = false; String filepath = directory + Util.FILE_SEPARATOR + TraceDataConst.FileName.BATTERY_FILE; if (!filereader.fileExist(filepath)) { return batteryInfos; } String[] lines = null; try { lines = filereader.readAllLine(filepath); } catch (IOException e1) { LOGGER.error("failed to open file for battery info: " + filepath); } if (lines != null) { for (String strLineBuf : lines) { String strFields[] = strLineBuf.split(" "); if (strFields.length == 4) { try { double bTimeStamp = Util.normalizeTime(Double.parseDouble(strFields[0]), startTime); int bLevel = Integer.parseInt(strFields[1]); int bTemp = Integer.parseInt(strFields[2]); boolean bState = Boolean.valueOf(strFields[3]); if ((bLevel != previousLevel) || (bTemp != previousTemp) || (bState != previousState)) { batteryInfos.add(new BatteryInfo(bTimeStamp, bState, bLevel, bTemp)); } previousLevel = Integer.parseInt(strFields[1]); previousTemp = Integer.parseInt(strFields[2]); previousState = Boolean.valueOf(strFields[3]); } catch (Exception e) { LOGGER.warn("Unexpected error parsing battery event: " + strLineBuf, e); } } else { LOGGER.warn("Invalid battery_events entry: " + strLineBuf); } } } return batteryInfos; } }
BatteryInfoReaderImpl extends PeripheralBase implements IBatteryInfoReader { @Override public List<BatteryInfo> readData(String directory, double startTime) { List<BatteryInfo> batteryInfos = new ArrayList<BatteryInfo>(); int previousLevel = 0; int previousTemp = 0; boolean previousState = false; String filepath = directory + Util.FILE_SEPARATOR + TraceDataConst.FileName.BATTERY_FILE; if (!filereader.fileExist(filepath)) { return batteryInfos; } String[] lines = null; try { lines = filereader.readAllLine(filepath); } catch (IOException e1) { LOGGER.error("failed to open file for battery info: " + filepath); } if (lines != null) { for (String strLineBuf : lines) { String strFields[] = strLineBuf.split(" "); if (strFields.length == 4) { try { double bTimeStamp = Util.normalizeTime(Double.parseDouble(strFields[0]), startTime); int bLevel = Integer.parseInt(strFields[1]); int bTemp = Integer.parseInt(strFields[2]); boolean bState = Boolean.valueOf(strFields[3]); if ((bLevel != previousLevel) || (bTemp != previousTemp) || (bState != previousState)) { batteryInfos.add(new BatteryInfo(bTimeStamp, bState, bLevel, bTemp)); } previousLevel = Integer.parseInt(strFields[1]); previousTemp = Integer.parseInt(strFields[2]); previousState = Boolean.valueOf(strFields[3]); } catch (Exception e) { LOGGER.warn("Unexpected error parsing battery event: " + strLineBuf, e); } } else { LOGGER.warn("Invalid battery_events entry: " + strLineBuf); } } } return batteryInfos; }  }
BatteryInfoReaderImpl extends PeripheralBase implements IBatteryInfoReader { @Override public List<BatteryInfo> readData(String directory, double startTime) { List<BatteryInfo> batteryInfos = new ArrayList<BatteryInfo>(); int previousLevel = 0; int previousTemp = 0; boolean previousState = false; String filepath = directory + Util.FILE_SEPARATOR + TraceDataConst.FileName.BATTERY_FILE; if (!filereader.fileExist(filepath)) { return batteryInfos; } String[] lines = null; try { lines = filereader.readAllLine(filepath); } catch (IOException e1) { LOGGER.error("failed to open file for battery info: " + filepath); } if (lines != null) { for (String strLineBuf : lines) { String strFields[] = strLineBuf.split(" "); if (strFields.length == 4) { try { double bTimeStamp = Util.normalizeTime(Double.parseDouble(strFields[0]), startTime); int bLevel = Integer.parseInt(strFields[1]); int bTemp = Integer.parseInt(strFields[2]); boolean bState = Boolean.valueOf(strFields[3]); if ((bLevel != previousLevel) || (bTemp != previousTemp) || (bState != previousState)) { batteryInfos.add(new BatteryInfo(bTimeStamp, bState, bLevel, bTemp)); } previousLevel = Integer.parseInt(strFields[1]); previousTemp = Integer.parseInt(strFields[2]); previousState = Boolean.valueOf(strFields[3]); } catch (Exception e) { LOGGER.warn("Unexpected error parsing battery event: " + strLineBuf, e); } } else { LOGGER.warn("Invalid battery_events entry: " + strLineBuf); } } } return batteryInfos; }  @Override List<BatteryInfo> readData(String directory, double startTime); }
BatteryInfoReaderImpl extends PeripheralBase implements IBatteryInfoReader { @Override public List<BatteryInfo> readData(String directory, double startTime) { List<BatteryInfo> batteryInfos = new ArrayList<BatteryInfo>(); int previousLevel = 0; int previousTemp = 0; boolean previousState = false; String filepath = directory + Util.FILE_SEPARATOR + TraceDataConst.FileName.BATTERY_FILE; if (!filereader.fileExist(filepath)) { return batteryInfos; } String[] lines = null; try { lines = filereader.readAllLine(filepath); } catch (IOException e1) { LOGGER.error("failed to open file for battery info: " + filepath); } if (lines != null) { for (String strLineBuf : lines) { String strFields[] = strLineBuf.split(" "); if (strFields.length == 4) { try { double bTimeStamp = Util.normalizeTime(Double.parseDouble(strFields[0]), startTime); int bLevel = Integer.parseInt(strFields[1]); int bTemp = Integer.parseInt(strFields[2]); boolean bState = Boolean.valueOf(strFields[3]); if ((bLevel != previousLevel) || (bTemp != previousTemp) || (bState != previousState)) { batteryInfos.add(new BatteryInfo(bTimeStamp, bState, bLevel, bTemp)); } previousLevel = Integer.parseInt(strFields[1]); previousTemp = Integer.parseInt(strFields[2]); previousState = Boolean.valueOf(strFields[3]); } catch (Exception e) { LOGGER.warn("Unexpected error parsing battery event: " + strLineBuf, e); } } else { LOGGER.warn("Invalid battery_events entry: " + strLineBuf); } } } return batteryInfos; }  @Override List<BatteryInfo> readData(String directory, double startTime);  }