Browse Source

added second test case for changeOrderInSavedPlaylist() & and added productive code

feature-pr-changeOrderInSavedPlaylist
Jan Ortner 3 years ago
parent
commit
6776f0b752
  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

@ -213,8 +213,14 @@ public class RadioPlayer implements Device {
public String changeOrderInSavedPlaylist(int nr) { public String changeOrderInSavedPlaylist(int nr) {
String station = playedStation; String station = playedStation;
if((nr-1) > savedPlaylist.size()) {
savedPlaylist.remove(playedStation); savedPlaylist.remove(playedStation);
savedPlaylist.add(nr-1,station);
savedPlaylist.add(savedPlaylist.size(),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";
} else {
savedPlaylist.remove(playedStation);
savedPlaylist.add(nr - 1, station);
return "Station " + playedStation + " is now on place 0" + (savedPlaylist.size()+1) + "in saved playlist";
}
} }
} }

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

@ -277,9 +277,12 @@ class RadioPlayerTest {
RadioPlayer rp = new RadioPlayer(); RadioPlayer rp = new RadioPlayer();
rp.next(); rp.next();
rp.changeOrderInSavedPlaylist(1); rp.changeOrderInSavedPlaylist(1);
RadioPlayer rp1 = new RadioPlayer();
rp1.changeOrderInSavedPlaylist(5);
return Stream.of( return Stream.of(
Arguments.of("Test for change order in saved playlist with nr isn`t than playlist size", rp, 0, "Teddy")
Arguments.of("Test for change order in saved playlist with nr isn`t bigger than playlist size", rp, 0, "Teddy"),
Arguments.of("Test for change order in saved playlist with nr is than bigger playlist size but at the end of playlist", rp1, 2, "YouFM")
); );
} }
} }
Loading…
Cancel
Save