Browse Source

added third test case for chooseItem() & and added productive code for RadioPlayer

feature-pr-RadioPlayer-chooseItem
Jan Ortner 3 years ago
parent
commit
cd09cb8775
  1. 7
      src/main/java/device/radioPlayer/RadioPlayer.java
  2. 5
      src/test/java/device/radioPlayer/RadioPlayerTest.java

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

@ -161,9 +161,13 @@ public class RadioPlayer implements Device {
if (itemNr > savedPlaylist.size()) { if (itemNr > savedPlaylist.size()) {
playedStation = savedPlaylist.get(savedPlaylist.size() - 1); playedStation = savedPlaylist.get(savedPlaylist.size() - 1);
return ("Radio is playing station: 0" + savedPlaylist.size() + " " + this.playedStation + " from saved playlist"); 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 { } else {
playedStation = savedPlaylist.get(itemNr - 1); playedStation = savedPlaylist.get(itemNr - 1);
return ("Radio is playing station: 0" + (savedPlaylist.indexOf(playedStation) + 1) + " " + this.playedStation + " from saved playlist"); return ("Radio is playing station: 0" + (savedPlaylist.indexOf(playedStation) + 1) + " " + this.playedStation + " from saved playlist");
} }
} }
@ -232,8 +236,7 @@ public class RadioPlayer implements Device {
savedPlaylist.remove(playedStation); savedPlaylist.remove(playedStation);
savedPlaylist.add(0, station); savedPlaylist.add(0, station);
return "Station " + playedStation + " is now on place 01 in saved playlist"; return "Station " + playedStation + " is now on place 01 in saved playlist";
}
else {
} else {
savedPlaylist.remove(playedStation); savedPlaylist.remove(playedStation);
savedPlaylist.add(nr - 1, station); savedPlaylist.add(nr - 1, station);
return "Station " + playedStation + " is now on place 0" + nr + "in saved playlist"; return "Station " + playedStation + " is now on place 0" + nr + "in saved playlist";

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

@ -185,10 +185,13 @@ class RadioPlayerTest {
rp.chooseItem(2); rp.chooseItem(2);
RadioPlayer rp1 = new RadioPlayer(); RadioPlayer rp1 = new RadioPlayer();
rp1.chooseItem(5); rp1.chooseItem(5);
RadioPlayer rp2 = new RadioPlayer();
rp2.chooseItem(-1);
return Stream.of( 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 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 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")
); );
} }

Loading…
Cancel
Save