@Test public void readData() throws IOException { Mockito.when(filereader.fileExist(Mockito.anyString())).thenReturn(true); String[] arr = new String[] { "com.att.android.arodatacollector", "HTC One X", "HTC", "android", "4.0.4", "3.1.1.7", "-1", "720*1184", ""}; Mockito.when(filereader.readAllLine(Mockito.anyString())).thenReturn(arr); DeviceDetail info = reader.readData("/"); assertEquals( "com.att.android.arodatacollector", info.getCollectorName()); assertEquals( "HTC One X", info.getDeviceModel()); assertEquals( "HTC", info.getDeviceMake()); assertEquals( "android", info.getOsType()); assertEquals( "4.0.4", info.getOsVersion()); assertEquals( "3.1.1.7", info.getCollectorVersion()); assertEquals( "720*1184", info.getScreenSize()); assertTrue( info.getTotalLines()>0); }
@Override public DeviceDetail readData(String directory) { String filepath = directory + Util.FILE_SEPARATOR + TraceDataConst.FileName.DEVICEDETAILS_FILE; DeviceDetail device = new DeviceDetail(); if (!filereader.fileExist(filepath)) { return null; } String[] lines = null; try { lines = filereader.readAllLine(filepath); } catch (IOException e) { LOGGER.error("failed to read device detail file: " + filepath); } if (lines == null || lines.length < 1) { return null; } device.setTotalLines(lines.length); device.setCollectorName(lines[0]); device.setDeviceModel(lines[1]); device.setDeviceMake(lines[2]); device.setOsType(lines[3]); device.setOsVersion(lines[4]); device.setCollectorVersion(lines[5]); if (lines.length > 7) { device.setScreenSize(lines[7]); } if (lines.length > 8) { double screenDensity; try { screenDensity = Double.parseDouble(lines[8]); } catch (NumberFormatException e) { screenDensity = 0; } device.setScreenDensity(screenDensity); } return device; }
DeviceDetailReaderImpl extends PeripheralBase implements IDeviceDetailReader { @Override public DeviceDetail readData(String directory) { String filepath = directory + Util.FILE_SEPARATOR + TraceDataConst.FileName.DEVICEDETAILS_FILE; DeviceDetail device = new DeviceDetail(); if (!filereader.fileExist(filepath)) { return null; } String[] lines = null; try { lines = filereader.readAllLine(filepath); } catch (IOException e) { LOGGER.error("failed to read device detail file: " + filepath); } if (lines == null || lines.length < 1) { return null; } device.setTotalLines(lines.length); device.setCollectorName(lines[0]); device.setDeviceModel(lines[1]); device.setDeviceMake(lines[2]); device.setOsType(lines[3]); device.setOsVersion(lines[4]); device.setCollectorVersion(lines[5]); if (lines.length > 7) { device.setScreenSize(lines[7]); } if (lines.length > 8) { double screenDensity; try { screenDensity = Double.parseDouble(lines[8]); } catch (NumberFormatException e) { screenDensity = 0; } device.setScreenDensity(screenDensity); } return device; } }
DeviceDetailReaderImpl extends PeripheralBase implements IDeviceDetailReader { @Override public DeviceDetail readData(String directory) { String filepath = directory + Util.FILE_SEPARATOR + TraceDataConst.FileName.DEVICEDETAILS_FILE; DeviceDetail device = new DeviceDetail(); if (!filereader.fileExist(filepath)) { return null; } String[] lines = null; try { lines = filereader.readAllLine(filepath); } catch (IOException e) { LOGGER.error("failed to read device detail file: " + filepath); } if (lines == null || lines.length < 1) { return null; } device.setTotalLines(lines.length); device.setCollectorName(lines[0]); device.setDeviceModel(lines[1]); device.setDeviceMake(lines[2]); device.setOsType(lines[3]); device.setOsVersion(lines[4]); device.setCollectorVersion(lines[5]); if (lines.length > 7) { device.setScreenSize(lines[7]); } if (lines.length > 8) { double screenDensity; try { screenDensity = Double.parseDouble(lines[8]); } catch (NumberFormatException e) { screenDensity = 0; } device.setScreenDensity(screenDensity); } return device; }  }
DeviceDetailReaderImpl extends PeripheralBase implements IDeviceDetailReader { @Override public DeviceDetail readData(String directory) { String filepath = directory + Util.FILE_SEPARATOR + TraceDataConst.FileName.DEVICEDETAILS_FILE; DeviceDetail device = new DeviceDetail(); if (!filereader.fileExist(filepath)) { return null; } String[] lines = null; try { lines = filereader.readAllLine(filepath); } catch (IOException e) { LOGGER.error("failed to read device detail file: " + filepath); } if (lines == null || lines.length < 1) { return null; } device.setTotalLines(lines.length); device.setCollectorName(lines[0]); device.setDeviceModel(lines[1]); device.setDeviceMake(lines[2]); device.setOsType(lines[3]); device.setOsVersion(lines[4]); device.setCollectorVersion(lines[5]); if (lines.length > 7) { device.setScreenSize(lines[7]); } if (lines.length > 8) { double screenDensity; try { screenDensity = Double.parseDouble(lines[8]); } catch (NumberFormatException e) { screenDensity = 0; } device.setScreenDensity(screenDensity); } return device; }  @Override DeviceDetail readData(String directory); }
DeviceDetailReaderImpl extends PeripheralBase implements IDeviceDetailReader { @Override public DeviceDetail readData(String directory) { String filepath = directory + Util.FILE_SEPARATOR + TraceDataConst.FileName.DEVICEDETAILS_FILE; DeviceDetail device = new DeviceDetail(); if (!filereader.fileExist(filepath)) { return null; } String[] lines = null; try { lines = filereader.readAllLine(filepath); } catch (IOException e) { LOGGER.error("failed to read device detail file: " + filepath); } if (lines == null || lines.length < 1) { return null; } device.setTotalLines(lines.length); device.setCollectorName(lines[0]); device.setDeviceModel(lines[1]); device.setDeviceMake(lines[2]); device.setOsType(lines[3]); device.setOsVersion(lines[4]); device.setCollectorVersion(lines[5]); if (lines.length > 7) { device.setScreenSize(lines[7]); } if (lines.length > 8) { double screenDensity; try { screenDensity = Double.parseDouble(lines[8]); } catch (NumberFormatException e) { screenDensity = 0; } device.setScreenDensity(screenDensity); } return device; }  @Override DeviceDetail readData(String directory);  }