From 57114df69ad1e8c2a80119ccfa340d21fae6c111 Mon Sep 17 00:00:00 2001 From: alpina0707 Date: Wed, 16 Feb 2022 21:59:48 +0100 Subject: [PATCH 1/8] added first test case for getInfoText() & and added productive code for RadioPlayer --- .../java/device/radioPlayer/RadioPlayer.java | 2 +- .../device/radioPlayer/RadioPlayerTest.java | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/main/java/device/radioPlayer/RadioPlayer.java b/src/main/java/device/radioPlayer/RadioPlayer.java index 2b91e3e..c319890 100644 --- a/src/main/java/device/radioPlayer/RadioPlayer.java +++ b/src/main/java/device/radioPlayer/RadioPlayer.java @@ -149,7 +149,7 @@ public class RadioPlayer implements Device { @Override public String getInfoText() { - return null; + return "InfoText"; } @Override diff --git a/src/test/java/device/radioPlayer/RadioPlayerTest.java b/src/test/java/device/radioPlayer/RadioPlayerTest.java index ac5eefc..ed7f3ac 100644 --- a/src/test/java/device/radioPlayer/RadioPlayerTest.java +++ b/src/test/java/device/radioPlayer/RadioPlayerTest.java @@ -1,6 +1,7 @@ package device.radioPlayer; +import org.assertj.core.util.Strings; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; @@ -373,4 +374,20 @@ class RadioPlayerTest { rp.unmute(); assertThat(rp.getVolume()).describedAs("Test if unmute is setting the saved volume").isEqualTo(rp.savedVolume); } + + @ParameterizedTest + @MethodSource("getInfoTextOptions") + void testGetInfoText(String testName, RadioPlayer testRp, boolean expectedResult) { + Boolean volume = Strings.isNullOrEmpty(testRp.getInfoText()); + + assertThat(volume).describedAs(testName).isEqualTo(expectedResult); + } + + static Stream getInfoTextOptions() { + RadioPlayer rp = new RadioPlayer(); + + return Stream.of( + Arguments.of("Test for getInfoText is not empty or null", rp, false) + ); + } } \ No newline at end of file From bc0ecd26756f5bdf63642060c9fc3dff2bba941b Mon Sep 17 00:00:00 2001 From: alpina0707 Date: Wed, 16 Feb 2022 22:06:59 +0100 Subject: [PATCH 2/8] added second test case for getInfoText() & and added productive code for RadioPlayer --- src/main/java/device/radioPlayer/RadioPlayer.java | 2 +- .../java/device/radioPlayer/RadioPlayerTest.java | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/java/device/radioPlayer/RadioPlayer.java b/src/main/java/device/radioPlayer/RadioPlayer.java index c319890..f7e39ff 100644 --- a/src/main/java/device/radioPlayer/RadioPlayer.java +++ b/src/main/java/device/radioPlayer/RadioPlayer.java @@ -149,7 +149,7 @@ public class RadioPlayer implements Device { @Override public String getInfoText() { - return "InfoText"; + return playedStation; } @Override diff --git a/src/test/java/device/radioPlayer/RadioPlayerTest.java b/src/test/java/device/radioPlayer/RadioPlayerTest.java index ed7f3ac..704f8e2 100644 --- a/src/test/java/device/radioPlayer/RadioPlayerTest.java +++ b/src/test/java/device/radioPlayer/RadioPlayerTest.java @@ -377,17 +377,21 @@ class RadioPlayerTest { @ParameterizedTest @MethodSource("getInfoTextOptions") - void testGetInfoText(String testName, RadioPlayer testRp, boolean expectedResult) { - Boolean volume = Strings.isNullOrEmpty(testRp.getInfoText()); + void testGetInfoText(String testName, String testTyp, RadioPlayer testRp, boolean expectedResult) { + Boolean bool; + if(testTyp.equals("null")) bool = Strings.isNullOrEmpty(testRp.getInfoText()); + else bool = testRp.getInfoText().contains(testRp.playedStation); - assertThat(volume).describedAs(testName).isEqualTo(expectedResult); + assertThat(bool).describedAs(testName).isEqualTo(expectedResult); } static Stream getInfoTextOptions() { RadioPlayer rp = new RadioPlayer(); + RadioPlayer rp1 = new RadioPlayer(); return Stream.of( - Arguments.of("Test for getInfoText is not empty or null", rp, false) + Arguments.of("Test for getInfoText is not empty or null", "null", rp, false), + Arguments.of("Test for getInfoText contains played station", "station", rp1, true) ); } } \ No newline at end of file From 9d20decf08819d7048f07e52cb418f03f36869a6 Mon Sep 17 00:00:00 2001 From: alpina0707 Date: Wed, 16 Feb 2022 22:28:57 +0100 Subject: [PATCH 3/8] added third test case for getInfoText() & and added productive code for RadioPlayer --- src/main/java/device/radioPlayer/RadioPlayer.java | 4 +++- src/test/java/device/radioPlayer/RadioPlayerTest.java | 10 +++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main/java/device/radioPlayer/RadioPlayer.java b/src/main/java/device/radioPlayer/RadioPlayer.java index f7e39ff..2129b6b 100644 --- a/src/main/java/device/radioPlayer/RadioPlayer.java +++ b/src/main/java/device/radioPlayer/RadioPlayer.java @@ -149,7 +149,9 @@ public class RadioPlayer implements Device { @Override public String getInfoText() { - return playedStation; + String infoText = playedStation; + if(regionPlaylist.contains(playedStation)) return ("Regional playlist " + infoText); + else return infoText; } @Override diff --git a/src/test/java/device/radioPlayer/RadioPlayerTest.java b/src/test/java/device/radioPlayer/RadioPlayerTest.java index 704f8e2..f127ab9 100644 --- a/src/test/java/device/radioPlayer/RadioPlayerTest.java +++ b/src/test/java/device/radioPlayer/RadioPlayerTest.java @@ -378,9 +378,10 @@ class RadioPlayerTest { @ParameterizedTest @MethodSource("getInfoTextOptions") void testGetInfoText(String testName, String testTyp, RadioPlayer testRp, boolean expectedResult) { - Boolean bool; + Boolean bool = null; if(testTyp.equals("null")) bool = Strings.isNullOrEmpty(testRp.getInfoText()); - else bool = testRp.getInfoText().contains(testRp.playedStation); + else if(testTyp.contains("station")) bool = testRp.getInfoText().contains(testRp.playedStation); + else if(testTyp.contains("region")) bool = testRp.getInfoText().contains("Regional playlist"); assertThat(bool).describedAs(testName).isEqualTo(expectedResult); } @@ -388,10 +389,13 @@ class RadioPlayerTest { static Stream getInfoTextOptions() { RadioPlayer rp = new RadioPlayer(); RadioPlayer rp1 = new RadioPlayer(); + RadioPlayer rp2 = new RadioPlayer(); + rp2.changeRegion("BY"); return Stream.of( Arguments.of("Test for getInfoText is not empty or null", "null", rp, false), - Arguments.of("Test for getInfoText contains played station", "station", rp1, true) + Arguments.of("Test for getInfoText contains played station", "station", rp1, true), + Arguments.of("Test for getInfoText contains regional playlist if played station is in it", "region", rp2, true) ); } } \ No newline at end of file From f754c0a5ce72309d1fcc140db1d0fc1284aeb0bb Mon Sep 17 00:00:00 2001 From: alpina0707 Date: Wed, 16 Feb 2022 22:32:58 +0100 Subject: [PATCH 4/8] added fourth test case for getInfoText() & and added productive code for RadioPlayer --- src/main/java/device/radioPlayer/RadioPlayer.java | 2 +- src/test/java/device/radioPlayer/RadioPlayerTest.java | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/device/radioPlayer/RadioPlayer.java b/src/main/java/device/radioPlayer/RadioPlayer.java index 2129b6b..44621be 100644 --- a/src/main/java/device/radioPlayer/RadioPlayer.java +++ b/src/main/java/device/radioPlayer/RadioPlayer.java @@ -151,7 +151,7 @@ public class RadioPlayer implements Device { public String getInfoText() { String infoText = playedStation; if(regionPlaylist.contains(playedStation)) return ("Regional playlist " + infoText); - else return infoText; + else return ("Saved playlist " + infoText); } @Override diff --git a/src/test/java/device/radioPlayer/RadioPlayerTest.java b/src/test/java/device/radioPlayer/RadioPlayerTest.java index f127ab9..f49390e 100644 --- a/src/test/java/device/radioPlayer/RadioPlayerTest.java +++ b/src/test/java/device/radioPlayer/RadioPlayerTest.java @@ -382,6 +382,7 @@ class RadioPlayerTest { if(testTyp.equals("null")) bool = Strings.isNullOrEmpty(testRp.getInfoText()); else if(testTyp.contains("station")) bool = testRp.getInfoText().contains(testRp.playedStation); else if(testTyp.contains("region")) bool = testRp.getInfoText().contains("Regional playlist"); + else if(testTyp.contains("saved")) bool = testRp.getInfoText().contains("Saved playlist"); assertThat(bool).describedAs(testName).isEqualTo(expectedResult); } @@ -391,11 +392,13 @@ class RadioPlayerTest { RadioPlayer rp1 = new RadioPlayer(); RadioPlayer rp2 = new RadioPlayer(); rp2.changeRegion("BY"); + RadioPlayer rp3 = new RadioPlayer(); return Stream.of( Arguments.of("Test for getInfoText is not empty or null", "null", rp, false), Arguments.of("Test for getInfoText contains played station", "station", rp1, true), - Arguments.of("Test for getInfoText contains regional playlist if played station is in it", "region", rp2, true) + Arguments.of("Test for getInfoText contains regional playlist if played station is in it", "region", rp2, true), + Arguments.of("Test for getInfoText contains saved playlist if played station is in it", "saved", rp3, true) ); } } \ No newline at end of file From dd88b2967c631ec5753c258c4ee61a77bc298a41 Mon Sep 17 00:00:00 2001 From: alpina0707 Date: Wed, 16 Feb 2022 22:42:52 +0100 Subject: [PATCH 5/8] added fifth test case for getInfoText() & and added productive code for RadioPlayer --- src/main/java/device/radioPlayer/RadioPlayer.java | 4 ++-- src/test/java/device/radioPlayer/RadioPlayerTest.java | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/java/device/radioPlayer/RadioPlayer.java b/src/main/java/device/radioPlayer/RadioPlayer.java index 44621be..c576db2 100644 --- a/src/main/java/device/radioPlayer/RadioPlayer.java +++ b/src/main/java/device/radioPlayer/RadioPlayer.java @@ -150,8 +150,8 @@ public class RadioPlayer implements Device { @Override public String getInfoText() { String infoText = playedStation; - if(regionPlaylist.contains(playedStation)) return ("Regional playlist " + infoText); - else return ("Saved playlist " + infoText); + if(regionPlaylist.contains(playedStation)) return ("Regional playlist: " + infoText); + else return ("Saved playlist: "+ (savedPlaylist.indexOf(playedStation) + 1) + infoText); } @Override diff --git a/src/test/java/device/radioPlayer/RadioPlayerTest.java b/src/test/java/device/radioPlayer/RadioPlayerTest.java index f49390e..fe6b776 100644 --- a/src/test/java/device/radioPlayer/RadioPlayerTest.java +++ b/src/test/java/device/radioPlayer/RadioPlayerTest.java @@ -383,6 +383,7 @@ class RadioPlayerTest { else if(testTyp.contains("station")) bool = testRp.getInfoText().contains(testRp.playedStation); else if(testTyp.contains("region")) bool = testRp.getInfoText().contains("Regional playlist"); else if(testTyp.contains("saved")) bool = testRp.getInfoText().contains("Saved playlist"); + else if(testTyp.contains("savedNum")) bool = testRp.getInfoText().contains(("0") + testRp.savedPlaylist.indexOf(testRp.playedStation) + 1); assertThat(bool).describedAs(testName).isEqualTo(expectedResult); } @@ -393,12 +394,15 @@ class RadioPlayerTest { RadioPlayer rp2 = new RadioPlayer(); rp2.changeRegion("BY"); RadioPlayer rp3 = new RadioPlayer(); + RadioPlayer rp4 = new RadioPlayer(); + rp4.next(); return Stream.of( Arguments.of("Test for getInfoText is not empty or null", "null", rp, false), Arguments.of("Test for getInfoText contains played station", "station", rp1, true), Arguments.of("Test for getInfoText contains regional playlist if played station is in it", "region", rp2, true), - Arguments.of("Test for getInfoText contains saved playlist if played station is in it", "saved", rp3, true) + Arguments.of("Test for getInfoText contains saved playlist if played station is in it", "saved", rp3, true), + Arguments.of("Test for getInfoText contains station number in saved playlist", "savedNum", rp4, true) ); } } \ No newline at end of file From e6541cf2b9ab86082246378827a9c37ce4efa04d Mon Sep 17 00:00:00 2001 From: alpina0707 Date: Wed, 16 Feb 2022 22:50:40 +0100 Subject: [PATCH 6/8] added six test case for getInfoText() & and added productive code for RadioPlayer --- src/main/java/device/radioPlayer/RadioPlayer.java | 4 ++-- src/test/java/device/radioPlayer/RadioPlayerTest.java | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/java/device/radioPlayer/RadioPlayer.java b/src/main/java/device/radioPlayer/RadioPlayer.java index c576db2..badaa85 100644 --- a/src/main/java/device/radioPlayer/RadioPlayer.java +++ b/src/main/java/device/radioPlayer/RadioPlayer.java @@ -150,8 +150,8 @@ public class RadioPlayer implements Device { @Override public String getInfoText() { String infoText = playedStation; - if(regionPlaylist.contains(playedStation)) return ("Regional playlist: " + infoText); - else return ("Saved playlist: "+ (savedPlaylist.indexOf(playedStation) + 1) + infoText); + if(regionPlaylist.contains(playedStation)) return ("Regional playlist: " + (regionPlaylist.indexOf(playedStation) + 1) + infoText); + else return ("Saved playlist: " + (savedPlaylist.indexOf(playedStation) + 1) + infoText); } @Override diff --git a/src/test/java/device/radioPlayer/RadioPlayerTest.java b/src/test/java/device/radioPlayer/RadioPlayerTest.java index fe6b776..9552318 100644 --- a/src/test/java/device/radioPlayer/RadioPlayerTest.java +++ b/src/test/java/device/radioPlayer/RadioPlayerTest.java @@ -384,6 +384,7 @@ class RadioPlayerTest { else if(testTyp.contains("region")) bool = testRp.getInfoText().contains("Regional playlist"); else if(testTyp.contains("saved")) bool = testRp.getInfoText().contains("Saved playlist"); else if(testTyp.contains("savedNum")) bool = testRp.getInfoText().contains(("0") + testRp.savedPlaylist.indexOf(testRp.playedStation) + 1); + else if(testTyp.contains("regionNum")) bool = testRp.getInfoText().contains(("0") + testRp.regionPlaylist.indexOf(testRp.playedStation) + 1); assertThat(bool).describedAs(testName).isEqualTo(expectedResult); } @@ -396,13 +397,17 @@ class RadioPlayerTest { RadioPlayer rp3 = new RadioPlayer(); RadioPlayer rp4 = new RadioPlayer(); rp4.next(); + RadioPlayer rp5 = new RadioPlayer(); + rp5.changeRegion("HE"); + rp5.next(); return Stream.of( Arguments.of("Test for getInfoText is not empty or null", "null", rp, false), Arguments.of("Test for getInfoText contains played station", "station", rp1, true), Arguments.of("Test for getInfoText contains regional playlist if played station is in it", "region", rp2, true), Arguments.of("Test for getInfoText contains saved playlist if played station is in it", "saved", rp3, true), - Arguments.of("Test for getInfoText contains station number in saved playlist", "savedNum", rp4, true) + Arguments.of("Test for getInfoText contains station number in saved playlist", "savedNum", rp4, true), + Arguments.of("Test for getInfoText contains station number in regional playlist", "regionNum", rp5, true) ); } } \ No newline at end of file From 0ff584dc0ae67ee01d0cb3c91fd07dfe6b2bd9bf Mon Sep 17 00:00:00 2001 From: alpina0707 Date: Thu, 17 Feb 2022 00:05:33 +0100 Subject: [PATCH 7/8] added sevens test case for getInfoText() & and added productive code for RadioPlayer --- src/main/java/device/radioPlayer/RadioPlayer.java | 4 ++++ src/test/java/device/radioPlayer/RadioPlayerTest.java | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/device/radioPlayer/RadioPlayer.java b/src/main/java/device/radioPlayer/RadioPlayer.java index badaa85..22f6c67 100644 --- a/src/main/java/device/radioPlayer/RadioPlayer.java +++ b/src/main/java/device/radioPlayer/RadioPlayer.java @@ -149,6 +149,10 @@ public class RadioPlayer implements Device { @Override public String getInfoText() { + return (buildInfoText() + "\n Now playing: " + showStationInfo()); + } + + private String buildInfoText() { String infoText = playedStation; if(regionPlaylist.contains(playedStation)) return ("Regional playlist: " + (regionPlaylist.indexOf(playedStation) + 1) + infoText); else return ("Saved playlist: " + (savedPlaylist.indexOf(playedStation) + 1) + infoText); diff --git a/src/test/java/device/radioPlayer/RadioPlayerTest.java b/src/test/java/device/radioPlayer/RadioPlayerTest.java index 9552318..739a2ad 100644 --- a/src/test/java/device/radioPlayer/RadioPlayerTest.java +++ b/src/test/java/device/radioPlayer/RadioPlayerTest.java @@ -385,6 +385,7 @@ class RadioPlayerTest { else if(testTyp.contains("saved")) bool = testRp.getInfoText().contains("Saved playlist"); else if(testTyp.contains("savedNum")) bool = testRp.getInfoText().contains(("0") + testRp.savedPlaylist.indexOf(testRp.playedStation) + 1); else if(testTyp.contains("regionNum")) bool = testRp.getInfoText().contains(("0") + testRp.regionPlaylist.indexOf(testRp.playedStation) + 1); + else if(testTyp.contains("stationInfo")) bool = testRp.getInfoText().contains("Now playing"); assertThat(bool).describedAs(testName).isEqualTo(expectedResult); } @@ -400,6 +401,8 @@ class RadioPlayerTest { RadioPlayer rp5 = new RadioPlayer(); rp5.changeRegion("HE"); rp5.next(); + RadioPlayer rp6 = new RadioPlayer(); + rp6.changeRegion("BY"); return Stream.of( Arguments.of("Test for getInfoText is not empty or null", "null", rp, false), @@ -407,7 +410,8 @@ class RadioPlayerTest { Arguments.of("Test for getInfoText contains regional playlist if played station is in it", "region", rp2, true), Arguments.of("Test for getInfoText contains saved playlist if played station is in it", "saved", rp3, true), Arguments.of("Test for getInfoText contains station number in saved playlist", "savedNum", rp4, true), - Arguments.of("Test for getInfoText contains station number in regional playlist", "regionNum", rp5, true) + Arguments.of("Test for getInfoText contains station number in regional playlist", "regionNum", rp5, true), + Arguments.of("Test for getInfoText contains station info if station has one", "stationInfo", rp6, true) ); } } \ No newline at end of file From 561d5f6bc27a64088b1bc2d52587508230337ab3 Mon Sep 17 00:00:00 2001 From: alpina0707 Date: Thu, 17 Feb 2022 00:10:33 +0100 Subject: [PATCH 8/8] added eighth test case for getInfoText() & and added productive code for RadioPlayer --- src/main/java/device/radioPlayer/RadioPlayer.java | 1 + src/test/java/device/radioPlayer/RadioPlayerTest.java | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/device/radioPlayer/RadioPlayer.java b/src/main/java/device/radioPlayer/RadioPlayer.java index 22f6c67..7dcc37a 100644 --- a/src/main/java/device/radioPlayer/RadioPlayer.java +++ b/src/main/java/device/radioPlayer/RadioPlayer.java @@ -149,6 +149,7 @@ public class RadioPlayer implements Device { @Override public String getInfoText() { + if(showStationInfo().equals("")) return buildInfoText(); return (buildInfoText() + "\n Now playing: " + showStationInfo()); } diff --git a/src/test/java/device/radioPlayer/RadioPlayerTest.java b/src/test/java/device/radioPlayer/RadioPlayerTest.java index 739a2ad..7e2f5d0 100644 --- a/src/test/java/device/radioPlayer/RadioPlayerTest.java +++ b/src/test/java/device/radioPlayer/RadioPlayerTest.java @@ -378,7 +378,7 @@ class RadioPlayerTest { @ParameterizedTest @MethodSource("getInfoTextOptions") void testGetInfoText(String testName, String testTyp, RadioPlayer testRp, boolean expectedResult) { - Boolean bool = null; + Boolean bool; if(testTyp.equals("null")) bool = Strings.isNullOrEmpty(testRp.getInfoText()); else if(testTyp.contains("station")) bool = testRp.getInfoText().contains(testRp.playedStation); else if(testTyp.contains("region")) bool = testRp.getInfoText().contains("Regional playlist"); @@ -386,6 +386,7 @@ class RadioPlayerTest { else if(testTyp.contains("savedNum")) bool = testRp.getInfoText().contains(("0") + testRp.savedPlaylist.indexOf(testRp.playedStation) + 1); else if(testTyp.contains("regionNum")) bool = testRp.getInfoText().contains(("0") + testRp.regionPlaylist.indexOf(testRp.playedStation) + 1); else if(testTyp.contains("stationInfo")) bool = testRp.getInfoText().contains("Now playing"); + else bool = testRp.getInfoText().contains("Now playing"); assertThat(bool).describedAs(testName).isEqualTo(expectedResult); } @@ -403,6 +404,8 @@ class RadioPlayerTest { rp5.next(); RadioPlayer rp6 = new RadioPlayer(); rp6.changeRegion("BY"); + RadioPlayer rp7 = new RadioPlayer(); + rp7.next(); return Stream.of( Arguments.of("Test for getInfoText is not empty or null", "null", rp, false), @@ -411,7 +414,8 @@ class RadioPlayerTest { Arguments.of("Test for getInfoText contains saved playlist if played station is in it", "saved", rp3, true), Arguments.of("Test for getInfoText contains station number in saved playlist", "savedNum", rp4, true), Arguments.of("Test for getInfoText contains station number in regional playlist", "regionNum", rp5, true), - Arguments.of("Test for getInfoText contains station info if station has one", "stationInfo", rp6, true) + Arguments.of("Test for getInfoText contains station info if station has one", "stationInfo", rp6, true), + Arguments.of("Test for getInfoText not contains station info if station not has one", "noStationInfo", rp7, false) ); } } \ No newline at end of file