From 799360763a94c8cf51fd3fa6d48ecf6b486f304f Mon Sep 17 00:00:00 2001 From: alpina0707 Date: Tue, 15 Feb 2022 17:42:06 +0100 Subject: [PATCH 1/3] added first test case for changeOrderInSavedPlaylist() & and added productive code --- .../java/device/radioPlayer/RadioPlayer.java | 7 +++++++ .../device/radioPlayer/RadioPlayerTest.java | 17 +++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/main/java/device/radioPlayer/RadioPlayer.java b/src/main/java/device/radioPlayer/RadioPlayer.java index 075cd4a..b68c0c8 100644 --- a/src/main/java/device/radioPlayer/RadioPlayer.java +++ b/src/main/java/device/radioPlayer/RadioPlayer.java @@ -210,4 +210,11 @@ public class RadioPlayer implements Device { } return "You are already in saved Playlist!"; } + + public String changeOrderInSavedPlaylist(int nr) { + String station = playedStation; + savedPlaylist.remove(playedStation); + savedPlaylist.add(nr-1,station); + return"Station " + playedStation + " is now on place 0" + nr + "in saved playlist"; + } } diff --git a/src/test/java/device/radioPlayer/RadioPlayerTest.java b/src/test/java/device/radioPlayer/RadioPlayerTest.java index a92b654..782dfbd 100644 --- a/src/test/java/device/radioPlayer/RadioPlayerTest.java +++ b/src/test/java/device/radioPlayer/RadioPlayerTest.java @@ -265,4 +265,21 @@ class RadioPlayerTest { ); } + + @ParameterizedTest + @MethodSource("changeOrderInSavedPlaylistOptions") + void testChangeOrderInSavedPlaylist(String testName, RadioPlayer testRp, int nr, String expectedResult) { + String savedStation = testRp.savedPlaylist.get(nr); + assertThat(savedStation).describedAs(testName).isEqualTo(expectedResult); + } + + static Stream changeOrderInSavedPlaylistOptions() { + RadioPlayer rp = new RadioPlayer(); + rp.next(); + rp.changeOrderInSavedPlaylist(1); + + return Stream.of( + Arguments.of("Test for change order in saved playlist with nr isn`t than playlist size", rp, 0, "Teddy") + ); + } } \ No newline at end of file From 6776f0b75268862f4b0d47538b00801a7b1b76e2 Mon Sep 17 00:00:00 2001 From: alpina0707 Date: Tue, 15 Feb 2022 18:04:07 +0100 Subject: [PATCH 2/3] added second test case for changeOrderInSavedPlaylist() & and added productive code --- src/main/java/device/radioPlayer/RadioPlayer.java | 12 +++++++++--- .../java/device/radioPlayer/RadioPlayerTest.java | 5 ++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/main/java/device/radioPlayer/RadioPlayer.java b/src/main/java/device/radioPlayer/RadioPlayer.java index b68c0c8..4d26867 100644 --- a/src/main/java/device/radioPlayer/RadioPlayer.java +++ b/src/main/java/device/radioPlayer/RadioPlayer.java @@ -213,8 +213,14 @@ public class RadioPlayer implements Device { public String changeOrderInSavedPlaylist(int nr) { String station = playedStation; - savedPlaylist.remove(playedStation); - savedPlaylist.add(nr-1,station); - return"Station " + playedStation + " is now on place 0" + nr + "in saved playlist"; + if((nr-1) > savedPlaylist.size()) { + savedPlaylist.remove(playedStation); + savedPlaylist.add(savedPlaylist.size(),station); + return"Station " + playedStation + " is now on place 0" + nr + "in saved playlist"; + } else { + savedPlaylist.remove(playedStation); + savedPlaylist.add(nr - 1, station); + return "Station " + playedStation + " is now on place 0" + (savedPlaylist.size()+1) + "in saved playlist"; + } } } diff --git a/src/test/java/device/radioPlayer/RadioPlayerTest.java b/src/test/java/device/radioPlayer/RadioPlayerTest.java index 782dfbd..db0ec4b 100644 --- a/src/test/java/device/radioPlayer/RadioPlayerTest.java +++ b/src/test/java/device/radioPlayer/RadioPlayerTest.java @@ -277,9 +277,12 @@ class RadioPlayerTest { RadioPlayer rp = new RadioPlayer(); rp.next(); rp.changeOrderInSavedPlaylist(1); + RadioPlayer rp1 = new RadioPlayer(); + rp1.changeOrderInSavedPlaylist(5); return Stream.of( - Arguments.of("Test for change order in saved playlist with nr isn`t than playlist size", rp, 0, "Teddy") + Arguments.of("Test for change order in saved playlist with nr isn`t bigger than playlist size", rp, 0, "Teddy"), + Arguments.of("Test for change order in saved playlist with nr is than bigger playlist size but at the end of playlist", rp1, 2, "YouFM") ); } } \ No newline at end of file From 0cc9fe4b88f46895ac2340f3bcfeb20f4819efb4 Mon Sep 17 00:00:00 2001 From: alpina0707 Date: Tue, 15 Feb 2022 18:12:45 +0100 Subject: [PATCH 3/3] added third test case for changeOrderInSavedPlaylist() & and added productive code --- src/main/java/device/radioPlayer/RadioPlayer.java | 11 ++++++++--- src/test/java/device/radioPlayer/RadioPlayerTest.java | 6 +++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/main/java/device/radioPlayer/RadioPlayer.java b/src/main/java/device/radioPlayer/RadioPlayer.java index 4d26867..73d5625 100644 --- a/src/main/java/device/radioPlayer/RadioPlayer.java +++ b/src/main/java/device/radioPlayer/RadioPlayer.java @@ -216,11 +216,16 @@ public class RadioPlayer implements Device { if((nr-1) > savedPlaylist.size()) { savedPlaylist.remove(playedStation); savedPlaylist.add(savedPlaylist.size(),station); - return"Station " + playedStation + " is now on place 0" + nr + "in saved playlist"; - } else { + return"Station " + playedStation + " is now on place 0" + (savedPlaylist.size()+1) + "in saved playlist"; + }else if(nr < 0) { + savedPlaylist.remove(playedStation); + savedPlaylist.add(0,station); + return"Station " + playedStation + " is now on place 01 in saved playlist"; + } + else { savedPlaylist.remove(playedStation); savedPlaylist.add(nr - 1, station); - return "Station " + playedStation + " is now on place 0" + (savedPlaylist.size()+1) + "in saved playlist"; + return "Station " + playedStation + " is now on place 0" + nr + "in saved playlist"; } } } diff --git a/src/test/java/device/radioPlayer/RadioPlayerTest.java b/src/test/java/device/radioPlayer/RadioPlayerTest.java index db0ec4b..109e1d1 100644 --- a/src/test/java/device/radioPlayer/RadioPlayerTest.java +++ b/src/test/java/device/radioPlayer/RadioPlayerTest.java @@ -279,10 +279,14 @@ class RadioPlayerTest { rp.changeOrderInSavedPlaylist(1); RadioPlayer rp1 = new RadioPlayer(); rp1.changeOrderInSavedPlaylist(5); + RadioPlayer rp2 = new RadioPlayer(); + rp2.next(); + rp2.changeOrderInSavedPlaylist(-1); return Stream.of( Arguments.of("Test for change order in saved playlist with nr isn`t bigger than playlist size", rp, 0, "Teddy"), - Arguments.of("Test for change order in saved playlist with nr is than bigger playlist size but at the end of playlist", rp1, 2, "YouFM") + Arguments.of("Test for change order in saved playlist with nr is than bigger playlist size put at the end of playlist", rp1, 2, "YouFM"), + Arguments.of("Test for change order in saved playlist with nr is than smaller than 0 at front of playlist", rp2, 0, "Teddy") ); } } \ No newline at end of file