Browse Source

added new test case for saveStation & changed saveStation() to not saving duplicate stations

feature-pr-saveStations
Jan Ortner 3 years ago
parent
commit
ecf5a3e4ad
  1. 8
      src/main/java/device/radioPlayer/RadioPlayer.java
  2. 5
      src/test/java/device/radioPlayer/RadioPlayerTest.java

8
src/main/java/device/radioPlayer/RadioPlayer.java

@ -114,7 +114,7 @@ public class RadioPlayer implements Device {
@Override
public void next() {
if (regionPlaylist.contains(playedStation)){
if (regionPlaylist.contains(playedStation)) {
int currentIndex = regionPlaylist.indexOf(playedStation);
int nextIndex = (currentIndex + 1) % regionPlaylist.size();
playedStation = regionPlaylist.get(nextIndex);
@ -183,7 +183,9 @@ public class RadioPlayer implements Device {
}
public String saveStation() {
savedPlaylist.add(playedStation);
return "";
if (savedPlaylist.contains(playedStation)) return "Station " + playedStation + " is already saved";
else
savedPlaylist.add(playedStation);
return "Station " + playedStation + " is saved in your Station list";
}
}

5
src/test/java/device/radioPlayer/RadioPlayerTest.java

@ -194,11 +194,14 @@ class RadioPlayerTest {
static Stream<Arguments> saveStationOptions() {
RadioPlayer rp1 = new RadioPlayer();
RadioPlayer rp2 = new RadioPlayer();
rp1.changeRegion("BY");
rp1.saveStation();
rp2.saveStation();
return Stream.of(
Arguments.of("Test for saving station in saved playlist", rp1, "Antenne Bayern")
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")
);
}
Loading…
Cancel
Save