@Test(expected = UserVisibleException.class) public void saveThrowsIfIOIsNull() { storage = new ProjectStorage(null); storage.save(projects); }
@Override public void save(List<Project> projects) { ProjectsFileFormat projectList = new ProjectsFileFormat(); projectList.setProjects(projects); if (io == null) { throw new UserVisibleException("Could not save project data to local storage."); } Writer writer = io.getWriter(); if (writer == null) { throw new UserVisibleException("Could not save project data to local storage."); } gson.toJson(projectList, writer); try { writer.close(); } catch (IOException e) { return; } }
ProjectStorage implements DataSource<Project> { @Override public void save(List<Project> projects) { ProjectsFileFormat projectList = new ProjectsFileFormat(); projectList.setProjects(projects); if (io == null) { throw new UserVisibleException("Could not save project data to local storage."); } Writer writer = io.getWriter(); if (writer == null) { throw new UserVisibleException("Could not save project data to local storage."); } gson.toJson(projectList, writer); try { writer.close(); } catch (IOException e) { return; } } }
ProjectStorage implements DataSource<Project> { @Override public void save(List<Project> projects) { ProjectsFileFormat projectList = new ProjectsFileFormat(); projectList.setProjects(projects); if (io == null) { throw new UserVisibleException("Could not save project data to local storage."); } Writer writer = io.getWriter(); if (writer == null) { throw new UserVisibleException("Could not save project data to local storage."); } gson.toJson(projectList, writer); try { writer.close(); } catch (IOException e) { return; } } ProjectStorage(FileIO io); }
ProjectStorage implements DataSource<Project> { @Override public void save(List<Project> projects) { ProjectsFileFormat projectList = new ProjectsFileFormat(); projectList.setProjects(projects); if (io == null) { throw new UserVisibleException("Could not save project data to local storage."); } Writer writer = io.getWriter(); if (writer == null) { throw new UserVisibleException("Could not save project data to local storage."); } gson.toJson(projectList, writer); try { writer.close(); } catch (IOException e) { return; } } ProjectStorage(FileIO io); @Override List<Project> load(); @Override void save(List<Project> projects); }
ProjectStorage implements DataSource<Project> { @Override public void save(List<Project> projects) { ProjectsFileFormat projectList = new ProjectsFileFormat(); projectList.setProjects(projects); if (io == null) { throw new UserVisibleException("Could not save project data to local storage."); } Writer writer = io.getWriter(); if (writer == null) { throw new UserVisibleException("Could not save project data to local storage."); } gson.toJson(projectList, writer); try { writer.close(); } catch (IOException e) { return; } } ProjectStorage(FileIO io); @Override List<Project> load(); @Override void save(List<Project> projects);  }