Browse Source

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

feature-pr-changeOrderInSavedPlaylist
Jan Ortner 3 years ago
parent
commit
0cc9fe4b88
  1. 11
      src/main/java/device/radioPlayer/RadioPlayer.java
  2. 6
      src/test/java/device/radioPlayer/RadioPlayerTest.java

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

@ -216,11 +216,16 @@ public class RadioPlayer implements Device {
if((nr-1) > savedPlaylist.size()) { if((nr-1) > savedPlaylist.size()) {
savedPlaylist.remove(playedStation); savedPlaylist.remove(playedStation);
savedPlaylist.add(savedPlaylist.size(),station); savedPlaylist.add(savedPlaylist.size(),station);
return"Station " + playedStation + " is now on place 0" + nr + "in saved playlist";
} else {
return"Station " + playedStation + " is now on place 0" + (savedPlaylist.size()+1) + "in saved playlist";
}else if(nr < 0) {
savedPlaylist.remove(playedStation);
savedPlaylist.add(0,station);
return"Station " + playedStation + " is now on place 01 in saved playlist";
}
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" + (savedPlaylist.size()+1) + "in saved playlist";
return "Station " + playedStation + " is now on place 0" + nr + "in saved playlist";
} }
} }
} }

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

@ -279,10 +279,14 @@ class RadioPlayerTest {
rp.changeOrderInSavedPlaylist(1); rp.changeOrderInSavedPlaylist(1);
RadioPlayer rp1 = new RadioPlayer(); RadioPlayer rp1 = new RadioPlayer();
rp1.changeOrderInSavedPlaylist(5); rp1.changeOrderInSavedPlaylist(5);
RadioPlayer rp2 = new RadioPlayer();
rp2.next();
rp2.changeOrderInSavedPlaylist(-1);
return Stream.of( return Stream.of(
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 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")
Arguments.of("Test for change order in saved playlist with nr is than bigger playlist size put at the end of playlist", rp1, 2, "YouFM"),
Arguments.of("Test for change order in saved playlist with nr is than smaller than 0 at front of playlist", rp2, 0, "Teddy")
); );
} }
} }
Loading…
Cancel
Save