Browse Source

added new test case for deleteStation() & code for saved station delete until there is only one station in savedPlaylist

feature-pr-deleteStation
Jan Ortner 3 years ago
parent
commit
2b0ee697b6
  1. 14
      src/main/java/device/radioPlayer/RadioPlayer.java
  2. 29
      src/test/java/device/radioPlayer/RadioPlayerTest.java

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

@ -187,9 +187,19 @@ public class RadioPlayer implements Device {
public String saveStation() {
if (savedPlaylist.contains(playedStation)) return "Station " + playedStation + " is already saved";
else
savedPlaylist.add(playedStation);
else savedPlaylist.add(playedStation);
regionPlaylist.clear();
return "Station " + playedStation + " is saved in your Station list";
}
public String deleteStation() {
String station = playedStation;
if ((savedPlaylist.size()) > 1) {
savedPlaylist.remove(playedStation);
playedStation = savedPlaylist.get(0);
return "Station: 0" + (savedPlaylist.indexOf(playedStation) + 1) + " " + station + " has been deleted";
} else return " Last Station: 01 " + station + " can´t by deleted";
}
}

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

@ -196,11 +196,11 @@ class RadioPlayerTest {
@ParameterizedTest
@MethodSource("saveStationOptions")
void testSaveStation(String testName, RadioPlayer testRp,String testTyp, String expectedResult) {
void testSaveStation(String testName, RadioPlayer testRp, String testTyp, String expectedResult) {
String savedStation;
if (testTyp.equals("normal")) {
savedStation = testRp.savedPlaylist.get(testRp.savedPlaylist.size() - 1);}
else savedStation = Boolean.toString(testRp.regionPlaylist.isEmpty());
savedStation = testRp.savedPlaylist.get(testRp.savedPlaylist.size() - 1);
} else savedStation = Boolean.toString(testRp.regionPlaylist.isEmpty());
assertThat(savedStation).describedAs(testName).isEqualTo(expectedResult);
}
@ -221,4 +221,27 @@ class RadioPlayerTest {
);
}
@ParameterizedTest
@MethodSource("deleteStationOptions")
void testDeleteStation(String testName, RadioPlayer testRp, String testTyp, Boolean expectedResult) {
Boolean savedStation;
if (testTyp.equals("delete")) {
savedStation = testRp.savedPlaylist.contains("YouFM");
} else savedStation = testRp.savedPlaylist.contains("MegaHits");
assertThat(savedStation).describedAs(testName).isEqualTo(expectedResult);
}
static Stream<Arguments> deleteStationOptions() {
RadioPlayer rp = new RadioPlayer();
rp.deleteStation();
RadioPlayer rp1 = new RadioPlayer();
rp1.deleteStation();
rp1.deleteStation();
rp1.deleteStation();
return Stream.of(
Arguments.of("Test for delete station in saved playlist", rp, "delete", false),
Arguments.of("Test for not delete station in saved playlist if this is the last station", rp1, "noDelete", true)
);
}
}
Loading…
Cancel
Save