@Test public void testExceptionIsThrownIfFileDoesntExist() throws UserVisibleException { when(io.fileExists()).thenReturn(false); assertTrue(storage.load() instanceof List && storage.load().size() == 0); }
@Override public List<Course> load() { if (!io.fileExists()) { return new ArrayList<Course>(); } CoursesFileFormat courseList = null; Reader reader = io.getReader(); if (reader == null) { throw new UserVisibleException("Could not load course data from local storage."); } try { courseList = gson.fromJson(reader, CoursesFileFormat.class); } catch (JsonSyntaxException ex) { throw new UserVisibleException("Local course storage corrupted"); } finally { try { reader.close(); } catch (IOException e) { return getCourses(courseList); } } return getCourses(courseList); }
CourseStorage implements DataSource<Course> { @Override public List<Course> load() { if (!io.fileExists()) { return new ArrayList<Course>(); } CoursesFileFormat courseList = null; Reader reader = io.getReader(); if (reader == null) { throw new UserVisibleException("Could not load course data from local storage."); } try { courseList = gson.fromJson(reader, CoursesFileFormat.class); } catch (JsonSyntaxException ex) { throw new UserVisibleException("Local course storage corrupted"); } finally { try { reader.close(); } catch (IOException e) { return getCourses(courseList); } } return getCourses(courseList); } }
CourseStorage implements DataSource<Course> { @Override public List<Course> load() { if (!io.fileExists()) { return new ArrayList<Course>(); } CoursesFileFormat courseList = null; Reader reader = io.getReader(); if (reader == null) { throw new UserVisibleException("Could not load course data from local storage."); } try { courseList = gson.fromJson(reader, CoursesFileFormat.class); } catch (JsonSyntaxException ex) { throw new UserVisibleException("Local course storage corrupted"); } finally { try { reader.close(); } catch (IOException e) { return getCourses(courseList); } } return getCourses(courseList); } CourseStorage(FileIO io); }
CourseStorage implements DataSource<Course> { @Override public List<Course> load() { if (!io.fileExists()) { return new ArrayList<Course>(); } CoursesFileFormat courseList = null; Reader reader = io.getReader(); if (reader == null) { throw new UserVisibleException("Could not load course data from local storage."); } try { courseList = gson.fromJson(reader, CoursesFileFormat.class); } catch (JsonSyntaxException ex) { throw new UserVisibleException("Local course storage corrupted"); } finally { try { reader.close(); } catch (IOException e) { return getCourses(courseList); } } return getCourses(courseList); } CourseStorage(FileIO io); @Override List<Course> load(); @Override void save(List<Course> courses); }
CourseStorage implements DataSource<Course> { @Override public List<Course> load() { if (!io.fileExists()) { return new ArrayList<Course>(); } CoursesFileFormat courseList = null; Reader reader = io.getReader(); if (reader == null) { throw new UserVisibleException("Could not load course data from local storage."); } try { courseList = gson.fromJson(reader, CoursesFileFormat.class); } catch (JsonSyntaxException ex) { throw new UserVisibleException("Local course storage corrupted"); } finally { try { reader.close(); } catch (IOException e) { return getCourses(courseList); } } return getCourses(courseList); } CourseStorage(FileIO io); @Override List<Course> load(); @Override void save(List<Course> courses);  }