From 3376c4c676218366dcd949ff3f64698ef969caf2 Mon Sep 17 00:00:00 2001 From: alpina0707 Date: Wed, 9 Feb 2022 20:02:39 +0100 Subject: [PATCH 1/4] first Test for changeRegion() --- .../java/device/radioPlayer/RadioPlayer.java | 3 ++ .../device/radioPlayer/RadioPlayerTest.java | 38 +++++++------------ 2 files changed, 17 insertions(+), 24 deletions(-) diff --git a/src/main/java/device/radioPlayer/RadioPlayer.java b/src/main/java/device/radioPlayer/RadioPlayer.java index ca8897d..61763ea 100644 --- a/src/main/java/device/radioPlayer/RadioPlayer.java +++ b/src/main/java/device/radioPlayer/RadioPlayer.java @@ -26,6 +26,9 @@ public class RadioPlayer implements Device { return Lautstaerke; } + public void changeRegion(){ + + } @Override public void louder() { diff --git a/src/test/java/device/radioPlayer/RadioPlayerTest.java b/src/test/java/device/radioPlayer/RadioPlayerTest.java index e7e2410..f192ae9 100644 --- a/src/test/java/device/radioPlayer/RadioPlayerTest.java +++ b/src/test/java/device/radioPlayer/RadioPlayerTest.java @@ -44,35 +44,25 @@ class RadioPlayerTest { ); } -/* - @Test - void louder() { - rp.setLautstaerke(0); - rp.louder(); - assertThat(rp.getLautstaerke()).isEqualTo(1); + @ParameterizedTest + @MethodSource("changeRegionOptions") + void changeFrequencyTest(String testName, RadioPlayer testRp, String expectedResult) { + String station = testRp.playTrack; + assertThat(station).describedAs(testName).isEqualTo(expectedResult); } - @Test - void louderMax() { - rp.setLautstaerke(100); - rp.louder(); - assertThat(rp.getLautstaerke()).isEqualTo(100); - } + static Stream changeRegionOptions() { + RadioPlayer rp1 = new RadioPlayer(); + rp1.changeRegion(); - @Test - void quieter() { - rp.setLautstaerke(1); - rp.quieter(); - assertThat(rp.getLautstaerke()).isEqualTo(0); - } - @Test - void quieterMax() { - rp.setLautstaerke(0); - rp.quieter(); - assertThat(rp.getLautstaerke()).isEqualTo(0); + return Stream.of( + Arguments.of("Test change Region to Bayern", rp1, "Antenne Bayern") + + ); } - Jenkins config test + +/* @Test void getVolume() { } From e603340839dbdca7ece1b0be6db3cf759fe2a30e Mon Sep 17 00:00:00 2001 From: alpina0707 Date: Thu, 10 Feb 2022 16:48:45 +0100 Subject: [PATCH 2/4] added first region to changeRegion() --- src/main/java/device/radioPlayer/RadioPlayer.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/device/radioPlayer/RadioPlayer.java b/src/main/java/device/radioPlayer/RadioPlayer.java index 61763ea..7bf5da1 100644 --- a/src/main/java/device/radioPlayer/RadioPlayer.java +++ b/src/main/java/device/radioPlayer/RadioPlayer.java @@ -15,6 +15,7 @@ public class RadioPlayer implements Device { } ArrayList Playlist=new ArrayList(); + int Lautstaerke = 0; String playTrack=""; @@ -27,7 +28,12 @@ public class RadioPlayer implements Device { } public void changeRegion(){ - + Playlist.clear(); + Playlist.add("Antenne Bayern"); + Playlist.add("Bayern 1"); + Playlist.add("Bayern 3"); + Playlist.add("Hit Radio N1"); + playTrack=Playlist.get(0); } @Override From 25148dfdc53f21d551288aa741accd72b27c57be Mon Sep 17 00:00:00 2001 From: alpina0707 Date: Thu, 10 Feb 2022 17:01:08 +0100 Subject: [PATCH 3/4] added test and code for second region to changeRegion() --- .../java/device/radioPlayer/RadioPlayer.java | 32 +++++++++++++++---- .../device/radioPlayer/RadioPlayerTest.java | 16 ++++++---- 2 files changed, 34 insertions(+), 14 deletions(-) diff --git a/src/main/java/device/radioPlayer/RadioPlayer.java b/src/main/java/device/radioPlayer/RadioPlayer.java index 7bf5da1..fb31321 100644 --- a/src/main/java/device/radioPlayer/RadioPlayer.java +++ b/src/main/java/device/radioPlayer/RadioPlayer.java @@ -27,13 +27,31 @@ public class RadioPlayer implements Device { return Lautstaerke; } - public void changeRegion(){ - Playlist.clear(); - Playlist.add("Antenne Bayern"); - Playlist.add("Bayern 1"); - Playlist.add("Bayern 3"); - Playlist.add("Hit Radio N1"); - playTrack=Playlist.get(0); + public void changeRegion(String region){ + switch (region) { + case "Bayern": + Playlist.clear(); + Playlist.add("Antenne Bayern"); + Playlist.add("Bayern 1"); + Playlist.add("Bayern 3"); + Playlist.add("Hit Radio N1"); + playTrack=Playlist.get(0); + break; + case "Hessen": + Playlist.clear(); + Playlist.add("Hit Radio FFH"); + Playlist.add("HR 1"); + Playlist.add("HR 3"); + Playlist.add("You FM"); + playTrack=Playlist.get(0); + break; + default: + Playlist.clear(); + Playlist.add("YouFM"); + Playlist.add("Teddy"); + Playlist.add("MegaHits"); + playTrack=Playlist.get(0); + } } @Override diff --git a/src/test/java/device/radioPlayer/RadioPlayerTest.java b/src/test/java/device/radioPlayer/RadioPlayerTest.java index f192ae9..6c173ae 100644 --- a/src/test/java/device/radioPlayer/RadioPlayerTest.java +++ b/src/test/java/device/radioPlayer/RadioPlayerTest.java @@ -46,18 +46,20 @@ class RadioPlayerTest { @ParameterizedTest @MethodSource("changeRegionOptions") - void changeFrequencyTest(String testName, RadioPlayer testRp, String expectedResult) { + void changeRegionTest(String testName, RadioPlayer testRp, String expectedResult) { String station = testRp.playTrack; assertThat(station).describedAs(testName).isEqualTo(expectedResult); } static Stream changeRegionOptions() { RadioPlayer rp1 = new RadioPlayer(); - rp1.changeRegion(); + RadioPlayer rp2 = new RadioPlayer(); + rp1.changeRegion("Bayern"); + rp2.changeRegion("Hessen"); return Stream.of( - Arguments.of("Test change Region to Bayern", rp1, "Antenne Bayern") - + Arguments.of("Test change Region to Bayern", rp1, "Antenne Bayern"), + Arguments.of("Test change Region to Hessen", rp2, "Hit Radio FFH") ); } @@ -84,9 +86,9 @@ class RadioPlayerTest { rp2.prev(); rp3.prev(); return Stream.of( - Arguments.of("Next Station Test", rp1, "Radio Teddy"), - Arguments.of("Prev Station Test", rp2, "Radio YouFM"), - Arguments.of("Prev works on first Station ", rp3, "Radio MegaHits") + Arguments.of("Next Station Test", rp1, "Teddy"), + Arguments.of("Prev Station Test", rp2, "YouFM"), + Arguments.of("Prev works on first Station ", rp3, "MegaHits") ); } From 7b164b510a89feb81909204e3471df8306f96789 Mon Sep 17 00:00:00 2001 From: alpina0707 Date: Thu, 10 Feb 2022 17:22:05 +0100 Subject: [PATCH 4/4] bug fix renaming saved stations --- .../java/device/radioPlayer/RadioPlayer.java | 19 ++++++++++++++----- .../device/radioPlayer/RadioPlayerTest.java | 9 ++++++--- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/main/java/device/radioPlayer/RadioPlayer.java b/src/main/java/device/radioPlayer/RadioPlayer.java index fb31321..36d7170 100644 --- a/src/main/java/device/radioPlayer/RadioPlayer.java +++ b/src/main/java/device/radioPlayer/RadioPlayer.java @@ -8,9 +8,9 @@ public class RadioPlayer implements Device { public RadioPlayer() { super(); - Playlist.add("Radio YouFM"); - Playlist.add("Radio Teddy"); - Playlist.add("Radio MegaHits"); + Playlist.add("YouFM"); + Playlist.add("Teddy"); + Playlist.add("MegaHits"); playTrack=Playlist.get(0); } @@ -29,7 +29,7 @@ public class RadioPlayer implements Device { public void changeRegion(String region){ switch (region) { - case "Bayern": + case "BY": Playlist.clear(); Playlist.add("Antenne Bayern"); Playlist.add("Bayern 1"); @@ -37,7 +37,7 @@ public class RadioPlayer implements Device { Playlist.add("Hit Radio N1"); playTrack=Playlist.get(0); break; - case "Hessen": + case "HE": Playlist.clear(); Playlist.add("Hit Radio FFH"); Playlist.add("HR 1"); @@ -45,12 +45,21 @@ public class RadioPlayer implements Device { Playlist.add("You FM"); playTrack=Playlist.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); + break; } } diff --git a/src/test/java/device/radioPlayer/RadioPlayerTest.java b/src/test/java/device/radioPlayer/RadioPlayerTest.java index 6c173ae..89092ba 100644 --- a/src/test/java/device/radioPlayer/RadioPlayerTest.java +++ b/src/test/java/device/radioPlayer/RadioPlayerTest.java @@ -54,12 +54,15 @@ class RadioPlayerTest { static Stream changeRegionOptions() { RadioPlayer rp1 = new RadioPlayer(); RadioPlayer rp2 = new RadioPlayer(); - rp1.changeRegion("Bayern"); - rp2.changeRegion("Hessen"); + RadioPlayer rp3 = new RadioPlayer(); + rp1.changeRegion("BY"); + rp2.changeRegion("HE"); + rp3.changeRegion("BW"); return Stream.of( Arguments.of("Test change Region to Bayern", rp1, "Antenne Bayern"), - Arguments.of("Test change Region to Hessen", rp2, "Hit Radio FFH") + Arguments.of("Test change Region to Hessen", rp2, "Hit Radio FFH"), + Arguments.of("Test change Region to Baden-Wuerttemberg", rp3, "DASDING") ); }