MusicControl { Node createMuteSwitchButton(final Slider volumeSlider) { final Button muteButton = createButton("mute", SPEAKER_ICON, "mute", ICON_SIZE / 2d); final Button unmuteButton = createButton("unmute", MUTE_ICON, "unmute", ICON_SIZE / 2d); setUpSwitchButton(muteButton); setUpSwitchButton(unmuteButton); final boolean muted = volumeSlider.getValue() == 0; muteButton.setVisible(!muted); unmuteButton.setVisible(muted); if (muted) { beforeMutedValue = Configuration.DEFAULT_VALUE_MUSIC_VOLUME; } else { beforeMutedValue = volumeSlider.getValue(); } muteButton.setOnAction((event) -> { beforeMutedValue = volumeSlider.getValue(); volumeSlider.setValue(0); }); unmuteButton.setOnAction((event) -> volumeSlider.setValue(beforeMutedValue)); volumeSlider.valueProperty().addListener((observable, oldValue, newValue) -> { final boolean localMuted = newValue.doubleValue() == 0; muteButton.setVisible(!localMuted); unmuteButton.setVisible(localMuted); }); return new StackPane(muteButton, unmuteButton); }  void updateMusicController(); TitledPane createMusicControlPane(); TitledPane createVolumeLevelControlPane(final Configuration config, final Translator translator);  }
@Test void shouldCreateUnmutedMuteSwitch() { mockVolumeSlider.setValue(0.5); StackPane result = (StackPane) musicControl.createMuteSwitchButton(mockVolumeSlider); Button mute = (Button) result.getChildren().get(0); Button unmute = (Button) result.getChildren().get(1); assertTrue(mute.isVisible()); assertFalse(unmute.isVisible()); }
@Test void shouldCreateMutedMuteSwitch() { mockVolumeSlider.setValue(0); StackPane result = (StackPane) musicControl.createMuteSwitchButton(mockVolumeSlider); Button mute = (Button) result.getChildren().get(0); Button unmute = (Button) result.getChildren().get(1); assertFalse(mute.isVisible()); assertTrue(unmute.isVisible()); }
@Test void shouldMuteVolumeWhenMuteButtonPressed() { mockVolumeSlider.setValue(0.5); StackPane result = (StackPane) musicControl.createMuteSwitchButton(mockVolumeSlider); Button mute = (Button) result.getChildren().get(0); mute.fire(); assertEquals(0, mockVolumeSlider.getValue()); }
@Test void shouldUnmuteVolumeWhenUnmuteButtonPressed() { mockVolumeSlider.setValue(0); StackPane result = (StackPane) musicControl.createMuteSwitchButton(mockVolumeSlider); Button unmute = (Button) result.getChildren().get(1); unmute.fire(); assertNotEquals(0, mockVolumeSlider.getValue()); }
@Test void shouldShowMuteButtonWhenVolumeIsIncreased() { mockVolumeSlider.setValue(0); StackPane result = (StackPane) musicControl.createMuteSwitchButton(mockVolumeSlider); Button mute = (Button) result.getChildren().get(0); Button unmute = (Button) result.getChildren().get(1); mockVolumeSlider.setValue(0.5); assertFalse(unmute.isVisible()); assertTrue(mute.isVisible()); }
@Test void shouldShowUnmuteButtonWhenVolumeIsSetToZero() { mockVolumeSlider.setValue(0.5); StackPane result = (StackPane) musicControl.createMuteSwitchButton(mockVolumeSlider); Button mute = (Button) result.getChildren().get(0); Button unmute = (Button) result.getChildren().get(1); mockVolumeSlider.setValue(0); assertFalse(mute.isVisible()); assertTrue(unmute.isVisible()); }