@Test public void readData() throws IOException { Mockito.when(filereader.fileExist(Mockito.anyString())).thenReturn(true); String[] arr = new String[] { "1.41383675837E9 -42", "1.413836771449E9 -51", "1.413836784233E9 -53", "1.41383678679E9 -50", "1.413836807271E9 -51", "1.413836809831E9 -51", "1.413836822639E9 -51", "1.413836825194E9 -51", "1.413836837992E9 -51", "1.413836840548E9 -51", "1.413836845669E9 -41", "1.41383685336E9 -51", "1.41383685592E9 -51", "1.413836861023E9 -51", "1.413836868708E9 -51", "1.413836871277E9 -36", }; Mockito.when(filereader.readAllLine(Mockito.anyString())).thenReturn(arr); radioInfoReader.setFileReader(filereader); List<RadioInfo> listRadioInfo = radioInfoReader.readData("/", 0); assertEquals(16, listRadioInfo.size(), 0); assertEquals(-42, listRadioInfo.get(0).getSignalStrength(), 0); assertEquals(-51, listRadioInfo.get(1).getSignalStrength(), 0); assertEquals(-41, listRadioInfo.get(10).getSignalStrength(), 0); assertEquals(-36, listRadioInfo.get(15).getSignalStrength(), 0); assertEquals(1.41383675837E9, listRadioInfo.get(0).getTimeStamp(), 0); assertEquals(1.41383685336E9, listRadioInfo.get(11).getTimeStamp(), 0); assertEquals(1.413836871277E9, listRadioInfo.get(15).getTimeStamp(), 0); Mockito.when(filereader.fileExist(Mockito.anyString())).thenReturn(true); arr = new String[] { "1.412720866732E9 25 -86 -6 300 2147483647" ,"1.412720867835E9 25 -87 -7 300 2147483647" ,"1.412720870315E9 23 -92 -7 300 2147483647" ,"1.412720873837E9 21 -94 -7 300 2147483647" ,"1.412720876836E9 21 -95 -7 300 2147483647" }; Mockito.when(filereader.readAllLine(Mockito.anyString())).thenReturn(arr); radioInfoReader.setFileReader(filereader); listRadioInfo = radioInfoReader.readData("/", 0); assertEquals(5, listRadioInfo.size(), 0); Mockito.when(filereader.fileExist(Mockito.anyString())).thenReturn(true); arr = new String[] { "1.394754474555E9 -51" }; Mockito.when(filereader.readAllLine(Mockito.anyString())).thenReturn(arr); radioInfoReader.setFileReader(filereader); listRadioInfo = radioInfoReader.readData("/", 0); assertEquals(1, listRadioInfo.size(), 0); Mockito.when(filereader.fileExist(Mockito.anyString())).thenReturn(true); arr = new String[] { "1.394754474555E9 0" }; Mockito.when(filereader.readAllLine(Mockito.anyString())).thenReturn(arr); radioInfoReader.setFileReader(filereader); listRadioInfo = radioInfoReader.readData("/", 0); assertEquals(1, listRadioInfo.size(), 0); Mockito.when(filereader.fileExist(Mockito.anyString())).thenReturn(true); arr = new String[] { "" }; Mockito.when(filereader.readAllLine(Mockito.anyString())).thenReturn(arr); radioInfoReader.setFileReader(filereader); listRadioInfo = radioInfoReader.readData("/", 0); assertEquals(0, listRadioInfo.size(), 0); Mockito.when(filereader.fileExist(Mockito.anyString())).thenReturn(true); arr = new String[] { "1.414601817968E9 0" ,"1.414601897874E9 -99" ,"1.414601903563E9 -99" ,"1.414601916514E9 -105" ,"1.414601920485E9 -105" }; Mockito.when(filereader.readAllLine(Mockito.anyString())).thenReturn(arr); radioInfoReader.setFileReader(filereader); listRadioInfo = radioInfoReader.readData("/", 0); assertEquals(6, listRadioInfo.size(), 0); }
@Override public List<RadioInfo> readData(String directory, double startTime) { List<RadioInfo> radioInfos = new ArrayList<RadioInfo>(); String filepath = directory + Util.FILE_SEPARATOR + TraceDataConst.FileName.RADIO_EVENTS_FILE; String[] lines = null; if (!filereader.fileExist(filepath)) { return radioInfos; } try { lines = filereader.readAllLine(filepath); } catch (IOException e1) { LOGGER.error("failed to read Radio info file: "+filepath); } Double lastDbmValue = null; if(lines != null && lines.length > 0){ for (String strLineBuf : lines) { String[] strFields = strLineBuf.split(" "); try { if (strFields.length == 2) { double timestampVal = Util.normalizeTime(Double.parseDouble(strFields[0]),startTime); double dbmValue = Double.parseDouble(strFields[1]); if (lastDbmValue != null && timestampVal > 0.0 && (dbmValue >= 0.0 || lastDbmValue.doubleValue() >= 0.0) && dbmValue != lastDbmValue.doubleValue()) { radioInfos.add(new RadioInfo(timestampVal, lastDbmValue.doubleValue())); } radioInfos.add(new RadioInfo(timestampVal, dbmValue)); lastDbmValue = dbmValue; } else if (strFields.length == 6) { double timestampVal = Util.normalizeTime(Double.parseDouble(strFields[0]),startTime); RadioInfo radioInformation = new RadioInfo(timestampVal, Integer.parseInt(strFields[1]), Integer.parseInt(strFields[2]), Integer.parseInt(strFields[3]), Integer.parseInt(strFields[4]), Integer.parseInt(strFields[5])); if (lastDbmValue != null && timestampVal > 0.0 && (radioInformation.getSignalStrength() >= 0.0 || lastDbmValue.doubleValue() >= 0.0) && radioInformation.getSignalStrength() != lastDbmValue.doubleValue()) { radioInfos.add(new RadioInfo(timestampVal, lastDbmValue.doubleValue())); } radioInfos.add(radioInformation); lastDbmValue = radioInformation.getSignalStrength(); } else { LOGGER.warn("Invalid radio_events entry: " + strLineBuf); } } catch (Exception e) { LOGGER.warn("Unexpected error parsing radio event: " + strLineBuf, e); } } } return radioInfos; }
RadioInfoReaderImpl extends PeripheralBase implements IRadioInfoReader { @Override public List<RadioInfo> readData(String directory, double startTime) { List<RadioInfo> radioInfos = new ArrayList<RadioInfo>(); String filepath = directory + Util.FILE_SEPARATOR + TraceDataConst.FileName.RADIO_EVENTS_FILE; String[] lines = null; if (!filereader.fileExist(filepath)) { return radioInfos; } try { lines = filereader.readAllLine(filepath); } catch (IOException e1) { LOGGER.error("failed to read Radio info file: "+filepath); } Double lastDbmValue = null; if(lines != null && lines.length > 0){ for (String strLineBuf : lines) { String[] strFields = strLineBuf.split(" "); try { if (strFields.length == 2) { double timestampVal = Util.normalizeTime(Double.parseDouble(strFields[0]),startTime); double dbmValue = Double.parseDouble(strFields[1]); if (lastDbmValue != null && timestampVal > 0.0 && (dbmValue >= 0.0 || lastDbmValue.doubleValue() >= 0.0) && dbmValue != lastDbmValue.doubleValue()) { radioInfos.add(new RadioInfo(timestampVal, lastDbmValue.doubleValue())); } radioInfos.add(new RadioInfo(timestampVal, dbmValue)); lastDbmValue = dbmValue; } else if (strFields.length == 6) { double timestampVal = Util.normalizeTime(Double.parseDouble(strFields[0]),startTime); RadioInfo radioInformation = new RadioInfo(timestampVal, Integer.parseInt(strFields[1]), Integer.parseInt(strFields[2]), Integer.parseInt(strFields[3]), Integer.parseInt(strFields[4]), Integer.parseInt(strFields[5])); if (lastDbmValue != null && timestampVal > 0.0 && (radioInformation.getSignalStrength() >= 0.0 || lastDbmValue.doubleValue() >= 0.0) && radioInformation.getSignalStrength() != lastDbmValue.doubleValue()) { radioInfos.add(new RadioInfo(timestampVal, lastDbmValue.doubleValue())); } radioInfos.add(radioInformation); lastDbmValue = radioInformation.getSignalStrength(); } else { LOGGER.warn("Invalid radio_events entry: " + strLineBuf); } } catch (Exception e) { LOGGER.warn("Unexpected error parsing radio event: " + strLineBuf, e); } } } return radioInfos; } }
RadioInfoReaderImpl extends PeripheralBase implements IRadioInfoReader { @Override public List<RadioInfo> readData(String directory, double startTime) { List<RadioInfo> radioInfos = new ArrayList<RadioInfo>(); String filepath = directory + Util.FILE_SEPARATOR + TraceDataConst.FileName.RADIO_EVENTS_FILE; String[] lines = null; if (!filereader.fileExist(filepath)) { return radioInfos; } try { lines = filereader.readAllLine(filepath); } catch (IOException e1) { LOGGER.error("failed to read Radio info file: "+filepath); } Double lastDbmValue = null; if(lines != null && lines.length > 0){ for (String strLineBuf : lines) { String[] strFields = strLineBuf.split(" "); try { if (strFields.length == 2) { double timestampVal = Util.normalizeTime(Double.parseDouble(strFields[0]),startTime); double dbmValue = Double.parseDouble(strFields[1]); if (lastDbmValue != null && timestampVal > 0.0 && (dbmValue >= 0.0 || lastDbmValue.doubleValue() >= 0.0) && dbmValue != lastDbmValue.doubleValue()) { radioInfos.add(new RadioInfo(timestampVal, lastDbmValue.doubleValue())); } radioInfos.add(new RadioInfo(timestampVal, dbmValue)); lastDbmValue = dbmValue; } else if (strFields.length == 6) { double timestampVal = Util.normalizeTime(Double.parseDouble(strFields[0]),startTime); RadioInfo radioInformation = new RadioInfo(timestampVal, Integer.parseInt(strFields[1]), Integer.parseInt(strFields[2]), Integer.parseInt(strFields[3]), Integer.parseInt(strFields[4]), Integer.parseInt(strFields[5])); if (lastDbmValue != null && timestampVal > 0.0 && (radioInformation.getSignalStrength() >= 0.0 || lastDbmValue.doubleValue() >= 0.0) && radioInformation.getSignalStrength() != lastDbmValue.doubleValue()) { radioInfos.add(new RadioInfo(timestampVal, lastDbmValue.doubleValue())); } radioInfos.add(radioInformation); lastDbmValue = radioInformation.getSignalStrength(); } else { LOGGER.warn("Invalid radio_events entry: " + strLineBuf); } } catch (Exception e) { LOGGER.warn("Unexpected error parsing radio event: " + strLineBuf, e); } } } return radioInfos; }  }
RadioInfoReaderImpl extends PeripheralBase implements IRadioInfoReader { @Override public List<RadioInfo> readData(String directory, double startTime) { List<RadioInfo> radioInfos = new ArrayList<RadioInfo>(); String filepath = directory + Util.FILE_SEPARATOR + TraceDataConst.FileName.RADIO_EVENTS_FILE; String[] lines = null; if (!filereader.fileExist(filepath)) { return radioInfos; } try { lines = filereader.readAllLine(filepath); } catch (IOException e1) { LOGGER.error("failed to read Radio info file: "+filepath); } Double lastDbmValue = null; if(lines != null && lines.length > 0){ for (String strLineBuf : lines) { String[] strFields = strLineBuf.split(" "); try { if (strFields.length == 2) { double timestampVal = Util.normalizeTime(Double.parseDouble(strFields[0]),startTime); double dbmValue = Double.parseDouble(strFields[1]); if (lastDbmValue != null && timestampVal > 0.0 && (dbmValue >= 0.0 || lastDbmValue.doubleValue() >= 0.0) && dbmValue != lastDbmValue.doubleValue()) { radioInfos.add(new RadioInfo(timestampVal, lastDbmValue.doubleValue())); } radioInfos.add(new RadioInfo(timestampVal, dbmValue)); lastDbmValue = dbmValue; } else if (strFields.length == 6) { double timestampVal = Util.normalizeTime(Double.parseDouble(strFields[0]),startTime); RadioInfo radioInformation = new RadioInfo(timestampVal, Integer.parseInt(strFields[1]), Integer.parseInt(strFields[2]), Integer.parseInt(strFields[3]), Integer.parseInt(strFields[4]), Integer.parseInt(strFields[5])); if (lastDbmValue != null && timestampVal > 0.0 && (radioInformation.getSignalStrength() >= 0.0 || lastDbmValue.doubleValue() >= 0.0) && radioInformation.getSignalStrength() != lastDbmValue.doubleValue()) { radioInfos.add(new RadioInfo(timestampVal, lastDbmValue.doubleValue())); } radioInfos.add(radioInformation); lastDbmValue = radioInformation.getSignalStrength(); } else { LOGGER.warn("Invalid radio_events entry: " + strLineBuf); } } catch (Exception e) { LOGGER.warn("Unexpected error parsing radio event: " + strLineBuf, e); } } } return radioInfos; }  @Override List<RadioInfo> readData(String directory, double startTime); }
RadioInfoReaderImpl extends PeripheralBase implements IRadioInfoReader { @Override public List<RadioInfo> readData(String directory, double startTime) { List<RadioInfo> radioInfos = new ArrayList<RadioInfo>(); String filepath = directory + Util.FILE_SEPARATOR + TraceDataConst.FileName.RADIO_EVENTS_FILE; String[] lines = null; if (!filereader.fileExist(filepath)) { return radioInfos; } try { lines = filereader.readAllLine(filepath); } catch (IOException e1) { LOGGER.error("failed to read Radio info file: "+filepath); } Double lastDbmValue = null; if(lines != null && lines.length > 0){ for (String strLineBuf : lines) { String[] strFields = strLineBuf.split(" "); try { if (strFields.length == 2) { double timestampVal = Util.normalizeTime(Double.parseDouble(strFields[0]),startTime); double dbmValue = Double.parseDouble(strFields[1]); if (lastDbmValue != null && timestampVal > 0.0 && (dbmValue >= 0.0 || lastDbmValue.doubleValue() >= 0.0) && dbmValue != lastDbmValue.doubleValue()) { radioInfos.add(new RadioInfo(timestampVal, lastDbmValue.doubleValue())); } radioInfos.add(new RadioInfo(timestampVal, dbmValue)); lastDbmValue = dbmValue; } else if (strFields.length == 6) { double timestampVal = Util.normalizeTime(Double.parseDouble(strFields[0]),startTime); RadioInfo radioInformation = new RadioInfo(timestampVal, Integer.parseInt(strFields[1]), Integer.parseInt(strFields[2]), Integer.parseInt(strFields[3]), Integer.parseInt(strFields[4]), Integer.parseInt(strFields[5])); if (lastDbmValue != null && timestampVal > 0.0 && (radioInformation.getSignalStrength() >= 0.0 || lastDbmValue.doubleValue() >= 0.0) && radioInformation.getSignalStrength() != lastDbmValue.doubleValue()) { radioInfos.add(new RadioInfo(timestampVal, lastDbmValue.doubleValue())); } radioInfos.add(radioInformation); lastDbmValue = radioInformation.getSignalStrength(); } else { LOGGER.warn("Invalid radio_events entry: " + strLineBuf); } } catch (Exception e) { LOGGER.warn("Unexpected error parsing radio event: " + strLineBuf, e); } } } return radioInfos; }  @Override List<RadioInfo> readData(String directory, double startTime);  }