From 492cbdb79073a42f10a53428228b6e46e22d6a86 Mon Sep 17 00:00:00 2001 From: alpina0707 Date: Mon, 14 Feb 2022 23:22:09 +0100 Subject: [PATCH 1/2] added new test case for play() & changed play() to show if playedStation is in regional or saved playlist --- src/main/java/device/radioPlayer/RadioPlayer.java | 7 +++++-- src/test/java/device/radioPlayer/RadioPlayerTest.java | 5 ++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/java/device/radioPlayer/RadioPlayer.java b/src/main/java/device/radioPlayer/RadioPlayer.java index e1cb7dc..258eff5 100644 --- a/src/main/java/device/radioPlayer/RadioPlayer.java +++ b/src/main/java/device/radioPlayer/RadioPlayer.java @@ -164,7 +164,10 @@ public class RadioPlayer implements Device { @Override public String play() { - return ("Radio is playing station: 0" + (savedPlaylist.indexOf(playedStation) + 1) + " " + this.playedStation); + if (regionPlaylist.contains(playedStation)) + return ("Radio is playing station: 0" + (regionPlaylist.indexOf(playedStation) + 1) + " " + this.playedStation + " from regional playlist"); + else + return ("Radio is playing station: 0" + (savedPlaylist.indexOf(playedStation) + 1) + " " + this.playedStation + " from saved playlist"); } public String showStationInfo() { @@ -186,7 +189,7 @@ public class RadioPlayer implements Device { if (savedPlaylist.contains(playedStation)) return "Station " + playedStation + " is already saved"; else savedPlaylist.add(playedStation); - regionPlaylist.clear(); + regionPlaylist.clear(); 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 00d8bc6..dd49dce 100644 --- a/src/test/java/device/radioPlayer/RadioPlayerTest.java +++ b/src/test/java/device/radioPlayer/RadioPlayerTest.java @@ -185,9 +185,12 @@ class RadioPlayerTest { static Stream testPlayOptions() { RadioPlayer rp1 = new RadioPlayer(); + RadioPlayer rp2 = new RadioPlayer(); + rp2.changeRegion("BY"); return Stream.of( - Arguments.of("Test for playing first station on saved playlist", rp1, "Radio is playing station: 01 YouFM") + Arguments.of("Test for playing first station on saved playlist", rp1, "Radio is playing station: 01 YouFM from saved playlist"), + Arguments.of("Test for playing first station on regional playlist", rp2, "Radio is playing station: 01 Antenne Bayern from regional playlist") ); } From 54ac5f48b32f398f1329ebd22b94b9fa36fe9e37 Mon Sep 17 00:00:00 2001 From: alpina0707 Date: Mon, 14 Feb 2022 23:28:13 +0100 Subject: [PATCH 2/2] added new test case for play() & changed play() to show if playedStation is in regional or saved playlist --- src/test/java/device/radioPlayer/RadioPlayerTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/device/radioPlayer/RadioPlayerTest.java b/src/test/java/device/radioPlayer/RadioPlayerTest.java index dd49dce..225f0f6 100644 --- a/src/test/java/device/radioPlayer/RadioPlayerTest.java +++ b/src/test/java/device/radioPlayer/RadioPlayerTest.java @@ -198,7 +198,7 @@ class RadioPlayerTest { @MethodSource("saveStationOptions") void testSaveStation(String testName, RadioPlayer testRp,String testTyp, String expectedResult) { String savedStation; - if (testTyp == "normal") { + if (testTyp.equals("normal")) { savedStation = testRp.savedPlaylist.get(testRp.savedPlaylist.size() - 1);} else savedStation = Boolean.toString(testRp.regionPlaylist.isEmpty()); assertThat(savedStation).describedAs(testName).isEqualTo(expectedResult);