ConfigurationContext extends GraphicalContext<BorderPane> { static void setupNewMusicFolder(File gazePlayMusicFolder, String defaultSong) { if (!gazePlayMusicFolder.exists()) { boolean musicFolderCreated = gazePlayMusicFolder.mkdir(); log.debug("musicFolderCreated = " + musicFolderCreated); } String resourcePath = "data/home/sounds/" + defaultSong; try { InputStream defaultMusicTrack = Thread.currentThread().getContextClassLoader().getResourceAsStream(resourcePath); if (gazePlayMusicFolder.exists()) { Files.copy(defaultMusicTrack, Paths.get(new File(gazePlayMusicFolder, defaultSong).getAbsolutePath()), StandardCopyOption.REPLACE_EXISTING); } } catch (NullPointerException ne) { log.debug(String.format("Could not find %s: %s", resourcePath, ne.toString())); } catch (IOException ie) { log.debug(String.format("Could not copy file at %s to %s: %s", resourcePath, gazePlayMusicFolder, ie.toString())); } } ConfigurationContext(GazePlay gazePlay); @Override ObservableList<Node> getChildren();  }
@Test void shouldSetupANewMusicFolder() { String songName = "songidea(copycat)_0.mp3"; File testFolder = new File("music_test"); File expectedFile = new File(testFolder, songName); ConfigurationContext.setupNewMusicFolder(testFolder, songName); assertTrue(testFolder.isDirectory()); assertTrue(expectedFile.exists()); assertTrue(expectedFile.delete()); assertTrue(testFolder.delete()); }
@Test void shouldSetupANewMusicFolderIfTheFolderExists() { String songName = "songidea(copycat)_0.mp3"; File testFolder = new File("music_test"); assertTrue(testFolder.mkdir()); File expectedFile = new File(testFolder, songName); ConfigurationContext.setupNewMusicFolder(testFolder, songName); assertTrue(testFolder.isDirectory()); assertTrue(expectedFile.exists()); assertTrue(expectedFile.delete()); assertTrue(testFolder.delete()); }
@Test void shouldSetupANewMusicFolderIfTheSongDoesntExist() { String songName = "fakesong.mp3"; File testFolder = new File("music_test"); assertTrue(testFolder.mkdir()); File expectedFile = new File(testFolder, songName); ConfigurationContext.setupNewMusicFolder(testFolder, songName); assertTrue(testFolder.isDirectory()); assertFalse(expectedFile.exists()); assertTrue(testFolder.delete()); }