Browse Source

Merge commit '2b0ee697b60772cc5871b04c9ca71ceddfabecb2' into HEAD

feature-pr-changeToSavedPlaylist
Jenkins 3 years ago
parent
commit
2ce7da7c02
  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() { public String saveStation() {
if (savedPlaylist.contains(playedStation)) return "Station " + playedStation + " is already saved"; if (savedPlaylist.contains(playedStation)) return "Station " + playedStation + " is already saved";
else
savedPlaylist.add(playedStation);
else savedPlaylist.add(playedStation);
regionPlaylist.clear(); regionPlaylist.clear();
return "Station " + playedStation + " is saved in your Station list"; 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 @ParameterizedTest
@MethodSource("saveStationOptions") @MethodSource("saveStationOptions")
void testSaveStation(String testName, RadioPlayer testRp,String testTyp, String expectedResult) {
void testSaveStation(String testName, RadioPlayer testRp, String testTyp, String expectedResult) {
String savedStation; String savedStation;
if (testTyp.equals("normal")) { 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); 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