MediaFileReader { void addMedia(MediaFile mf) { final File mediaPlayerDirectory = getMediaPlayerDirectory(); boolean mediaPlayerDirectoryCreated = mediaPlayerDirectory.mkdirs(); log.debug("mediaPlayerDirectoryCreated = {}", mediaPlayerDirectoryCreated); final File playlistFile = new File(mediaPlayerDirectory, PLAYER_LIST_CSV); try { boolean fileIsUsable = playlistFile.exists(); if (!fileIsUsable) { fileIsUsable = playlistFile.createNewFile(); } if (fileIsUsable) { try ( OutputStream fileOutputStream = Files.newOutputStream(playlistFile.toPath(), StandardOpenOption.CREATE, APPEND); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fileOutputStream, StandardCharsets.UTF_8)) ) { if (mediaList.size() == 0) { bw.write("" + mf.getType() + "," + mf.getPath() + "," + mf.getName() + "," + mf.getImagepath()); } else { bw.write("\n" + mf.getType() + "," + mf.getPath() + "," + mf.getName() + "," + mf.getImagepath()); } } } } catch (IOException e) { throw new RuntimeException(e); } mediaList.add(mf); firstMediaDisplayedIndex.setValue(mediaList.size() - 1); } MediaFileReader(IGameContext gameContext); void setPlayingMediaIndex(int newIndex); void next(); File getMediaPlayerDirectory();  }
@Test void shouldAddMedia() { MediaFileReader mfr = new MediaFileReader(mockGameContext) { @Override public File getMediaPlayerDirectory() { return testDir; } }; MediaFile mediaTypeMediaFile = new MediaFile("MEDIA", "https: mfr.addMedia(mediaTypeMediaFile); assertTrue(mfr.getMediaList().contains(mediaTypeMediaFile)); MediaFile urlTypeMediaFile = new MediaFile("URL", "https: mfr.addMedia(urlTypeMediaFile); assertTrue(mfr.getMediaList().contains(mediaTypeMediaFile)); assertTrue(mfr.getMediaList().contains(urlTypeMediaFile)); }