ConfigurationContext extends GraphicalContext<BorderPane> { static void changeMusicFolder(final String newMusicFolder, Configuration config) { String musicFolder = newMusicFolder; if (musicFolder.isBlank()) { File gazePlayFolder = GazePlayDirectories.getGazePlayFolder(); File gazePlayMusicFolder = new File(gazePlayFolder, "music"); String songName = Configuration.DEFAULT_VALUE_BACKGROUND_MUSIC; setupNewMusicFolder(gazePlayMusicFolder, songName); musicFolder = gazePlayMusicFolder.getAbsolutePath(); } config.getMusicFolderProperty().setValue(musicFolder); BackgroundMusicManager musicManager = BackgroundMusicManager.getInstance(); boolean wasPlaying = musicManager.isPlaying(); musicManager.emptyPlaylist(); musicManager.getAudioFromFolder(musicFolder); if (wasPlaying) musicManager.play(); } ConfigurationContext(GazePlay gazePlay); @Override ObservableList<Node> getChildren();  }
@Test void shouldChangeTheMusicFolderAndPlayIfWasPlaying(@Mocked BackgroundMusicManager mockMusicManager, @Mocked Configuration mockConfiguration) { StringProperty mockMusicFolderProperty = new SimpleStringProperty(); new Expectations() {{ mockMusicManager.isPlaying(); result = true; BackgroundMusicManager.getInstance(); result = mockMusicManager; mockConfiguration.getMusicFolderProperty(); result = mockMusicFolderProperty; }}; ConfigurationContext.changeMusicFolder("mockFolder", mockConfiguration); new Verifications() {{ mockMusicManager.play(); times = 1; }}; }
@Test void shouldChangeTheMusicFolderAndNotPlayIfWasNotPlaying(@Mocked BackgroundMusicManager mockMusicManager, @Mocked Configuration mockConfiguration) { StringProperty mockMusicFolderProperty = new SimpleStringProperty(); new Expectations() {{ mockMusicManager.isPlaying(); result = false; BackgroundMusicManager.getInstance(); result = mockMusicManager; mockConfiguration.getMusicFolderProperty(); result = mockMusicFolderProperty; }}; ConfigurationContext.changeMusicFolder("mockFolder", mockConfiguration); new Verifications() {{ mockMusicManager.play(); times = 0; }}; }
@Test void shouldChangeTheMusicFolderWithBlankFolder(@Mocked BackgroundMusicManager mockMusicManager, @Mocked Configuration mockConfiguration) { StringProperty mockMusicFolderProperty = new SimpleStringProperty(); String expectedFolder = System.getProperty("user.home") + File.separator + "GazePlay" + File.separator + "music"; new Expectations() {{ mockMusicManager.isPlaying(); result = false; BackgroundMusicManager.getInstance(); result = mockMusicManager; mockConfiguration.getMusicFolderProperty(); result = mockMusicFolderProperty; }}; ConfigurationContext.changeMusicFolder("", mockConfiguration); new Verifications() {{ mockMusicManager.getAudioFromFolder(expectedFolder); }}; }