From 25148dfdc53f21d551288aa741accd72b27c57be Mon Sep 17 00:00:00 2001 From: alpina0707 Date: Thu, 10 Feb 2022 17:01:08 +0100 Subject: [PATCH] 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") ); }