@Test(expected = UserVisibleException.class) public void saveThrowsIfWritesIsNull() { when(io.getWriter()).thenReturn(null); storage.save(new ArrayList<Course>()); }
@Override public void save(List<Course> courses) { CoursesFileFormat courseList = new CoursesFileFormat(); courseList.setCourses(courses); if (io == null) { throw new UserVisibleException("Could not save course data to local storage."); } Writer writer = io.getWriter(); if (writer == null) { throw new UserVisibleException("Could not save course data to local storage."); } gson.toJson(courseList, writer); try { writer.close(); } catch (IOException e) { return; } }
CourseStorage implements DataSource<Course> { @Override public void save(List<Course> courses) { CoursesFileFormat courseList = new CoursesFileFormat(); courseList.setCourses(courses); if (io == null) { throw new UserVisibleException("Could not save course data to local storage."); } Writer writer = io.getWriter(); if (writer == null) { throw new UserVisibleException("Could not save course data to local storage."); } gson.toJson(courseList, writer); try { writer.close(); } catch (IOException e) { return; } } }
CourseStorage implements DataSource<Course> { @Override public void save(List<Course> courses) { CoursesFileFormat courseList = new CoursesFileFormat(); courseList.setCourses(courses); if (io == null) { throw new UserVisibleException("Could not save course data to local storage."); } Writer writer = io.getWriter(); if (writer == null) { throw new UserVisibleException("Could not save course data to local storage."); } gson.toJson(courseList, writer); try { writer.close(); } catch (IOException e) { return; } } CourseStorage(FileIO io); }
CourseStorage implements DataSource<Course> { @Override public void save(List<Course> courses) { CoursesFileFormat courseList = new CoursesFileFormat(); courseList.setCourses(courses); if (io == null) { throw new UserVisibleException("Could not save course data to local storage."); } Writer writer = io.getWriter(); if (writer == null) { throw new UserVisibleException("Could not save course data to local storage."); } gson.toJson(courseList, writer); try { writer.close(); } catch (IOException e) { return; } } CourseStorage(FileIO io); @Override List<Course> load(); @Override void save(List<Course> courses); }
CourseStorage implements DataSource<Course> { @Override public void save(List<Course> courses) { CoursesFileFormat courseList = new CoursesFileFormat(); courseList.setCourses(courses); if (io == null) { throw new UserVisibleException("Could not save course data to local storage."); } Writer writer = io.getWriter(); if (writer == null) { throw new UserVisibleException("Could not save course data to local storage."); } gson.toJson(courseList, writer); try { writer.close(); } catch (IOException e) { return; } } CourseStorage(FileIO io); @Override List<Course> load(); @Override void save(List<Course> courses);  }