From f8bcf0c62b1007777ad21ad29e880e220a4495ea Mon Sep 17 00:00:00 2001 From: alpina0707 Date: Wed, 16 Feb 2022 21:14:54 +0100 Subject: [PATCH 1/3] added first test case for mute() & and added productive code for RadioPlayer --- .../java/device/radioPlayer/RadioPlayer.java | 3 ++- .../device/radioPlayer/RadioPlayerTest.java | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/main/java/device/radioPlayer/RadioPlayer.java b/src/main/java/device/radioPlayer/RadioPlayer.java index 5ef8556..90bfffb 100644 --- a/src/main/java/device/radioPlayer/RadioPlayer.java +++ b/src/main/java/device/radioPlayer/RadioPlayer.java @@ -193,7 +193,8 @@ public class RadioPlayer implements Device { @Override public String mute() { - return null; + setLautstaerke(0); + return "RadioPlayer is muted now"; } @Override diff --git a/src/test/java/device/radioPlayer/RadioPlayerTest.java b/src/test/java/device/radioPlayer/RadioPlayerTest.java index 4de54c2..af01010 100644 --- a/src/test/java/device/radioPlayer/RadioPlayerTest.java +++ b/src/test/java/device/radioPlayer/RadioPlayerTest.java @@ -342,4 +342,22 @@ class RadioPlayerTest { Arguments.of("Test for return regional playlist", rp1, "region", rp1.regionPlaylist.toArray(new String[0])) ); } + + @ParameterizedTest + @MethodSource("muteOptions") + void testMute(String testName, RadioPlayer testRp, int expectedResult) { + + int volume = testRp.getVolume(); + assertThat(volume).describedAs(testName).isEqualTo(expectedResult); + } + + static Stream muteOptions() { + RadioPlayer rp = new RadioPlayer(); + rp.setLautstaerke(25); + rp.mute(); + + return Stream.of( + Arguments.of("Test for mute RadioPlayer if volume is actually 0", rp, 0) + ); + } } \ No newline at end of file From 8b23b50442e4552404e435caee641f8fbe1bc296 Mon Sep 17 00:00:00 2001 From: alpina0707 Date: Wed, 16 Feb 2022 21:23:20 +0100 Subject: [PATCH 2/3] added second test case for mute() & and added productive code for RadioPlayer --- src/main/java/device/radioPlayer/RadioPlayer.java | 2 ++ .../java/device/radioPlayer/RadioPlayerTest.java | 13 +++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/main/java/device/radioPlayer/RadioPlayer.java b/src/main/java/device/radioPlayer/RadioPlayer.java index 90bfffb..a510fef 100644 --- a/src/main/java/device/radioPlayer/RadioPlayer.java +++ b/src/main/java/device/radioPlayer/RadioPlayer.java @@ -22,6 +22,7 @@ public class RadioPlayer implements Device { LocalDateTime now = LocalDateTime.now(); int hour = now.getHour(); int Lautstaerke = 0; + int savedVolume; String playedStation = ""; public String getYouFMInfoByTime(int x) { @@ -193,6 +194,7 @@ public class RadioPlayer implements Device { @Override public String mute() { + savedVolume = getVolume(); setLautstaerke(0); return "RadioPlayer is muted now"; } diff --git a/src/test/java/device/radioPlayer/RadioPlayerTest.java b/src/test/java/device/radioPlayer/RadioPlayerTest.java index af01010..2570bb1 100644 --- a/src/test/java/device/radioPlayer/RadioPlayerTest.java +++ b/src/test/java/device/radioPlayer/RadioPlayerTest.java @@ -345,9 +345,10 @@ class RadioPlayerTest { @ParameterizedTest @MethodSource("muteOptions") - void testMute(String testName, RadioPlayer testRp, int expectedResult) { - - int volume = testRp.getVolume(); + 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); } @@ -355,9 +356,13 @@ class RadioPlayerTest { 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", rp, 0) + 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) ); } } \ No newline at end of file From de82f475dd2f7f7453406f886519043de7ea7998 Mon Sep 17 00:00:00 2001 From: alpina0707 Date: Wed, 16 Feb 2022 21:32:19 +0100 Subject: [PATCH 3/3] added test case for unmute() & and added productive code for RadioPlayer --- src/main/java/device/radioPlayer/RadioPlayer.java | 3 ++- src/test/java/device/radioPlayer/RadioPlayerTest.java | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/device/radioPlayer/RadioPlayer.java b/src/main/java/device/radioPlayer/RadioPlayer.java index a510fef..2b91e3e 100644 --- a/src/main/java/device/radioPlayer/RadioPlayer.java +++ b/src/main/java/device/radioPlayer/RadioPlayer.java @@ -201,7 +201,8 @@ public class RadioPlayer implements Device { @Override public String unmute() { - return null; + setLautstaerke(savedVolume); + return ("RadioPlayer is unmuted Volume is set to " + getVolume()); } diff --git a/src/test/java/device/radioPlayer/RadioPlayerTest.java b/src/test/java/device/radioPlayer/RadioPlayerTest.java index 2570bb1..ac5eefc 100644 --- a/src/test/java/device/radioPlayer/RadioPlayerTest.java +++ b/src/test/java/device/radioPlayer/RadioPlayerTest.java @@ -365,4 +365,12 @@ class RadioPlayerTest { 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); + } } \ No newline at end of file