From 5d52b2f721a06d7ed9989523021f4294d33a3c2f Mon Sep 17 00:00:00 2001 From: alpina0707 Date: Tue, 15 Feb 2022 16:42:52 +0100 Subject: [PATCH 1/2] added first test case for changeToSavedPlaylist() & and added productive code --- .../java/device/radioPlayer/RadioPlayer.java | 3 +++ .../device/radioPlayer/RadioPlayerTest.java | 17 +++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/main/java/device/radioPlayer/RadioPlayer.java b/src/main/java/device/radioPlayer/RadioPlayer.java index 12e4148..849784d 100644 --- a/src/main/java/device/radioPlayer/RadioPlayer.java +++ b/src/main/java/device/radioPlayer/RadioPlayer.java @@ -202,4 +202,7 @@ public class RadioPlayer implements Device { } else return " Last Station: 01 " + station + " canĀ“t by deleted"; } + public String changeToSavedPlaylist() { + return "You are already in saved Playlist!"; + } } diff --git a/src/test/java/device/radioPlayer/RadioPlayerTest.java b/src/test/java/device/radioPlayer/RadioPlayerTest.java index c272ddb..7ab13b0 100644 --- a/src/test/java/device/radioPlayer/RadioPlayerTest.java +++ b/src/test/java/device/radioPlayer/RadioPlayerTest.java @@ -244,4 +244,21 @@ class RadioPlayerTest { Arguments.of("Test for not delete station in saved playlist if this is the last station", rp1, "noDelete", true) ); } + + @ParameterizedTest + @MethodSource("changeToSavedPlaylistOptions") + void testChangeToSavedPlaylist(String testName, RadioPlayer testRp, String expectedResult) { + String savedStation = testRp.playedStation; + assertThat(savedStation).describedAs(testName).isEqualTo(expectedResult); + } + + static Stream changeToSavedPlaylistOptions() { + RadioPlayer rp = new RadioPlayer(); + rp.changeToSavedPlaylist(); + + return Stream.of( + Arguments.of("Test for change to saved playlist when you already in saved playlist", rp, "YouFM") + + ); + } } \ No newline at end of file From 0a02c7b9cdea159b75a781abdac4db4ab846240b Mon Sep 17 00:00:00 2001 From: alpina0707 Date: Tue, 15 Feb 2022 16:56:33 +0100 Subject: [PATCH 2/2] added second test case for changeToSavedPlaylist() & and added productive code --- src/main/java/device/radioPlayer/RadioPlayer.java | 5 +++++ src/test/java/device/radioPlayer/RadioPlayerTest.java | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/device/radioPlayer/RadioPlayer.java b/src/main/java/device/radioPlayer/RadioPlayer.java index 849784d..075cd4a 100644 --- a/src/main/java/device/radioPlayer/RadioPlayer.java +++ b/src/main/java/device/radioPlayer/RadioPlayer.java @@ -203,6 +203,11 @@ public class RadioPlayer implements Device { } public String changeToSavedPlaylist() { + 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"; + } return "You are already in saved Playlist!"; } } diff --git a/src/test/java/device/radioPlayer/RadioPlayerTest.java b/src/test/java/device/radioPlayer/RadioPlayerTest.java index 7ab13b0..a92b654 100644 --- a/src/test/java/device/radioPlayer/RadioPlayerTest.java +++ b/src/test/java/device/radioPlayer/RadioPlayerTest.java @@ -255,9 +255,13 @@ class RadioPlayerTest { static Stream changeToSavedPlaylistOptions() { RadioPlayer rp = new RadioPlayer(); rp.changeToSavedPlaylist(); + RadioPlayer rp1 = new RadioPlayer(); + rp1.changeRegion("BY"); + rp1.changeToSavedPlaylist(); return Stream.of( - Arguments.of("Test for change to saved playlist when you already in saved playlist", rp, "YouFM") + Arguments.of("Test for change to saved playlist when you already in saved playlist", rp, "YouFM"), + Arguments.of("Test for change to saved playlist when in regional playlist", rp1, "YouFM") ); }