From 9f78d7aa9b5826b88cd386deb8f8f81a9e99f2e8 Mon Sep 17 00:00:00 2001 From: alpina0707 Date: Mon, 14 Feb 2022 23:00:42 +0100 Subject: [PATCH] added new test case for saveStation & changed saveStation() to jump back to savedPlaylist after station is saved --- .../java/device/radioPlayer/RadioPlayer.java | 1 + .../device/radioPlayer/RadioPlayerTest.java | 23 +++++++++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/main/java/device/radioPlayer/RadioPlayer.java b/src/main/java/device/radioPlayer/RadioPlayer.java index f0ae7a3..e1cb7dc 100644 --- a/src/main/java/device/radioPlayer/RadioPlayer.java +++ b/src/main/java/device/radioPlayer/RadioPlayer.java @@ -186,6 +186,7 @@ public class RadioPlayer implements Device { if (savedPlaylist.contains(playedStation)) return "Station " + playedStation + " is already saved"; else savedPlaylist.add(playedStation); + 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 ce7114e..00d8bc6 100644 --- a/src/test/java/device/radioPlayer/RadioPlayerTest.java +++ b/src/test/java/device/radioPlayer/RadioPlayerTest.java @@ -77,6 +77,7 @@ class RadioPlayerTest { RadioPlayer rp3 = new RadioPlayer(); RadioPlayer rp4 = new RadioPlayer(); RadioPlayer rp5 = new RadioPlayer(); + RadioPlayer rp6 = new RadioPlayer(); rp1.next(); rp2.next(); rp2.prev(); @@ -85,12 +86,17 @@ class RadioPlayerTest { rp4.next(); rp5.changeRegion("BY"); rp5.prev(); + rp6.changeRegion("BY"); + rp6.saveStation(); + rp6.next(); + return Stream.of( Arguments.of("Next Station Test for saved Stations", rp1, "Teddy"), Arguments.of("Prev Station Test for saved Stations", rp2, "YouFM"), Arguments.of("Prev works on first Station for saved Stations", rp3, "MegaHits"), Arguments.of("changed Region and going to next station", rp4, "Bayern 1"), - Arguments.of("changed Region and going to prev station", rp5, "Hit Radio N1") + Arguments.of("changed Region and going to prev station", rp5, "Hit Radio N1"), + Arguments.of("changed Region, saved station and going to next station", rp6, "YouFM") ); } @@ -187,21 +193,28 @@ class RadioPlayerTest { @ParameterizedTest @MethodSource("saveStationOptions") - void testSaveStation(String testName, RadioPlayer testRp, String expectedResult) { - String savedStation = testRp.savedPlaylist.get(testRp.savedPlaylist.size() - 1); + void testSaveStation(String testName, RadioPlayer testRp,String testTyp, String expectedResult) { + String savedStation; + if (testTyp == "normal") { + savedStation = testRp.savedPlaylist.get(testRp.savedPlaylist.size() - 1);} + else savedStation = Boolean.toString(testRp.regionPlaylist.isEmpty()); assertThat(savedStation).describedAs(testName).isEqualTo(expectedResult); } static Stream saveStationOptions() { RadioPlayer rp1 = new RadioPlayer(); RadioPlayer rp2 = new RadioPlayer(); + RadioPlayer rp3 = new RadioPlayer(); rp1.changeRegion("BY"); rp1.saveStation(); rp2.saveStation(); + rp3.changeRegion("BY"); + rp3.saveStation(); return Stream.of( - 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") + Arguments.of("Test for saving station in saved playlist", rp1, "normal", "Antenne Bayern"), + Arguments.of("Test for not saving station which is already in saved playlist", rp2, "normal", "MegaHits"), + Arguments.of("Test for after saving station jump back to saved playlist", rp3, "jump", "true") ); }