From 74fa5f4bb6e58e5fb312d97159a832c3bd88cd09 Mon Sep 17 00:00:00 2001 From: alpina0707 Date: Mon, 14 Feb 2022 21:49:02 +0100 Subject: [PATCH] added new test case for prev() & changed prev() to work with regional and saved stations --- .../java/device/radioPlayer/RadioPlayer.java | 21 ++++++++++++++----- .../device/radioPlayer/RadioPlayerTest.java | 6 +++++- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/main/java/device/radioPlayer/RadioPlayer.java b/src/main/java/device/radioPlayer/RadioPlayer.java index 898cea0..6f68676 100644 --- a/src/main/java/device/radioPlayer/RadioPlayer.java +++ b/src/main/java/device/radioPlayer/RadioPlayer.java @@ -127,12 +127,23 @@ public class RadioPlayer implements Device { @Override public void prev() { - int currentIndex = savedPlaylist.indexOf(playedStation); - int nextIndex = savedPlaylist.size() - 1; - if (currentIndex != 0) { - nextIndex = (currentIndex - 1); + if (regionPlaylist.contains(playedStation)) { + int currentIndex = regionPlaylist.indexOf(playedStation); + int nextIndex = regionPlaylist.size() - 1; + if (currentIndex != 0) { + nextIndex = (currentIndex - 1); + } + playedStation = regionPlaylist.get(nextIndex); + } else { + { + int currentIndex = savedPlaylist.indexOf(playedStation); + int nextIndex = savedPlaylist.size() - 1; + if (currentIndex != 0) { + nextIndex = (currentIndex - 1); + } + playedStation = savedPlaylist.get(nextIndex); + } } - playedStation = savedPlaylist.get(nextIndex); } @Override diff --git a/src/test/java/device/radioPlayer/RadioPlayerTest.java b/src/test/java/device/radioPlayer/RadioPlayerTest.java index 6dc3db6..fcf7b3a 100644 --- a/src/test/java/device/radioPlayer/RadioPlayerTest.java +++ b/src/test/java/device/radioPlayer/RadioPlayerTest.java @@ -76,17 +76,21 @@ class RadioPlayerTest { RadioPlayer rp2 = new RadioPlayer(); RadioPlayer rp3 = new RadioPlayer(); RadioPlayer rp4 = new RadioPlayer(); + RadioPlayer rp5 = new RadioPlayer(); rp1.next(); rp2.next(); rp2.prev(); rp3.prev(); rp4.changeRegion("BY"); rp4.next(); + rp5.changeRegion("BY"); + rp5.prev(); 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 next station", rp4, "Bayern 1"), + Arguments.of("changed Region and going to prev station", rp5, "Hit Radio N1") ); }