From ecf5a3e4ad2363a766081e57c9e30ec4f7cfbc62 Mon Sep 17 00:00:00 2001 From: alpina0707 Date: Mon, 14 Feb 2022 22:06:37 +0100 Subject: [PATCH] added new test case for saveStation & changed saveStation() to not saving duplicate stations --- src/main/java/device/radioPlayer/RadioPlayer.java | 8 +++++--- src/test/java/device/radioPlayer/RadioPlayerTest.java | 5 ++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main/java/device/radioPlayer/RadioPlayer.java b/src/main/java/device/radioPlayer/RadioPlayer.java index 6f68676..f0ae7a3 100644 --- a/src/main/java/device/radioPlayer/RadioPlayer.java +++ b/src/main/java/device/radioPlayer/RadioPlayer.java @@ -114,7 +114,7 @@ public class RadioPlayer implements Device { @Override public void next() { - if (regionPlaylist.contains(playedStation)){ + if (regionPlaylist.contains(playedStation)) { int currentIndex = regionPlaylist.indexOf(playedStation); int nextIndex = (currentIndex + 1) % regionPlaylist.size(); playedStation = regionPlaylist.get(nextIndex); @@ -183,7 +183,9 @@ public class RadioPlayer implements Device { } public String saveStation() { - savedPlaylist.add(playedStation); - return ""; + if (savedPlaylist.contains(playedStation)) return "Station " + playedStation + " is already saved"; + else + savedPlaylist.add(playedStation); + 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 fcf7b3a..ce7114e 100644 --- a/src/test/java/device/radioPlayer/RadioPlayerTest.java +++ b/src/test/java/device/radioPlayer/RadioPlayerTest.java @@ -194,11 +194,14 @@ class RadioPlayerTest { static Stream saveStationOptions() { RadioPlayer rp1 = new RadioPlayer(); + RadioPlayer rp2 = new RadioPlayer(); rp1.changeRegion("BY"); rp1.saveStation(); + rp2.saveStation(); return Stream.of( - Arguments.of("Test for saving station in saved playlist", rp1, "Antenne Bayern") + Arguments.of("Test for saving station in saved playlist", rp1, "Antenne Bayern"), + Arguments.of("Test for not saving station which is already in saved playlist", rp2, "MegaHits") ); }