From f99a208c8ee9180f5a2c3fce3d0df3ecea76bd47 Mon Sep 17 00:00:00 2001 From: alpina0707 Date: Mon, 14 Feb 2022 21:35:42 +0100 Subject: [PATCH] added new test case for next() & changed next() to work with regional and saved stations --- src/main/java/device/radioPlayer/RadioPlayer.java | 12 +++++++++--- .../java/device/radioPlayer/RadioPlayerTest.java | 10 +++++++--- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/main/java/device/radioPlayer/RadioPlayer.java b/src/main/java/device/radioPlayer/RadioPlayer.java index 479463f..898cea0 100644 --- a/src/main/java/device/radioPlayer/RadioPlayer.java +++ b/src/main/java/device/radioPlayer/RadioPlayer.java @@ -114,9 +114,15 @@ public class RadioPlayer implements Device { @Override public void next() { - int currentIndex = savedPlaylist.indexOf(playedStation); - int nextIndex = (currentIndex + 1) % savedPlaylist.size(); - playedStation = savedPlaylist.get(nextIndex); + if (regionPlaylist.contains(playedStation)){ + int currentIndex = regionPlaylist.indexOf(playedStation); + int nextIndex = (currentIndex + 1) % regionPlaylist.size(); + playedStation = regionPlaylist.get(nextIndex); + } else { + int currentIndex = savedPlaylist.indexOf(playedStation); + int nextIndex = (currentIndex + 1) % savedPlaylist.size(); + playedStation = savedPlaylist.get(nextIndex); + } } @Override diff --git a/src/test/java/device/radioPlayer/RadioPlayerTest.java b/src/test/java/device/radioPlayer/RadioPlayerTest.java index b880afa..6dc3db6 100644 --- a/src/test/java/device/radioPlayer/RadioPlayerTest.java +++ b/src/test/java/device/radioPlayer/RadioPlayerTest.java @@ -75,14 +75,18 @@ class RadioPlayerTest { RadioPlayer rp1 = new RadioPlayer(); RadioPlayer rp2 = new RadioPlayer(); RadioPlayer rp3 = new RadioPlayer(); + RadioPlayer rp4 = new RadioPlayer(); rp1.next(); rp2.next(); rp2.prev(); rp3.prev(); + rp4.changeRegion("BY"); + rp4.next(); return Stream.of( - Arguments.of("Next Station Test", rp1, "Teddy"), - Arguments.of("Prev Station Test", rp2, "YouFM"), - Arguments.of("Prev works on first Station ", rp3, "MegaHits") + 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") ); }