@Test public void readData() throws IOException { Mockito.when(filereader.fileExist(Mockito.anyString())).thenReturn(true); String[] arr = new String[] { "1.411421173004E9 portrait", "1.411421193602E9 landscape", "1.411421282459E9 portrait", "1.411421287928E9 landscape" }; Mockito.when(filereader.readAllLine(Mockito.anyString())).thenReturn(arr); screenRotationReader.setFileReader(filereader); List<UserEvent> listScreenRotation = screenRotationReader.readData("/", 0); assertEquals(4, listScreenRotation.size(), 0); assertEquals("SCREEN_PORTRAIT", listScreenRotation.get(0).getEventType().name()); assertEquals("SCREEN_LANDSCAPE", listScreenRotation.get(1).getEventType().name()); assertEquals("SCREEN_PORTRAIT", listScreenRotation.get(2).getEventType().name()); assertEquals("SCREEN_LANDSCAPE", listScreenRotation.get(3).getEventType().name()); assertEquals(1.411421173004E9, listScreenRotation.get(0).getPressTime(), 0); assertEquals(1.411421287928E9, listScreenRotation.get(3).getPressTime(), 0); }
@Override public List<UserEvent> readData(String directory, double startTime) { List<UserEvent> userEvents = new ArrayList<UserEvent>(); String filepath = directory + Util.FILE_SEPARATOR + TraceDataConst.FileName.SCREEN_ROTATIONS_FILE; if(!filereader.fileExist(filepath)){ return userEvents; } String[] lines = null; try { lines = filereader.readAllLine(filepath); } catch (IOException e) { LOGGER.error("failed to read screen rotation file: "+filepath); } if(lines != null){ for(String line: lines) { String[] strFields = line.split(" "); double dTimeStamp = Util.normalizeTime(Double.parseDouble(strFields[0]), startTime); if (strFields[1].contains(TraceDataConst.UserEvent.KEY_LANDSCAPE)) { eventType = UserEventType.SCREEN_LANDSCAPE; } else if (strFields[1].contains(TraceDataConst.UserEvent.KEY_PORTRAIT)) { eventType = UserEventType.SCREEN_PORTRAIT; } userEvents.add(new UserEvent(eventType, dTimeStamp, dTimeStamp + 0.5)); } Collections.sort(userEvents, new UserEventSorting()); } return userEvents; }
ScreenRotationReaderImpl extends PeripheralBase implements IScreenRotationReader { @Override public List<UserEvent> readData(String directory, double startTime) { List<UserEvent> userEvents = new ArrayList<UserEvent>(); String filepath = directory + Util.FILE_SEPARATOR + TraceDataConst.FileName.SCREEN_ROTATIONS_FILE; if(!filereader.fileExist(filepath)){ return userEvents; } String[] lines = null; try { lines = filereader.readAllLine(filepath); } catch (IOException e) { LOGGER.error("failed to read screen rotation file: "+filepath); } if(lines != null){ for(String line: lines) { String[] strFields = line.split(" "); double dTimeStamp = Util.normalizeTime(Double.parseDouble(strFields[0]), startTime); if (strFields[1].contains(TraceDataConst.UserEvent.KEY_LANDSCAPE)) { eventType = UserEventType.SCREEN_LANDSCAPE; } else if (strFields[1].contains(TraceDataConst.UserEvent.KEY_PORTRAIT)) { eventType = UserEventType.SCREEN_PORTRAIT; } userEvents.add(new UserEvent(eventType, dTimeStamp, dTimeStamp + 0.5)); } Collections.sort(userEvents, new UserEventSorting()); } return userEvents; } }
ScreenRotationReaderImpl extends PeripheralBase implements IScreenRotationReader { @Override public List<UserEvent> readData(String directory, double startTime) { List<UserEvent> userEvents = new ArrayList<UserEvent>(); String filepath = directory + Util.FILE_SEPARATOR + TraceDataConst.FileName.SCREEN_ROTATIONS_FILE; if(!filereader.fileExist(filepath)){ return userEvents; } String[] lines = null; try { lines = filereader.readAllLine(filepath); } catch (IOException e) { LOGGER.error("failed to read screen rotation file: "+filepath); } if(lines != null){ for(String line: lines) { String[] strFields = line.split(" "); double dTimeStamp = Util.normalizeTime(Double.parseDouble(strFields[0]), startTime); if (strFields[1].contains(TraceDataConst.UserEvent.KEY_LANDSCAPE)) { eventType = UserEventType.SCREEN_LANDSCAPE; } else if (strFields[1].contains(TraceDataConst.UserEvent.KEY_PORTRAIT)) { eventType = UserEventType.SCREEN_PORTRAIT; } userEvents.add(new UserEvent(eventType, dTimeStamp, dTimeStamp + 0.5)); } Collections.sort(userEvents, new UserEventSorting()); } return userEvents; }  }
ScreenRotationReaderImpl extends PeripheralBase implements IScreenRotationReader { @Override public List<UserEvent> readData(String directory, double startTime) { List<UserEvent> userEvents = new ArrayList<UserEvent>(); String filepath = directory + Util.FILE_SEPARATOR + TraceDataConst.FileName.SCREEN_ROTATIONS_FILE; if(!filereader.fileExist(filepath)){ return userEvents; } String[] lines = null; try { lines = filereader.readAllLine(filepath); } catch (IOException e) { LOGGER.error("failed to read screen rotation file: "+filepath); } if(lines != null){ for(String line: lines) { String[] strFields = line.split(" "); double dTimeStamp = Util.normalizeTime(Double.parseDouble(strFields[0]), startTime); if (strFields[1].contains(TraceDataConst.UserEvent.KEY_LANDSCAPE)) { eventType = UserEventType.SCREEN_LANDSCAPE; } else if (strFields[1].contains(TraceDataConst.UserEvent.KEY_PORTRAIT)) { eventType = UserEventType.SCREEN_PORTRAIT; } userEvents.add(new UserEvent(eventType, dTimeStamp, dTimeStamp + 0.5)); } Collections.sort(userEvents, new UserEventSorting()); } return userEvents; }  @Override List<UserEvent> readData(String directory, double startTime); UserEventType getEventType(); }
ScreenRotationReaderImpl extends PeripheralBase implements IScreenRotationReader { @Override public List<UserEvent> readData(String directory, double startTime) { List<UserEvent> userEvents = new ArrayList<UserEvent>(); String filepath = directory + Util.FILE_SEPARATOR + TraceDataConst.FileName.SCREEN_ROTATIONS_FILE; if(!filereader.fileExist(filepath)){ return userEvents; } String[] lines = null; try { lines = filereader.readAllLine(filepath); } catch (IOException e) { LOGGER.error("failed to read screen rotation file: "+filepath); } if(lines != null){ for(String line: lines) { String[] strFields = line.split(" "); double dTimeStamp = Util.normalizeTime(Double.parseDouble(strFields[0]), startTime); if (strFields[1].contains(TraceDataConst.UserEvent.KEY_LANDSCAPE)) { eventType = UserEventType.SCREEN_LANDSCAPE; } else if (strFields[1].contains(TraceDataConst.UserEvent.KEY_PORTRAIT)) { eventType = UserEventType.SCREEN_PORTRAIT; } userEvents.add(new UserEvent(eventType, dTimeStamp, dTimeStamp + 0.5)); } Collections.sort(userEvents, new UserEventSorting()); } return userEvents; }  @Override List<UserEvent> readData(String directory, double startTime); UserEventType getEventType();  }