From d38a65b4909dbd6a6d53abc5fe5554e3622dffa9 Mon Sep 17 00:00:00 2001 From: alpina0707 Date: Mon, 14 Feb 2022 21:22:05 +0100 Subject: [PATCH 1/4] added saveStation() and first test for adding station to savedPlaylist --- .../java/device/radioPlayer/RadioPlayer.java | 110 +++++++++--------- .../device/radioPlayer/RadioPlayerTest.java | 58 +++++---- 2 files changed, 93 insertions(+), 75 deletions(-) diff --git a/src/main/java/device/radioPlayer/RadioPlayer.java b/src/main/java/device/radioPlayer/RadioPlayer.java index 927fff4..479463f 100644 --- a/src/main/java/device/radioPlayer/RadioPlayer.java +++ b/src/main/java/device/radioPlayer/RadioPlayer.java @@ -11,18 +11,21 @@ public class RadioPlayer implements Device { public RadioPlayer() { super(); - Playlist.add("YouFM"); - Playlist.add("Teddy"); - Playlist.add("MegaHits"); - playTrack=Playlist.get(0); + savedPlaylist.add("YouFM"); + savedPlaylist.add("Teddy"); + savedPlaylist.add("MegaHits"); + playedStation = savedPlaylist.get(0); } - ArrayList Playlist=new ArrayList(); + ArrayList savedPlaylist = new ArrayList(); + ArrayList regionPlaylist = new ArrayList(); LocalDateTime now = LocalDateTime.now(); int hour = now.getHour(); + int Lautstaerke = 0; + String playedStation = ""; public String getYouFMInfoByTime(int x) { - if(x >= 5 && x <10 ) return YouFMInfo[0]; + if (x >= 5 && x < 10) return YouFMInfo[0]; else if (x >= 10 && x < 14) return YouFMInfo[1]; else if (x >= 14 && x < 18) return YouFMInfo[2]; else if (x >= 18 && x < 20) return YouFMInfo[3]; @@ -34,7 +37,7 @@ public class RadioPlayer implements Device { String[] YouFMInfo = {"YOUFM Good Morning Show", "YOUFM Worktime", "YOUFM am Nachmittag", "YOUFM am Abend", "YOUFM Wir feiern euch", "YOUFM Deutschrap ideal", "YOUFM Junge Nacht der ARD"}; public String getBR3InfoByTime(int x) { - if(x >= 5 && x <9) return BR3Info[0]; + if (x >= 5 && x < 9) return BR3Info[0]; else if (x >= 9 && x < 12) return BR3Info[1]; else if (x == 12) return BR3Info[2]; else if (x >= 13 && x < 16) return BR3Info[3]; @@ -44,73 +47,66 @@ public class RadioPlayer implements Device { else return BR3Info[7]; } - String[] BR3Info = {"Sebastian Winkler und die Frühaufdreher", "BAYERN 3 - und DU mittendrin!", "Update", "Hits, Hits, Hits für euren Nachmittag", "Die Zwei für euren Feierabend", "Was geht?!", "Matuschke - der etwas andere Abend","Die Nacht"}; + String[] BR3Info = {"Sebastian Winkler und die Frühaufdreher", "BAYERN 3 - und DU mittendrin!", "Update", "Hits, Hits, Hits für euren Nachmittag", "Die Zwei für euren Feierabend", "Was geht?!", "Matuschke - der etwas andere Abend", "Die Nacht"}; public String getAntenneBYInfoByTime(int x) { - if(x >= 5 && x <9) return AntenneBYInfo[0]; + if (x >= 5 && x < 9) return AntenneBYInfo[0]; else if (x >= 9 && x < 12) return AntenneBYInfo[1]; else if (x >= 12 && x < 15) return AntenneBYInfo[2]; else if (x >= 15 && x < 19) return AntenneBYInfo[3]; else return AntenneBYInfo[4]; } - String[] AntenneBYInfo = {"ANTENNE BAYERN Guten Morgen Bayern", "ANTENNE BAYERN bei der Arbeit", "ANTENNE BAYERN am Nachmittag", "ANTENNE BAYERN am Abend", "ANTENNE BAYERN Hit-Nacht"}; - + String[] AntenneBYInfo = {"ANTENNE BAYERN Guten Morgen Bayern", "ANTENNE BAYERN bei der Arbeit", "ANTENNE BAYERN am Nachmittag", "ANTENNE BAYERN am Abend", "ANTENNE BAYERN Hit-Nacht"}; - int Lautstaerke = 0; - String playTrack=""; public void setLautstaerke(int lautstaerke) { Lautstaerke = lautstaerke; } - public void changeRegion(String region){ + public void changeRegion(String region) { switch (region) { case "BY": - Playlist.clear(); - Playlist.add("Antenne Bayern"); - Playlist.add("Bayern 1"); - Playlist.add("Bayern 3"); - Playlist.add("Hit Radio N1"); - playTrack=Playlist.get(0); + regionPlaylist.clear(); + regionPlaylist.add("Antenne Bayern"); + regionPlaylist.add("Bayern 1"); + regionPlaylist.add("Bayern 3"); + regionPlaylist.add("Hit Radio N1"); + playedStation = regionPlaylist.get(0); break; case "HE": - Playlist.clear(); - Playlist.add("Hit Radio FFH"); - Playlist.add("HR 1"); - Playlist.add("HR 3"); - Playlist.add("YouFM"); - playTrack=Playlist.get(0); + regionPlaylist.clear(); + regionPlaylist.add("Hit Radio FFH"); + regionPlaylist.add("HR 1"); + regionPlaylist.add("HR 3"); + regionPlaylist.add("YouFM"); + playedStation = regionPlaylist.get(0); break; case "BW": - Playlist.clear(); - Playlist.add("DASDING"); - Playlist.add("SWR 1"); - Playlist.add("SWR 3"); - Playlist.add("sunshine live"); - playTrack=Playlist.get(0); - break; - default: - Playlist.clear(); - Playlist.add("YouFM"); - Playlist.add("Teddy"); - Playlist.add("MegaHits"); - playTrack=Playlist.get(0); + regionPlaylist.clear(); + regionPlaylist.add("DASDING"); + regionPlaylist.add("SWR 1"); + regionPlaylist.add("SWR 3"); + regionPlaylist.add("sunshine live"); + playedStation = regionPlaylist.get(0); break; } } @Override public void louder() { - if(Lautstaerke < 100){Lautstaerke+=1;} - else Lautstaerke = 100; + if (Lautstaerke < 100) { + Lautstaerke += 1; + } else Lautstaerke = 100; } @Override public void quieter() { - if(Lautstaerke > 0){Lautstaerke-=1;} - else Lautstaerke = 0; + if (Lautstaerke > 0) { + Lautstaerke -= 1; + } else Lautstaerke = 0; } + @Override public int getVolume() { return Lautstaerke; @@ -118,17 +114,19 @@ public class RadioPlayer implements Device { @Override public void next() { - int currentIndex=Playlist.indexOf(playTrack); - int nextIndex=(currentIndex+1)%Playlist.size(); - playTrack=Playlist.get(nextIndex); + int currentIndex = savedPlaylist.indexOf(playedStation); + int nextIndex = (currentIndex + 1) % savedPlaylist.size(); + playedStation = savedPlaylist.get(nextIndex); } @Override public void prev() { - int currentIndex=Playlist.indexOf(playTrack); - int nextIndex=Playlist.size()-1; - if(currentIndex!=0){nextIndex=(currentIndex-1);} - playTrack=Playlist.get(nextIndex); + int currentIndex = savedPlaylist.indexOf(playedStation); + int nextIndex = savedPlaylist.size() - 1; + if (currentIndex != 0) { + nextIndex = (currentIndex - 1); + } + playedStation = savedPlaylist.get(nextIndex); } @Override @@ -149,20 +147,26 @@ public class RadioPlayer implements Device { @Override public String play() { - return ("Radio is playing station: 0"+(Playlist.indexOf(playTrack)+1)+ " "+this.playTrack); + return ("Radio is playing station: 0" + (savedPlaylist.indexOf(playedStation) + 1) + " " + this.playedStation); } public String showStationInfo() { - switch (playTrack) { + switch (playedStation) { case "Antenne Bayern": return getAntenneBYInfoByTime(hour); case "YouFM": return getYouFMInfoByTime(hour); case "Bayern 3": return getBR3InfoByTime(hour); - default: return ""; + default: + return ""; } } + + public String saveStation() { + savedPlaylist.add(playedStation); + return ""; + } } diff --git a/src/test/java/device/radioPlayer/RadioPlayerTest.java b/src/test/java/device/radioPlayer/RadioPlayerTest.java index 0d11d3a..b880afa 100644 --- a/src/test/java/device/radioPlayer/RadioPlayerTest.java +++ b/src/test/java/device/radioPlayer/RadioPlayerTest.java @@ -1,8 +1,6 @@ package device.radioPlayer; -import device.radioPlayer.RadioPlayer; -import device.usbPlayer.UsbPlayer; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; @@ -15,7 +13,6 @@ import static org.assertj.core.api.Assertions.assertThat; class RadioPlayerTest { - @ParameterizedTest @MethodSource("quieterLouderOptions") void quieterLouderTest(String testName, RadioPlayer testRp, int expectedResult) { @@ -47,7 +44,7 @@ class RadioPlayerTest { @ParameterizedTest @MethodSource("changeRegionOptions") void changeRegionTest(String testName, RadioPlayer testRp, String expectedResult) { - String station = testRp.playTrack; + String station = testRp.playedStation; assertThat(station).describedAs(testName).isEqualTo(expectedResult); } @@ -70,9 +67,9 @@ class RadioPlayerTest { @ParameterizedTest @MethodSource("prevNextOptions") void prevNextTest(String testName, RadioPlayer testRp, String expectedResult) { - String station = testRp.playTrack; + String station = testRp.playedStation; assertThat(station).describedAs(testName).isEqualTo(expectedResult); -} + } static Stream prevNextOptions() { RadioPlayer rp1 = new RadioPlayer(); @@ -151,26 +148,26 @@ class RadioPlayerTest { ); } -/* + /* - @Test - void getInfoText() { - } + @Test + void getInfoText() { + } - @Test - void getOptions() { - } + @Test + void getOptions() { + } - @Test - void chooseOption() { + @Test + void chooseOption() { + } + */ + @ParameterizedTest + @MethodSource("testPlayOptions") + void testPlay(String testName, RadioPlayer testRp, String expectedResult) { + String playedStation = testRp.play(); + assertThat(playedStation).describedAs(testName).isEqualTo(expectedResult); } -*/ -@ParameterizedTest -@MethodSource("testPlayOptions") -void testPlay(String testName, RadioPlayer testRp, String expectedResult) { - String playedStation = testRp.play(); - assertThat(playedStation).describedAs(testName).isEqualTo(expectedResult); -} static Stream testPlayOptions() { RadioPlayer rp1 = new RadioPlayer(); @@ -180,4 +177,21 @@ void testPlay(String testName, RadioPlayer testRp, String expectedResult) { ); } + @ParameterizedTest + @MethodSource("saveStationOptions") + void testSaveStation(String testName, RadioPlayer testRp, String expectedResult) { + String savedStation = testRp.savedPlaylist.get(testRp.savedPlaylist.size() - 1); + assertThat(savedStation).describedAs(testName).isEqualTo(expectedResult); + } + + static Stream saveStationOptions() { + RadioPlayer rp1 = new RadioPlayer(); + rp1.changeRegion("BY"); + rp1.saveStation(); + + return Stream.of( + Arguments.of("Test for saving station in saved playlist", rp1, "Antenne Bayern") + ); + } + } \ No newline at end of file From f99a208c8ee9180f5a2c3fce3d0df3ecea76bd47 Mon Sep 17 00:00:00 2001 From: alpina0707 Date: Mon, 14 Feb 2022 21:35:42 +0100 Subject: [PATCH 2/4] added new test case for next() & changed next() to work with regional and saved stations --- src/main/java/device/radioPlayer/RadioPlayer.java | 12 +++++++++--- .../java/device/radioPlayer/RadioPlayerTest.java | 10 +++++++--- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/main/java/device/radioPlayer/RadioPlayer.java b/src/main/java/device/radioPlayer/RadioPlayer.java index 479463f..898cea0 100644 --- a/src/main/java/device/radioPlayer/RadioPlayer.java +++ b/src/main/java/device/radioPlayer/RadioPlayer.java @@ -114,9 +114,15 @@ public class RadioPlayer implements Device { @Override public void next() { - int currentIndex = savedPlaylist.indexOf(playedStation); - int nextIndex = (currentIndex + 1) % savedPlaylist.size(); - playedStation = savedPlaylist.get(nextIndex); + if (regionPlaylist.contains(playedStation)){ + int currentIndex = regionPlaylist.indexOf(playedStation); + int nextIndex = (currentIndex + 1) % regionPlaylist.size(); + playedStation = regionPlaylist.get(nextIndex); + } else { + int currentIndex = savedPlaylist.indexOf(playedStation); + int nextIndex = (currentIndex + 1) % savedPlaylist.size(); + playedStation = savedPlaylist.get(nextIndex); + } } @Override diff --git a/src/test/java/device/radioPlayer/RadioPlayerTest.java b/src/test/java/device/radioPlayer/RadioPlayerTest.java index b880afa..6dc3db6 100644 --- a/src/test/java/device/radioPlayer/RadioPlayerTest.java +++ b/src/test/java/device/radioPlayer/RadioPlayerTest.java @@ -75,14 +75,18 @@ class RadioPlayerTest { RadioPlayer rp1 = new RadioPlayer(); RadioPlayer rp2 = new RadioPlayer(); RadioPlayer rp3 = new RadioPlayer(); + RadioPlayer rp4 = new RadioPlayer(); rp1.next(); rp2.next(); rp2.prev(); rp3.prev(); + rp4.changeRegion("BY"); + rp4.next(); return Stream.of( - Arguments.of("Next Station Test", rp1, "Teddy"), - Arguments.of("Prev Station Test", rp2, "YouFM"), - Arguments.of("Prev works on first Station ", rp3, "MegaHits") + Arguments.of("Next Station Test for saved Stations", rp1, "Teddy"), + Arguments.of("Prev Station Test for saved Stations", rp2, "YouFM"), + Arguments.of("Prev works on first Station for saved Stations", rp3, "MegaHits"), + Arguments.of("changed Region and going to next station", rp4, "Bayern 1") ); } From 74fa5f4bb6e58e5fb312d97159a832c3bd88cd09 Mon Sep 17 00:00:00 2001 From: alpina0707 Date: Mon, 14 Feb 2022 21:49:02 +0100 Subject: [PATCH 3/4] added new test case for prev() & changed prev() to work with regional and saved stations --- .../java/device/radioPlayer/RadioPlayer.java | 21 ++++++++++++++----- .../device/radioPlayer/RadioPlayerTest.java | 6 +++++- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/main/java/device/radioPlayer/RadioPlayer.java b/src/main/java/device/radioPlayer/RadioPlayer.java index 898cea0..6f68676 100644 --- a/src/main/java/device/radioPlayer/RadioPlayer.java +++ b/src/main/java/device/radioPlayer/RadioPlayer.java @@ -127,12 +127,23 @@ public class RadioPlayer implements Device { @Override public void prev() { - int currentIndex = savedPlaylist.indexOf(playedStation); - int nextIndex = savedPlaylist.size() - 1; - if (currentIndex != 0) { - nextIndex = (currentIndex - 1); + if (regionPlaylist.contains(playedStation)) { + int currentIndex = regionPlaylist.indexOf(playedStation); + int nextIndex = regionPlaylist.size() - 1; + if (currentIndex != 0) { + nextIndex = (currentIndex - 1); + } + playedStation = regionPlaylist.get(nextIndex); + } else { + { + int currentIndex = savedPlaylist.indexOf(playedStation); + int nextIndex = savedPlaylist.size() - 1; + if (currentIndex != 0) { + nextIndex = (currentIndex - 1); + } + playedStation = savedPlaylist.get(nextIndex); + } } - playedStation = savedPlaylist.get(nextIndex); } @Override diff --git a/src/test/java/device/radioPlayer/RadioPlayerTest.java b/src/test/java/device/radioPlayer/RadioPlayerTest.java index 6dc3db6..fcf7b3a 100644 --- a/src/test/java/device/radioPlayer/RadioPlayerTest.java +++ b/src/test/java/device/radioPlayer/RadioPlayerTest.java @@ -76,17 +76,21 @@ class RadioPlayerTest { RadioPlayer rp2 = new RadioPlayer(); RadioPlayer rp3 = new RadioPlayer(); RadioPlayer rp4 = new RadioPlayer(); + RadioPlayer rp5 = new RadioPlayer(); rp1.next(); rp2.next(); rp2.prev(); rp3.prev(); rp4.changeRegion("BY"); rp4.next(); + rp5.changeRegion("BY"); + rp5.prev(); return Stream.of( Arguments.of("Next Station Test for saved Stations", rp1, "Teddy"), Arguments.of("Prev Station Test for saved Stations", rp2, "YouFM"), Arguments.of("Prev works on first Station for saved Stations", rp3, "MegaHits"), - Arguments.of("changed Region and going to next station", rp4, "Bayern 1") + Arguments.of("changed Region and going to next station", rp4, "Bayern 1"), + Arguments.of("changed Region and going to prev station", rp5, "Hit Radio N1") ); } From ecf5a3e4ad2363a766081e57c9e30ec4f7cfbc62 Mon Sep 17 00:00:00 2001 From: alpina0707 Date: Mon, 14 Feb 2022 22:06:37 +0100 Subject: [PATCH 4/4] added new test case for saveStation & changed saveStation() to not saving duplicate stations --- src/main/java/device/radioPlayer/RadioPlayer.java | 8 +++++--- src/test/java/device/radioPlayer/RadioPlayerTest.java | 5 ++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main/java/device/radioPlayer/RadioPlayer.java b/src/main/java/device/radioPlayer/RadioPlayer.java index 6f68676..f0ae7a3 100644 --- a/src/main/java/device/radioPlayer/RadioPlayer.java +++ b/src/main/java/device/radioPlayer/RadioPlayer.java @@ -114,7 +114,7 @@ public class RadioPlayer implements Device { @Override public void next() { - if (regionPlaylist.contains(playedStation)){ + if (regionPlaylist.contains(playedStation)) { int currentIndex = regionPlaylist.indexOf(playedStation); int nextIndex = (currentIndex + 1) % regionPlaylist.size(); playedStation = regionPlaylist.get(nextIndex); @@ -183,7 +183,9 @@ public class RadioPlayer implements Device { } public String saveStation() { - savedPlaylist.add(playedStation); - return ""; + if (savedPlaylist.contains(playedStation)) return "Station " + playedStation + " is already saved"; + else + savedPlaylist.add(playedStation); + return "Station " + playedStation + " is saved in your Station list"; } } diff --git a/src/test/java/device/radioPlayer/RadioPlayerTest.java b/src/test/java/device/radioPlayer/RadioPlayerTest.java index fcf7b3a..ce7114e 100644 --- a/src/test/java/device/radioPlayer/RadioPlayerTest.java +++ b/src/test/java/device/radioPlayer/RadioPlayerTest.java @@ -194,11 +194,14 @@ class RadioPlayerTest { static Stream saveStationOptions() { RadioPlayer rp1 = new RadioPlayer(); + RadioPlayer rp2 = new RadioPlayer(); rp1.changeRegion("BY"); rp1.saveStation(); + rp2.saveStation(); return Stream.of( - Arguments.of("Test for saving station in saved playlist", rp1, "Antenne Bayern") + Arguments.of("Test for saving station in saved playlist", rp1, "Antenne Bayern"), + Arguments.of("Test for not saving station which is already in saved playlist", rp2, "MegaHits") ); }