@Test public void readData() throws IOException{ Mockito.when(filereader.fileExist(Mockito.anyString())).thenReturn(true); String[] arr = new String[]{"\"/system/bin/rild\"1.1","./data/data/com.att.android.arodatacollector/tcpdump 4.1"}; Mockito.when(filereader.readAllLine(Mockito.anyString())).thenReturn(arr); AppInfo info = reader.readData("/"); assertTrue(info.getAppInfos().size() == 2); assertTrue(info.getAppInfos().get(1).contains("tcpdump")); }
@Override public AppInfo readData(String directory) { AppInfo app = new AppInfo(); String filepath = directory + Util.FILE_SEPARATOR + TraceDataConst.FileName.APPNAME_FILE; if (!filereader.fileExist(filepath)) { LOGGER.warn("Application info file does not exists."); return app; } String[] lines = null; try { lines = filereader.readAllLine(filepath); } catch (IOException e) { LOGGER.error("failed to open appname file: "+filepath); } if(lines != null && lines.length > 0){ for (String line : lines) { String strFields[]; String appName; String appVer = "n/a"; if (line.charAt(0) == '"') { strFields = line.split("\""); appName = strFields[1]; if (strFields.length > 2) { appVer = strFields[2]; app.getAppVersionMap().put(appName, appVer); } } else { strFields = line.split(" "); appName = strFields[0]; if (strFields.length > 1) { appVer = strFields[1]; app.getAppVersionMap().put(appName, appVer); } } app.getAppInfos().add(appName); } } return app; }
AppInfoReaderImpl extends PeripheralBase implements IAppInfoReader { @Override public AppInfo readData(String directory) { AppInfo app = new AppInfo(); String filepath = directory + Util.FILE_SEPARATOR + TraceDataConst.FileName.APPNAME_FILE; if (!filereader.fileExist(filepath)) { LOGGER.warn("Application info file does not exists."); return app; } String[] lines = null; try { lines = filereader.readAllLine(filepath); } catch (IOException e) { LOGGER.error("failed to open appname file: "+filepath); } if(lines != null && lines.length > 0){ for (String line : lines) { String strFields[]; String appName; String appVer = "n/a"; if (line.charAt(0) == '"') { strFields = line.split("\""); appName = strFields[1]; if (strFields.length > 2) { appVer = strFields[2]; app.getAppVersionMap().put(appName, appVer); } } else { strFields = line.split(" "); appName = strFields[0]; if (strFields.length > 1) { appVer = strFields[1]; app.getAppVersionMap().put(appName, appVer); } } app.getAppInfos().add(appName); } } return app; } }
AppInfoReaderImpl extends PeripheralBase implements IAppInfoReader { @Override public AppInfo readData(String directory) { AppInfo app = new AppInfo(); String filepath = directory + Util.FILE_SEPARATOR + TraceDataConst.FileName.APPNAME_FILE; if (!filereader.fileExist(filepath)) { LOGGER.warn("Application info file does not exists."); return app; } String[] lines = null; try { lines = filereader.readAllLine(filepath); } catch (IOException e) { LOGGER.error("failed to open appname file: "+filepath); } if(lines != null && lines.length > 0){ for (String line : lines) { String strFields[]; String appName; String appVer = "n/a"; if (line.charAt(0) == '"') { strFields = line.split("\""); appName = strFields[1]; if (strFields.length > 2) { appVer = strFields[2]; app.getAppVersionMap().put(appName, appVer); } } else { strFields = line.split(" "); appName = strFields[0]; if (strFields.length > 1) { appVer = strFields[1]; app.getAppVersionMap().put(appName, appVer); } } app.getAppInfos().add(appName); } } return app; }  }
AppInfoReaderImpl extends PeripheralBase implements IAppInfoReader { @Override public AppInfo readData(String directory) { AppInfo app = new AppInfo(); String filepath = directory + Util.FILE_SEPARATOR + TraceDataConst.FileName.APPNAME_FILE; if (!filereader.fileExist(filepath)) { LOGGER.warn("Application info file does not exists."); return app; } String[] lines = null; try { lines = filereader.readAllLine(filepath); } catch (IOException e) { LOGGER.error("failed to open appname file: "+filepath); } if(lines != null && lines.length > 0){ for (String line : lines) { String strFields[]; String appName; String appVer = "n/a"; if (line.charAt(0) == '"') { strFields = line.split("\""); appName = strFields[1]; if (strFields.length > 2) { appVer = strFields[2]; app.getAppVersionMap().put(appName, appVer); } } else { strFields = line.split(" "); appName = strFields[0]; if (strFields.length > 1) { appVer = strFields[1]; app.getAppVersionMap().put(appName, appVer); } } app.getAppInfos().add(appName); } } return app; }  @Override AppInfo readData(String directory); }
AppInfoReaderImpl extends PeripheralBase implements IAppInfoReader { @Override public AppInfo readData(String directory) { AppInfo app = new AppInfo(); String filepath = directory + Util.FILE_SEPARATOR + TraceDataConst.FileName.APPNAME_FILE; if (!filereader.fileExist(filepath)) { LOGGER.warn("Application info file does not exists."); return app; } String[] lines = null; try { lines = filereader.readAllLine(filepath); } catch (IOException e) { LOGGER.error("failed to open appname file: "+filepath); } if(lines != null && lines.length > 0){ for (String line : lines) { String strFields[]; String appName; String appVer = "n/a"; if (line.charAt(0) == '"') { strFields = line.split("\""); appName = strFields[1]; if (strFields.length > 2) { appVer = strFields[2]; app.getAppVersionMap().put(appName, appVer); } } else { strFields = line.split(" "); appName = strFields[0]; if (strFields.length > 1) { appVer = strFields[1]; app.getAppVersionMap().put(appName, appVer); } } app.getAppInfos().add(appName); } } return app; }  @Override AppInfo readData(String directory);  }