From b7b79badda3d9c14f0fa7360b8256ec51fe3cde0 Mon Sep 17 00:00:00 2001 From: alpina0707 Date: Wed, 16 Feb 2022 20:09:42 +0100 Subject: [PATCH] added second test case for getItemList() & and added productive code for RadioPlayer --- src/main/java/device/radioPlayer/RadioPlayer.java | 5 ++++- .../java/device/radioPlayer/RadioPlayerTest.java | 12 ++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/main/java/device/radioPlayer/RadioPlayer.java b/src/main/java/device/radioPlayer/RadioPlayer.java index 1741dc6..5ef8556 100644 --- a/src/main/java/device/radioPlayer/RadioPlayer.java +++ b/src/main/java/device/radioPlayer/RadioPlayer.java @@ -185,7 +185,10 @@ public class RadioPlayer implements Device { @Override public String[] getItemList() { - return savedPlaylist.toArray(new String[0]); + if (regionPlaylist.contains(playedStation)) + return regionPlaylist.toArray(new String[0]); + else + return savedPlaylist.toArray(new String[0]); } @Override diff --git a/src/test/java/device/radioPlayer/RadioPlayerTest.java b/src/test/java/device/radioPlayer/RadioPlayerTest.java index b991a7f..4de54c2 100644 --- a/src/test/java/device/radioPlayer/RadioPlayerTest.java +++ b/src/test/java/device/radioPlayer/RadioPlayerTest.java @@ -320,18 +320,26 @@ class RadioPlayerTest { Arguments.of("Test for change order in saved playlist with nr is than smaller than 0 at front of playlist", rp2, 0, "Teddy") ); } + @ParameterizedTest @MethodSource("getItemListOptions") - void testGetItemList(String testName, RadioPlayer testRp, String[] expectedResult) { + void testGetItemList(String testName, RadioPlayer testRp, String testTyp, String[] expectedResult) { + if (testTyp.equals("region")) { + testRp.changeRegion("BY"); + } + String[] playList = testRp.getItemList(); assertThat(playList).describedAs(testName).isEqualTo(expectedResult); } static Stream getItemListOptions() { RadioPlayer rp = new RadioPlayer(); + RadioPlayer rp1 = new RadioPlayer(); + rp1.changeRegion("BY"); return Stream.of( - Arguments.of("Test for return saved playlist", rp, rp.savedPlaylist.toArray(new String[0])) + Arguments.of("Test for return saved playlist", rp, "saved", rp.savedPlaylist.toArray(new String[0])), + Arguments.of("Test for return regional playlist", rp1, "region", rp1.regionPlaylist.toArray(new String[0])) ); } } \ No newline at end of file