From a5c936d2700431c797b59835703ebf92454bc0d1 Mon Sep 17 00:00:00 2001 From: alpina0707 Date: Wed, 16 Feb 2022 18:57:40 +0100 Subject: [PATCH] added fourth test case for chooseItem() & and added productive code for RadioPlayer --- .../java/device/radioPlayer/RadioPlayer.java | 22 +++++++++++-------- .../device/radioPlayer/RadioPlayerTest.java | 6 ++++- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/main/java/device/radioPlayer/RadioPlayer.java b/src/main/java/device/radioPlayer/RadioPlayer.java index 5e9d7fe..42a5159 100644 --- a/src/main/java/device/radioPlayer/RadioPlayer.java +++ b/src/main/java/device/radioPlayer/RadioPlayer.java @@ -158,16 +158,20 @@ public class RadioPlayer implements Device { @Override public String chooseItem(int itemNr) { - if (itemNr > savedPlaylist.size()) { - playedStation = savedPlaylist.get(savedPlaylist.size() - 1); - return ("Radio is playing station: 0" + savedPlaylist.size() + " " + this.playedStation + " from saved playlist"); - } else if (itemNr < 1) { - playedStation = savedPlaylist.get(0); - return ("Radio is playing station: 01 " + this.playedStation + " from saved playlist"); + if (regionPlaylist.contains(playedStation)) { + playedStation = regionPlaylist.get(itemNr - 1); + return ("Radio is playing station: 0" + (regionPlaylist.indexOf(playedStation) + 1) + " " + this.playedStation + " from regional playlist"); } else { - playedStation = savedPlaylist.get(itemNr - 1); - return ("Radio is playing station: 0" + (savedPlaylist.indexOf(playedStation) + 1) + " " + this.playedStation + " from saved playlist"); - + if (itemNr > savedPlaylist.size()) { + playedStation = savedPlaylist.get(savedPlaylist.size() - 1); + return ("Radio is playing station: 0" + savedPlaylist.size() + " " + this.playedStation + " from saved playlist"); + } else if (itemNr < 1) { + playedStation = savedPlaylist.get(0); + return ("Radio is playing station: 01 " + this.playedStation + " from saved playlist"); + } else { + playedStation = savedPlaylist.get(itemNr - 1); + return ("Radio is playing station: 0" + (savedPlaylist.indexOf(playedStation) + 1) + " " + this.playedStation + " from saved playlist"); + } } } diff --git a/src/test/java/device/radioPlayer/RadioPlayerTest.java b/src/test/java/device/radioPlayer/RadioPlayerTest.java index 6e6121c..db2b35c 100644 --- a/src/test/java/device/radioPlayer/RadioPlayerTest.java +++ b/src/test/java/device/radioPlayer/RadioPlayerTest.java @@ -187,11 +187,15 @@ class RadioPlayerTest { rp1.chooseItem(5); RadioPlayer rp2 = new RadioPlayer(); rp2.chooseItem(-1); + RadioPlayer rp3 = new RadioPlayer(); + rp3.changeRegion("BY"); + rp3.chooseItem(2); return Stream.of( Arguments.of("Test select station in saved playlist to play with nr isn`t bigger than playlist size", rp, "Teddy"), Arguments.of("Test select station in saved playlist to play with nr is bigger than playlist size. Last station in playlist gets played", rp1, "MegaHits"), - Arguments.of("Test select station in saved playlist to play with nr is lower than 0. First station in playlist gets played", rp2, "YouFM") + Arguments.of("Test select station in saved playlist to play with nr is lower than 0. First station in playlist gets played", rp2, "YouFM"), + Arguments.of("Test select station in regional playlist to play with nr isn`t bigger than playlist size", rp3, "Bayern 1") ); }