Browse Source

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

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

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

@ -158,8 +158,13 @@ public class RadioPlayer implements Device {
@Override @Override
public String chooseItem(int itemNr) { public String chooseItem(int itemNr) {
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{
playedStation = savedPlaylist.get(itemNr - 1);
return ("Radio is playing station: 0" + (savedPlaylist.indexOf(playedStation) + 1) + " " + this.playedStation + " from saved playlist");
}
} }
@Override @Override

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

@ -183,9 +183,12 @@ class RadioPlayerTest {
static Stream<Arguments> chooseItemOptions() { static Stream<Arguments> chooseItemOptions() {
RadioPlayer rp = new RadioPlayer(); RadioPlayer rp = new RadioPlayer();
rp.chooseItem(2); rp.chooseItem(2);
RadioPlayer rp1 = new RadioPlayer();
rp1.chooseItem(5);
return Stream.of( return Stream.of(
Arguments.of("Test select station 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")
); );
} }

Loading…
Cancel
Save