Browse Source

Merge commit 'de82f475dd2f7f7453406f886519043de7ea7998' into HEAD

feature-pr-RadioPlayer-getOptions
Jenkins 3 years ago
parent
commit
9830ace3fd
  1. 8
      src/main/java/device/radioPlayer/RadioPlayer.java
  2. 31
      src/test/java/device/radioPlayer/RadioPlayerTest.java

8
src/main/java/device/radioPlayer/RadioPlayer.java

@ -22,6 +22,7 @@ public class RadioPlayer implements Device {
LocalDateTime now = LocalDateTime.now(); LocalDateTime now = LocalDateTime.now();
int hour = now.getHour(); int hour = now.getHour();
int Lautstaerke = 0; int Lautstaerke = 0;
int savedVolume;
String playedStation = ""; String playedStation = "";
public String getYouFMInfoByTime(int x) { public String getYouFMInfoByTime(int x) {
@ -193,12 +194,15 @@ public class RadioPlayer implements Device {
@Override @Override
public String mute() { public String mute() {
return null;
savedVolume = getVolume();
setLautstaerke(0);
return "RadioPlayer is muted now";
} }
@Override @Override
public String unmute() { public String unmute() {
return null;
setLautstaerke(savedVolume);
return ("RadioPlayer is unmuted Volume is set to " + getVolume());
} }

31
src/test/java/device/radioPlayer/RadioPlayerTest.java

@ -342,4 +342,35 @@ class RadioPlayerTest {
Arguments.of("Test for return regional playlist", rp1, "region", rp1.regionPlaylist.toArray(new String[0])) Arguments.of("Test for return regional playlist", rp1, "region", rp1.regionPlaylist.toArray(new String[0]))
); );
} }
@ParameterizedTest
@MethodSource("muteOptions")
void testMute(String testName, String testTyp, RadioPlayer testRp, int expectedResult) {
int volume;
if (testTyp.equals("actual")) volume = testRp.getVolume();
else volume = testRp.savedVolume;
assertThat(volume).describedAs(testName).isEqualTo(expectedResult);
}
static Stream<Arguments> muteOptions() {
RadioPlayer rp = new RadioPlayer();
rp.setLautstaerke(25);
rp.mute();
RadioPlayer rp1 = new RadioPlayer();
rp1.setLautstaerke(30);
rp1.mute();
return Stream.of(
Arguments.of("Test for mute RadioPlayer if volume is actually 0", "actual", rp, 0),
Arguments.of("Test for mute RadioPlayer if volume is saved before muting", "saved", rp1, 30)
);
}
@Test
void TestUnmute() {
RadioPlayer rp = new RadioPlayer();
rp.setLautstaerke(40);
rp.mute();
rp.unmute();
assertThat(rp.getVolume()).describedAs("Test if unmute is setting the saved volume").isEqualTo(rp.savedVolume);
}
} }
Loading…
Cancel
Save