From e5b9f46ce7b8c864340b39d4a0127c5e8df4ebe9 Mon Sep 17 00:00:00 2001 From: alpina0707 Date: Wed, 16 Feb 2022 17:53:53 +0100 Subject: [PATCH 1/6] 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 2/6] 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 3/6] 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 4/6] 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 5/6] 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 6/6] 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") ); }