From e5b9f46ce7b8c864340b39d4a0127c5e8df4ebe9 Mon Sep 17 00:00:00 2001 From: alpina0707 Date: Wed, 16 Feb 2022 17:53:53 +0100 Subject: [PATCH 01/11] added first test case for chooseItem() & and added productive code for RadioPlayer --- .../java/device/radioPlayer/RadioPlayer.java | 3 ++- .../device/radioPlayer/RadioPlayerTest.java | 21 +++++++++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/main/java/device/radioPlayer/RadioPlayer.java b/src/main/java/device/radioPlayer/RadioPlayer.java index 858cf13..5a79bc8 100644 --- a/src/main/java/device/radioPlayer/RadioPlayer.java +++ b/src/main/java/device/radioPlayer/RadioPlayer.java @@ -158,7 +158,8 @@ public class RadioPlayer implements Device { @Override public String chooseItem(int itemNr) { - return null; + playedStation = savedPlaylist.get(itemNr - 1); + return ("Radio is playing station: 0" + (savedPlaylist.indexOf(playedStation) + 1) + " " + this.playedStation + " from saved playlist"); } @Override diff --git a/src/test/java/device/radioPlayer/RadioPlayerTest.java b/src/test/java/device/radioPlayer/RadioPlayerTest.java index 109e1d1..6de8fc1 100644 --- a/src/test/java/device/radioPlayer/RadioPlayerTest.java +++ b/src/test/java/device/radioPlayer/RadioPlayerTest.java @@ -171,11 +171,24 @@ class RadioPlayerTest { @Test void getOptions() { } - - @Test - void chooseOption() { - } */ + + @ParameterizedTest + @MethodSource("chooseItemOptions") + void testChooseItem(String testName, RadioPlayer testRp, String expectedResult) { + String playedStation = testRp.playedStation; + assertThat(playedStation).describedAs(testName).isEqualTo(expectedResult); + } + + static Stream chooseItemOptions() { + RadioPlayer rp = new RadioPlayer(); + rp.chooseItem(2); + + return Stream.of( + Arguments.of("Test select station to play with nr isn`t bigger than playlist size", rp, "Teddy") + ); + } + @ParameterizedTest @MethodSource("testPlayOptions") void testPlay(String testName, RadioPlayer testRp, String expectedResult) { From 820d148f3000d97e09ae57794502b5c17286b48d Mon Sep 17 00:00:00 2001 From: alpina0707 Date: Wed, 16 Feb 2022 18:19:37 +0100 Subject: [PATCH 02/11] added second test case for chooseItem() & and added productive code for RadioPlayer --- src/main/java/device/radioPlayer/RadioPlayer.java | 9 +++++++-- src/test/java/device/radioPlayer/RadioPlayerTest.java | 5 ++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/main/java/device/radioPlayer/RadioPlayer.java b/src/main/java/device/radioPlayer/RadioPlayer.java index 5a79bc8..8568110 100644 --- a/src/main/java/device/radioPlayer/RadioPlayer.java +++ b/src/main/java/device/radioPlayer/RadioPlayer.java @@ -158,8 +158,13 @@ public class RadioPlayer implements Device { @Override public String chooseItem(int itemNr) { - playedStation = savedPlaylist.get(itemNr - 1); - return ("Radio is playing station: 0" + (savedPlaylist.indexOf(playedStation) + 1) + " " + this.playedStation + " from saved playlist"); + if(itemNr > savedPlaylist.size()) { + playedStation = savedPlaylist.get(savedPlaylist.size()-1); + return ("Radio is playing station: 0" + savedPlaylist.size() + " " + this.playedStation + " from saved playlist"); + }else{ + playedStation = savedPlaylist.get(itemNr - 1); + return ("Radio is playing station: 0" + (savedPlaylist.indexOf(playedStation) + 1) + " " + this.playedStation + " from saved playlist"); + } } @Override diff --git a/src/test/java/device/radioPlayer/RadioPlayerTest.java b/src/test/java/device/radioPlayer/RadioPlayerTest.java index 6de8fc1..b7fa5ef 100644 --- a/src/test/java/device/radioPlayer/RadioPlayerTest.java +++ b/src/test/java/device/radioPlayer/RadioPlayerTest.java @@ -183,9 +183,12 @@ class RadioPlayerTest { static Stream chooseItemOptions() { RadioPlayer rp = new RadioPlayer(); rp.chooseItem(2); + RadioPlayer rp1 = new RadioPlayer(); + rp1.chooseItem(5); return Stream.of( - Arguments.of("Test select station to play with nr isn`t bigger than playlist size", rp, "Teddy") + Arguments.of("Test select station in saved playlist to play with nr isn`t bigger than playlist size", rp, "Teddy"), + Arguments.of("Test select station in saved playlist to play with nr is bigger than playlist size. Last station in playlist gets played", rp1, "MegaHits") ); } From cd09cb87758069b47552ec7fd0e3629d9276ffa7 Mon Sep 17 00:00:00 2001 From: alpina0707 Date: Wed, 16 Feb 2022 18:55:20 +0100 Subject: [PATCH 03/11] added third test case for chooseItem() & and added productive code for RadioPlayer --- .../java/device/radioPlayer/RadioPlayer.java | 27 ++++++++++--------- .../device/radioPlayer/RadioPlayerTest.java | 5 +++- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/main/java/device/radioPlayer/RadioPlayer.java b/src/main/java/device/radioPlayer/RadioPlayer.java index 8568110..5e9d7fe 100644 --- a/src/main/java/device/radioPlayer/RadioPlayer.java +++ b/src/main/java/device/radioPlayer/RadioPlayer.java @@ -158,12 +158,16 @@ public class RadioPlayer implements Device { @Override public String chooseItem(int itemNr) { - if(itemNr > savedPlaylist.size()) { - playedStation = savedPlaylist.get(savedPlaylist.size()-1); + if (itemNr > savedPlaylist.size()) { + playedStation = savedPlaylist.get(savedPlaylist.size() - 1); return ("Radio is playing station: 0" + savedPlaylist.size() + " " + this.playedStation + " from saved playlist"); - }else{ + } else if (itemNr < 1) { + playedStation = savedPlaylist.get(0); + return ("Radio is playing station: 01 " + this.playedStation + " from saved playlist"); + } else { playedStation = savedPlaylist.get(itemNr - 1); return ("Radio is playing station: 0" + (savedPlaylist.indexOf(playedStation) + 1) + " " + this.playedStation + " from saved playlist"); + } } @@ -214,7 +218,7 @@ public class RadioPlayer implements Device { } public String changeToSavedPlaylist() { - if(regionPlaylist.contains(playedStation)) { + if (regionPlaylist.contains(playedStation)) { playedStation = savedPlaylist.get(0); regionPlaylist.clear(); return "Playlist switched now playing station: 0" + (savedPlaylist.indexOf(playedStation) + 1) + " " + this.playedStation + " from saved playlist"; @@ -224,16 +228,15 @@ public class RadioPlayer implements Device { public String changeOrderInSavedPlaylist(int nr) { String station = playedStation; - if((nr-1) > savedPlaylist.size()) { + if ((nr - 1) > savedPlaylist.size()) { savedPlaylist.remove(playedStation); - savedPlaylist.add(savedPlaylist.size(),station); - return"Station " + playedStation + " is now on place 0" + (savedPlaylist.size()+1) + "in saved playlist"; - }else if(nr < 0) { + savedPlaylist.add(savedPlaylist.size(), station); + return "Station " + playedStation + " is now on place 0" + (savedPlaylist.size() + 1) + "in saved playlist"; + } else if (nr < 0) { savedPlaylist.remove(playedStation); - savedPlaylist.add(0,station); - return"Station " + playedStation + " is now on place 01 in saved playlist"; - } - else { + savedPlaylist.add(0, station); + return "Station " + playedStation + " is now on place 01 in saved playlist"; + } else { savedPlaylist.remove(playedStation); savedPlaylist.add(nr - 1, station); return "Station " + playedStation + " is now on place 0" + nr + "in saved playlist"; diff --git a/src/test/java/device/radioPlayer/RadioPlayerTest.java b/src/test/java/device/radioPlayer/RadioPlayerTest.java index b7fa5ef..6e6121c 100644 --- a/src/test/java/device/radioPlayer/RadioPlayerTest.java +++ b/src/test/java/device/radioPlayer/RadioPlayerTest.java @@ -185,10 +185,13 @@ class RadioPlayerTest { rp.chooseItem(2); RadioPlayer rp1 = new RadioPlayer(); rp1.chooseItem(5); + RadioPlayer rp2 = new RadioPlayer(); + rp2.chooseItem(-1); return Stream.of( Arguments.of("Test select station in saved playlist to play with nr isn`t bigger than playlist size", rp, "Teddy"), - Arguments.of("Test select station in saved playlist to play with nr is bigger than playlist size. Last station in playlist gets played", rp1, "MegaHits") + Arguments.of("Test select station in saved playlist to play with nr is bigger than playlist size. Last station in playlist gets played", rp1, "MegaHits"), + Arguments.of("Test select station in saved playlist to play with nr is lower than 0. First station in playlist gets played", rp2, "YouFM") ); } From a5c936d2700431c797b59835703ebf92454bc0d1 Mon Sep 17 00:00:00 2001 From: alpina0707 Date: Wed, 16 Feb 2022 18:57:40 +0100 Subject: [PATCH 04/11] added fourth test case for chooseItem() & and added productive code for RadioPlayer --- .../java/device/radioPlayer/RadioPlayer.java | 22 +++++++++++-------- .../device/radioPlayer/RadioPlayerTest.java | 6 ++++- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/main/java/device/radioPlayer/RadioPlayer.java b/src/main/java/device/radioPlayer/RadioPlayer.java index 5e9d7fe..42a5159 100644 --- a/src/main/java/device/radioPlayer/RadioPlayer.java +++ b/src/main/java/device/radioPlayer/RadioPlayer.java @@ -158,16 +158,20 @@ public class RadioPlayer implements Device { @Override public String chooseItem(int itemNr) { - if (itemNr > savedPlaylist.size()) { - playedStation = savedPlaylist.get(savedPlaylist.size() - 1); - return ("Radio is playing station: 0" + savedPlaylist.size() + " " + this.playedStation + " from saved playlist"); - } else if (itemNr < 1) { - playedStation = savedPlaylist.get(0); - return ("Radio is playing station: 01 " + this.playedStation + " from saved playlist"); + if (regionPlaylist.contains(playedStation)) { + playedStation = regionPlaylist.get(itemNr - 1); + return ("Radio is playing station: 0" + (regionPlaylist.indexOf(playedStation) + 1) + " " + this.playedStation + " from regional playlist"); } else { - playedStation = savedPlaylist.get(itemNr - 1); - return ("Radio is playing station: 0" + (savedPlaylist.indexOf(playedStation) + 1) + " " + this.playedStation + " from saved playlist"); - + if (itemNr > savedPlaylist.size()) { + playedStation = savedPlaylist.get(savedPlaylist.size() - 1); + return ("Radio is playing station: 0" + savedPlaylist.size() + " " + this.playedStation + " from saved playlist"); + } else if (itemNr < 1) { + playedStation = savedPlaylist.get(0); + return ("Radio is playing station: 01 " + this.playedStation + " from saved playlist"); + } else { + playedStation = savedPlaylist.get(itemNr - 1); + return ("Radio is playing station: 0" + (savedPlaylist.indexOf(playedStation) + 1) + " " + this.playedStation + " from saved playlist"); + } } } diff --git a/src/test/java/device/radioPlayer/RadioPlayerTest.java b/src/test/java/device/radioPlayer/RadioPlayerTest.java index 6e6121c..db2b35c 100644 --- a/src/test/java/device/radioPlayer/RadioPlayerTest.java +++ b/src/test/java/device/radioPlayer/RadioPlayerTest.java @@ -187,11 +187,15 @@ class RadioPlayerTest { rp1.chooseItem(5); RadioPlayer rp2 = new RadioPlayer(); rp2.chooseItem(-1); + RadioPlayer rp3 = new RadioPlayer(); + rp3.changeRegion("BY"); + rp3.chooseItem(2); return Stream.of( Arguments.of("Test select station in saved playlist to play with nr isn`t bigger than playlist size", rp, "Teddy"), Arguments.of("Test select station in saved playlist to play with nr is bigger than playlist size. Last station in playlist gets played", rp1, "MegaHits"), - Arguments.of("Test select station in saved playlist to play with nr is lower than 0. First station in playlist gets played", rp2, "YouFM") + Arguments.of("Test select station in saved playlist to play with nr is lower than 0. First station in playlist gets played", rp2, "YouFM"), + Arguments.of("Test select station in regional playlist to play with nr isn`t bigger than playlist size", rp3, "Bayern 1") ); } From acfc2fef2b549e88cefb7ac26fcac6ad14ff8eba Mon Sep 17 00:00:00 2001 From: alpina0707 Date: Wed, 16 Feb 2022 19:05:22 +0100 Subject: [PATCH 05/11] added fifth test case for chooseItem() & and added productive code for RadioPlayer --- src/main/java/device/radioPlayer/RadioPlayer.java | 9 +++++++-- src/test/java/device/radioPlayer/RadioPlayerTest.java | 6 +++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/main/java/device/radioPlayer/RadioPlayer.java b/src/main/java/device/radioPlayer/RadioPlayer.java index 42a5159..ca25596 100644 --- a/src/main/java/device/radioPlayer/RadioPlayer.java +++ b/src/main/java/device/radioPlayer/RadioPlayer.java @@ -159,8 +159,13 @@ public class RadioPlayer implements Device { @Override public String chooseItem(int itemNr) { if (regionPlaylist.contains(playedStation)) { - playedStation = regionPlaylist.get(itemNr - 1); - return ("Radio is playing station: 0" + (regionPlaylist.indexOf(playedStation) + 1) + " " + this.playedStation + " from regional playlist"); + if (itemNr > regionPlaylist.size()) { + playedStation = regionPlaylist.get(regionPlaylist.size() - 1); + return ("Radio is playing station: 0" + regionPlaylist.size() + " " + this.playedStation + " from regional playlist"); + } else { + playedStation = regionPlaylist.get(itemNr - 1); + return ("Radio is playing station: 0" + (regionPlaylist.indexOf(playedStation) + 1) + " " + this.playedStation + " from regional playlist"); + } } else { if (itemNr > savedPlaylist.size()) { playedStation = savedPlaylist.get(savedPlaylist.size() - 1); diff --git a/src/test/java/device/radioPlayer/RadioPlayerTest.java b/src/test/java/device/radioPlayer/RadioPlayerTest.java index db2b35c..aa7417c 100644 --- a/src/test/java/device/radioPlayer/RadioPlayerTest.java +++ b/src/test/java/device/radioPlayer/RadioPlayerTest.java @@ -190,12 +190,16 @@ class RadioPlayerTest { RadioPlayer rp3 = new RadioPlayer(); rp3.changeRegion("BY"); rp3.chooseItem(2); + RadioPlayer rp4 = new RadioPlayer(); + rp4.changeRegion("BY"); + rp4.chooseItem(5); return Stream.of( Arguments.of("Test select station in saved playlist to play with nr isn`t bigger than playlist size", rp, "Teddy"), Arguments.of("Test select station in saved playlist to play with nr is bigger than playlist size. Last station in playlist gets played", rp1, "MegaHits"), Arguments.of("Test select station in saved playlist to play with nr is lower than 0. First station in playlist gets played", rp2, "YouFM"), - Arguments.of("Test select station in regional playlist to play with nr isn`t bigger than playlist size", rp3, "Bayern 1") + Arguments.of("Test select station in regional playlist to play with nr isn`t bigger than playlist size", rp3, "Bayern 1"), + Arguments.of("Test select station in regional playlist to play with nr is bigger than playlist size. Last station in playlist gets played", rp4, "Hit Radio N1") ); } From 419699e4bcff4bdb3d18aecdd45822a31046e271 Mon Sep 17 00:00:00 2001 From: alpina0707 Date: Wed, 16 Feb 2022 19:11:38 +0100 Subject: [PATCH 06/11] added six test case for chooseItem() & and added productive code for RadioPlayer --- src/main/java/device/radioPlayer/RadioPlayer.java | 3 +++ src/test/java/device/radioPlayer/RadioPlayerTest.java | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/java/device/radioPlayer/RadioPlayer.java b/src/main/java/device/radioPlayer/RadioPlayer.java index ca25596..849fb11 100644 --- a/src/main/java/device/radioPlayer/RadioPlayer.java +++ b/src/main/java/device/radioPlayer/RadioPlayer.java @@ -162,6 +162,9 @@ public class RadioPlayer implements Device { if (itemNr > regionPlaylist.size()) { playedStation = regionPlaylist.get(regionPlaylist.size() - 1); return ("Radio is playing station: 0" + regionPlaylist.size() + " " + this.playedStation + " from regional playlist"); + } else if (itemNr < 1) { + playedStation = regionPlaylist.get(0); + return ("Radio is playing station: 01 " + this.playedStation + " from regional playlist"); } else { playedStation = regionPlaylist.get(itemNr - 1); return ("Radio is playing station: 0" + (regionPlaylist.indexOf(playedStation) + 1) + " " + this.playedStation + " from regional playlist"); diff --git a/src/test/java/device/radioPlayer/RadioPlayerTest.java b/src/test/java/device/radioPlayer/RadioPlayerTest.java index aa7417c..0e8f008 100644 --- a/src/test/java/device/radioPlayer/RadioPlayerTest.java +++ b/src/test/java/device/radioPlayer/RadioPlayerTest.java @@ -193,13 +193,17 @@ class RadioPlayerTest { RadioPlayer rp4 = new RadioPlayer(); rp4.changeRegion("BY"); rp4.chooseItem(5); + RadioPlayer rp5 = new RadioPlayer(); + rp5.changeRegion("BY"); + rp5.chooseItem(-2); return Stream.of( Arguments.of("Test select station in saved playlist to play with nr isn`t bigger than playlist size", rp, "Teddy"), Arguments.of("Test select station in saved playlist to play with nr is bigger than playlist size. Last station in playlist gets played", rp1, "MegaHits"), Arguments.of("Test select station in saved playlist to play with nr is lower than 0. First station in playlist gets played", rp2, "YouFM"), Arguments.of("Test select station in regional playlist to play with nr isn`t bigger than playlist size", rp3, "Bayern 1"), - Arguments.of("Test select station in regional playlist to play with nr is bigger than playlist size. Last station in playlist gets played", rp4, "Hit Radio N1") + Arguments.of("Test select station in regional playlist to play with nr is bigger than playlist size. Last station in playlist gets played", rp4, "Hit Radio N1"), + Arguments.of("Test select station in regional playlist to play with nr is lower than 0. Last station in playlist gets played", rp5, "Antenne Bayern") ); } From d61ea260075e780a3eae25879f4a44ad28ef00c3 Mon Sep 17 00:00:00 2001 From: alpina0707 Date: Wed, 16 Feb 2022 19:54:41 +0100 Subject: [PATCH 07/11] added first test case for getItemList() & and added productive code for RadioPlayer --- src/main/java/device/radioPlayer/RadioPlayer.java | 2 +- .../java/device/radioPlayer/RadioPlayerTest.java | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main/java/device/radioPlayer/RadioPlayer.java b/src/main/java/device/radioPlayer/RadioPlayer.java index d7f35f1..1741dc6 100644 --- a/src/main/java/device/radioPlayer/RadioPlayer.java +++ b/src/main/java/device/radioPlayer/RadioPlayer.java @@ -185,7 +185,7 @@ public class RadioPlayer implements Device { @Override public String[] getItemList() { - return null; + return savedPlaylist.toArray(new String[0]); } @Override diff --git a/src/test/java/device/radioPlayer/RadioPlayerTest.java b/src/test/java/device/radioPlayer/RadioPlayerTest.java index 0e8f008..b991a7f 100644 --- a/src/test/java/device/radioPlayer/RadioPlayerTest.java +++ b/src/test/java/device/radioPlayer/RadioPlayerTest.java @@ -320,4 +320,18 @@ class RadioPlayerTest { Arguments.of("Test for change order in saved playlist with nr is than smaller than 0 at front of playlist", rp2, 0, "Teddy") ); } + @ParameterizedTest + @MethodSource("getItemListOptions") + void testGetItemList(String testName, RadioPlayer testRp, String[] expectedResult) { + String[] playList = testRp.getItemList(); + assertThat(playList).describedAs(testName).isEqualTo(expectedResult); + } + + static Stream getItemListOptions() { + RadioPlayer rp = new RadioPlayer(); + + return Stream.of( + Arguments.of("Test for return saved playlist", rp, rp.savedPlaylist.toArray(new String[0])) + ); + } } \ No newline at end of file From b7b79badda3d9c14f0fa7360b8256ec51fe3cde0 Mon Sep 17 00:00:00 2001 From: alpina0707 Date: Wed, 16 Feb 2022 20:09:42 +0100 Subject: [PATCH 08/11] added second test case for getItemList() & and added productive code for RadioPlayer --- src/main/java/device/radioPlayer/RadioPlayer.java | 5 ++++- .../java/device/radioPlayer/RadioPlayerTest.java | 12 ++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/main/java/device/radioPlayer/RadioPlayer.java b/src/main/java/device/radioPlayer/RadioPlayer.java index 1741dc6..5ef8556 100644 --- a/src/main/java/device/radioPlayer/RadioPlayer.java +++ b/src/main/java/device/radioPlayer/RadioPlayer.java @@ -185,7 +185,10 @@ public class RadioPlayer implements Device { @Override public String[] getItemList() { - return savedPlaylist.toArray(new String[0]); + if (regionPlaylist.contains(playedStation)) + return regionPlaylist.toArray(new String[0]); + else + return savedPlaylist.toArray(new String[0]); } @Override diff --git a/src/test/java/device/radioPlayer/RadioPlayerTest.java b/src/test/java/device/radioPlayer/RadioPlayerTest.java index b991a7f..4de54c2 100644 --- a/src/test/java/device/radioPlayer/RadioPlayerTest.java +++ b/src/test/java/device/radioPlayer/RadioPlayerTest.java @@ -320,18 +320,26 @@ class RadioPlayerTest { Arguments.of("Test for change order in saved playlist with nr is than smaller than 0 at front of playlist", rp2, 0, "Teddy") ); } + @ParameterizedTest @MethodSource("getItemListOptions") - void testGetItemList(String testName, RadioPlayer testRp, String[] expectedResult) { + void testGetItemList(String testName, RadioPlayer testRp, String testTyp, String[] expectedResult) { + if (testTyp.equals("region")) { + testRp.changeRegion("BY"); + } + String[] playList = testRp.getItemList(); assertThat(playList).describedAs(testName).isEqualTo(expectedResult); } static Stream getItemListOptions() { RadioPlayer rp = new RadioPlayer(); + RadioPlayer rp1 = new RadioPlayer(); + rp1.changeRegion("BY"); return Stream.of( - Arguments.of("Test for return saved playlist", rp, rp.savedPlaylist.toArray(new String[0])) + Arguments.of("Test for return saved playlist", rp, "saved", rp.savedPlaylist.toArray(new String[0])), + Arguments.of("Test for return regional playlist", rp1, "region", rp1.regionPlaylist.toArray(new String[0])) ); } } \ No newline at end of file From f8bcf0c62b1007777ad21ad29e880e220a4495ea Mon Sep 17 00:00:00 2001 From: alpina0707 Date: Wed, 16 Feb 2022 21:14:54 +0100 Subject: [PATCH 09/11] 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 10/11] 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 11/11] 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