@Test public void readData() throws IOException { Mockito.when(filereader.fileExist(Mockito.anyString())).thenReturn(true); String[] arr = new String[] { "1.358205538539E9 10", "1.358205540396E9 15", "1.35820554882E9 3", "1.358205549444E9 1", "1.358205552859E9 9", "1.358205564577E9 3", "1.358205565208E9 10", "1.358205565834E9 15", "1.358205572238E9 3", "1.358205572969E9 8", "1.358205584581E9 3", "1.358205586095E9 13", "1.358205590906E9 3", "1.358205591561E9 2", "1.358205594481E9 5", "1.358205605874E9 3", "1.358205606144E9 0", "1.358205607302E9 15", "1.358205614199E9 -1", "1.358205623225E9 -1", "1.358205763101E9 15", "1.358205779064E9 3", "1.358205779663E9 33", "1.358205782276E9 fe", "1.358205790737E9 3", "1.358205791067E9 10", "1.358205801382E9 15", }; Mockito.when(filereader.readAllLine(Mockito.anyString())).thenReturn(arr); networkTypeReader.setFileReader(filereader); NetworkTypeObject info = networkTypeReader.readData("/", 0, 0); List<NetworkType> listNetworkType = info.getNetworkTypesList(); assertEquals(11, listNetworkType.size(), 0); List<NetworkBearerTypeInfo> listNetworkBearerTypeInfo = info.getNetworkTypeInfos(); assertEquals(27, listNetworkBearerTypeInfo.size(), 0); assertEquals(1.358205538539E9, listNetworkBearerTypeInfo.get(0).getBeginTimestamp(), 0); assertEquals(1.358205801382E9, listNetworkBearerTypeInfo.get(26).getBeginTimestamp(), 0); assertEquals("HSPAP", listNetworkBearerTypeInfo.get(26).getNetworkType().toString()); Mockito.when(filereader.fileExist(Mockito.anyString())).thenReturn(false); Mockito.when(filereader.readAllLine(Mockito.anyString())).thenReturn(arr); info = networkTypeReader.readData("/", 0, 0); assertTrue(listNetworkType != null); Mockito.when(filereader.fileExist(Mockito.anyString())).thenReturn(true); arr = new String[] { "1.358205538539E9 bd", "1.358205540396E9 15" }; Mockito.when(filereader.readAllLine(Mockito.anyString())).thenReturn(arr); info = networkTypeReader.readData("/", 0, 0); listNetworkType = info.getNetworkTypesList(); assertEquals(2, listNetworkType.size(), 0); }
@Override public NetworkTypeObject readData(String directory, double startTime, double traceDuration) { NetworkTypeObject obj = null; List<NetworkBearerTypeInfo> networkTypeInfos = new ArrayList<NetworkBearerTypeInfo>(); List<NetworkType> networkTypesList = new ArrayList<NetworkType>(); String filepath = directory + Util.FILE_SEPARATOR + TraceDataConst.FileName.NETWORKINFO_FILE; if (!filereader.fileExist(filepath)) { return obj; } String[] lines = null; try { lines = filereader.readAllLine(filepath); } catch (IOException e1) { LOGGER.error("failed to read network info file: " + filepath); } String line; if (lines != null && lines.length > 0) { line = lines[0]; networkTypeInfos.clear(); NetworkType networkType; double beginTime; double endTime; String[] fields = line.split(" "); if (fields.length == 2) { beginTime = Util.normalizeTime(Double.parseDouble(fields[0]), startTime); try { networkType = getNetworkTypeFromCode(Integer.parseInt(fields[1])); } catch (NumberFormatException e) { networkType = NetworkType.none; LOGGER.warn("Invalid network type [" + fields[1] + "]"); } networkTypesList.add(networkType); for (int i = 1; i < lines.length; i++) { line = lines[i]; fields = line.split(" "); if (fields.length == 2) { endTime = Util.normalizeTime(Double.parseDouble(fields[0]), startTime); networkTypeInfos.add(new NetworkBearerTypeInfo(beginTime, endTime, networkType)); try { networkType = getNetworkTypeFromCode(Integer.parseInt(fields[1])); } catch (NumberFormatException e) { networkType = NetworkType.none; LOGGER.warn("Invalid network type [" + fields[1] + "]"); } beginTime = endTime; if (!networkTypesList.contains(networkType)) { networkTypesList.add(networkType); } } } networkTypeInfos.add(new NetworkBearerTypeInfo(beginTime, traceDuration, networkType)); } } obj = new NetworkTypeObject(); obj.setNetworkTypeInfos(networkTypeInfos); obj.setNetworkTypesList(networkTypesList); return obj; }
NetworkTypeReaderImpl extends PeripheralBase implements INetworkTypeReader { @Override public NetworkTypeObject readData(String directory, double startTime, double traceDuration) { NetworkTypeObject obj = null; List<NetworkBearerTypeInfo> networkTypeInfos = new ArrayList<NetworkBearerTypeInfo>(); List<NetworkType> networkTypesList = new ArrayList<NetworkType>(); String filepath = directory + Util.FILE_SEPARATOR + TraceDataConst.FileName.NETWORKINFO_FILE; if (!filereader.fileExist(filepath)) { return obj; } String[] lines = null; try { lines = filereader.readAllLine(filepath); } catch (IOException e1) { LOGGER.error("failed to read network info file: " + filepath); } String line; if (lines != null && lines.length > 0) { line = lines[0]; networkTypeInfos.clear(); NetworkType networkType; double beginTime; double endTime; String[] fields = line.split(" "); if (fields.length == 2) { beginTime = Util.normalizeTime(Double.parseDouble(fields[0]), startTime); try { networkType = getNetworkTypeFromCode(Integer.parseInt(fields[1])); } catch (NumberFormatException e) { networkType = NetworkType.none; LOGGER.warn("Invalid network type [" + fields[1] + "]"); } networkTypesList.add(networkType); for (int i = 1; i < lines.length; i++) { line = lines[i]; fields = line.split(" "); if (fields.length == 2) { endTime = Util.normalizeTime(Double.parseDouble(fields[0]), startTime); networkTypeInfos.add(new NetworkBearerTypeInfo(beginTime, endTime, networkType)); try { networkType = getNetworkTypeFromCode(Integer.parseInt(fields[1])); } catch (NumberFormatException e) { networkType = NetworkType.none; LOGGER.warn("Invalid network type [" + fields[1] + "]"); } beginTime = endTime; if (!networkTypesList.contains(networkType)) { networkTypesList.add(networkType); } } } networkTypeInfos.add(new NetworkBearerTypeInfo(beginTime, traceDuration, networkType)); } } obj = new NetworkTypeObject(); obj.setNetworkTypeInfos(networkTypeInfos); obj.setNetworkTypesList(networkTypesList); return obj; } }
NetworkTypeReaderImpl extends PeripheralBase implements INetworkTypeReader { @Override public NetworkTypeObject readData(String directory, double startTime, double traceDuration) { NetworkTypeObject obj = null; List<NetworkBearerTypeInfo> networkTypeInfos = new ArrayList<NetworkBearerTypeInfo>(); List<NetworkType> networkTypesList = new ArrayList<NetworkType>(); String filepath = directory + Util.FILE_SEPARATOR + TraceDataConst.FileName.NETWORKINFO_FILE; if (!filereader.fileExist(filepath)) { return obj; } String[] lines = null; try { lines = filereader.readAllLine(filepath); } catch (IOException e1) { LOGGER.error("failed to read network info file: " + filepath); } String line; if (lines != null && lines.length > 0) { line = lines[0]; networkTypeInfos.clear(); NetworkType networkType; double beginTime; double endTime; String[] fields = line.split(" "); if (fields.length == 2) { beginTime = Util.normalizeTime(Double.parseDouble(fields[0]), startTime); try { networkType = getNetworkTypeFromCode(Integer.parseInt(fields[1])); } catch (NumberFormatException e) { networkType = NetworkType.none; LOGGER.warn("Invalid network type [" + fields[1] + "]"); } networkTypesList.add(networkType); for (int i = 1; i < lines.length; i++) { line = lines[i]; fields = line.split(" "); if (fields.length == 2) { endTime = Util.normalizeTime(Double.parseDouble(fields[0]), startTime); networkTypeInfos.add(new NetworkBearerTypeInfo(beginTime, endTime, networkType)); try { networkType = getNetworkTypeFromCode(Integer.parseInt(fields[1])); } catch (NumberFormatException e) { networkType = NetworkType.none; LOGGER.warn("Invalid network type [" + fields[1] + "]"); } beginTime = endTime; if (!networkTypesList.contains(networkType)) { networkTypesList.add(networkType); } } } networkTypeInfos.add(new NetworkBearerTypeInfo(beginTime, traceDuration, networkType)); } } obj = new NetworkTypeObject(); obj.setNetworkTypeInfos(networkTypeInfos); obj.setNetworkTypesList(networkTypesList); return obj; }  }
NetworkTypeReaderImpl extends PeripheralBase implements INetworkTypeReader { @Override public NetworkTypeObject readData(String directory, double startTime, double traceDuration) { NetworkTypeObject obj = null; List<NetworkBearerTypeInfo> networkTypeInfos = new ArrayList<NetworkBearerTypeInfo>(); List<NetworkType> networkTypesList = new ArrayList<NetworkType>(); String filepath = directory + Util.FILE_SEPARATOR + TraceDataConst.FileName.NETWORKINFO_FILE; if (!filereader.fileExist(filepath)) { return obj; } String[] lines = null; try { lines = filereader.readAllLine(filepath); } catch (IOException e1) { LOGGER.error("failed to read network info file: " + filepath); } String line; if (lines != null && lines.length > 0) { line = lines[0]; networkTypeInfos.clear(); NetworkType networkType; double beginTime; double endTime; String[] fields = line.split(" "); if (fields.length == 2) { beginTime = Util.normalizeTime(Double.parseDouble(fields[0]), startTime); try { networkType = getNetworkTypeFromCode(Integer.parseInt(fields[1])); } catch (NumberFormatException e) { networkType = NetworkType.none; LOGGER.warn("Invalid network type [" + fields[1] + "]"); } networkTypesList.add(networkType); for (int i = 1; i < lines.length; i++) { line = lines[i]; fields = line.split(" "); if (fields.length == 2) { endTime = Util.normalizeTime(Double.parseDouble(fields[0]), startTime); networkTypeInfos.add(new NetworkBearerTypeInfo(beginTime, endTime, networkType)); try { networkType = getNetworkTypeFromCode(Integer.parseInt(fields[1])); } catch (NumberFormatException e) { networkType = NetworkType.none; LOGGER.warn("Invalid network type [" + fields[1] + "]"); } beginTime = endTime; if (!networkTypesList.contains(networkType)) { networkTypesList.add(networkType); } } } networkTypeInfos.add(new NetworkBearerTypeInfo(beginTime, traceDuration, networkType)); } } obj = new NetworkTypeObject(); obj.setNetworkTypeInfos(networkTypeInfos); obj.setNetworkTypesList(networkTypesList); return obj; }  @Override NetworkTypeObject readData(String directory, double startTime, double traceDuration); }
NetworkTypeReaderImpl extends PeripheralBase implements INetworkTypeReader { @Override public NetworkTypeObject readData(String directory, double startTime, double traceDuration) { NetworkTypeObject obj = null; List<NetworkBearerTypeInfo> networkTypeInfos = new ArrayList<NetworkBearerTypeInfo>(); List<NetworkType> networkTypesList = new ArrayList<NetworkType>(); String filepath = directory + Util.FILE_SEPARATOR + TraceDataConst.FileName.NETWORKINFO_FILE; if (!filereader.fileExist(filepath)) { return obj; } String[] lines = null; try { lines = filereader.readAllLine(filepath); } catch (IOException e1) { LOGGER.error("failed to read network info file: " + filepath); } String line; if (lines != null && lines.length > 0) { line = lines[0]; networkTypeInfos.clear(); NetworkType networkType; double beginTime; double endTime; String[] fields = line.split(" "); if (fields.length == 2) { beginTime = Util.normalizeTime(Double.parseDouble(fields[0]), startTime); try { networkType = getNetworkTypeFromCode(Integer.parseInt(fields[1])); } catch (NumberFormatException e) { networkType = NetworkType.none; LOGGER.warn("Invalid network type [" + fields[1] + "]"); } networkTypesList.add(networkType); for (int i = 1; i < lines.length; i++) { line = lines[i]; fields = line.split(" "); if (fields.length == 2) { endTime = Util.normalizeTime(Double.parseDouble(fields[0]), startTime); networkTypeInfos.add(new NetworkBearerTypeInfo(beginTime, endTime, networkType)); try { networkType = getNetworkTypeFromCode(Integer.parseInt(fields[1])); } catch (NumberFormatException e) { networkType = NetworkType.none; LOGGER.warn("Invalid network type [" + fields[1] + "]"); } beginTime = endTime; if (!networkTypesList.contains(networkType)) { networkTypesList.add(networkType); } } } networkTypeInfos.add(new NetworkBearerTypeInfo(beginTime, traceDuration, networkType)); } } obj = new NetworkTypeObject(); obj.setNetworkTypeInfos(networkTypeInfos); obj.setNetworkTypesList(networkTypesList); return obj; }  @Override NetworkTypeObject readData(String directory, double startTime, double traceDuration);  }