@Test(expected = UserVisibleException.class) public void loadThrowsIfReaderIsNull() { when(io.fileExists()).thenReturn(true); when(io.getReader()).thenReturn(null); storage.load(); }
@Override public List<Project> load() { if (!io.fileExists()) { return new ArrayList<Project>(); } ProjectsFileFormat projectList = null; Reader reader = io.getReader(); if (reader == null) { throw new UserVisibleException("Could not load project data from local storage."); } try { projectList = gson.fromJson(reader, ProjectsFileFormat.class); } catch (JsonSyntaxException ex) { throw new UserVisibleException("Local project storage corrupted"); } finally { try { reader.close(); } catch (IOException e) { return getProjectList(projectList); } } return getProjectList(projectList); }
ProjectStorage implements DataSource<Project> { @Override public List<Project> load() { if (!io.fileExists()) { return new ArrayList<Project>(); } ProjectsFileFormat projectList = null; Reader reader = io.getReader(); if (reader == null) { throw new UserVisibleException("Could not load project data from local storage."); } try { projectList = gson.fromJson(reader, ProjectsFileFormat.class); } catch (JsonSyntaxException ex) { throw new UserVisibleException("Local project storage corrupted"); } finally { try { reader.close(); } catch (IOException e) { return getProjectList(projectList); } } return getProjectList(projectList); } }
ProjectStorage implements DataSource<Project> { @Override public List<Project> load() { if (!io.fileExists()) { return new ArrayList<Project>(); } ProjectsFileFormat projectList = null; Reader reader = io.getReader(); if (reader == null) { throw new UserVisibleException("Could not load project data from local storage."); } try { projectList = gson.fromJson(reader, ProjectsFileFormat.class); } catch (JsonSyntaxException ex) { throw new UserVisibleException("Local project storage corrupted"); } finally { try { reader.close(); } catch (IOException e) { return getProjectList(projectList); } } return getProjectList(projectList); } ProjectStorage(FileIO io); }
ProjectStorage implements DataSource<Project> { @Override public List<Project> load() { if (!io.fileExists()) { return new ArrayList<Project>(); } ProjectsFileFormat projectList = null; Reader reader = io.getReader(); if (reader == null) { throw new UserVisibleException("Could not load project data from local storage."); } try { projectList = gson.fromJson(reader, ProjectsFileFormat.class); } catch (JsonSyntaxException ex) { throw new UserVisibleException("Local project storage corrupted"); } finally { try { reader.close(); } catch (IOException e) { return getProjectList(projectList); } } return getProjectList(projectList); } ProjectStorage(FileIO io); @Override List<Project> load(); @Override void save(List<Project> projects); }
ProjectStorage implements DataSource<Project> { @Override public List<Project> load() { if (!io.fileExists()) { return new ArrayList<Project>(); } ProjectsFileFormat projectList = null; Reader reader = io.getReader(); if (reader == null) { throw new UserVisibleException("Could not load project data from local storage."); } try { projectList = gson.fromJson(reader, ProjectsFileFormat.class); } catch (JsonSyntaxException ex) { throw new UserVisibleException("Local project storage corrupted"); } finally { try { reader.close(); } catch (IOException e) { return getProjectList(projectList); } } return getProjectList(projectList); } ProjectStorage(FileIO io); @Override List<Project> load(); @Override void save(List<Project> projects);  }