Browse Source

added new test case for saveStation & changed saveStation() to jump back to savedPlaylist after station is saved

feature-pr-saveStations
Jan Ortner 3 years ago
parent
commit
9f78d7aa9b
  1. 1
      src/main/java/device/radioPlayer/RadioPlayer.java
  2. 23
      src/test/java/device/radioPlayer/RadioPlayerTest.java

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

@ -186,6 +186,7 @@ public class RadioPlayer implements Device {
if (savedPlaylist.contains(playedStation)) return "Station " + playedStation + " is already saved";
else
savedPlaylist.add(playedStation);
regionPlaylist.clear();
return "Station " + playedStation + " is saved in your Station list";
}
}

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

@ -77,6 +77,7 @@ class RadioPlayerTest {
RadioPlayer rp3 = new RadioPlayer();
RadioPlayer rp4 = new RadioPlayer();
RadioPlayer rp5 = new RadioPlayer();
RadioPlayer rp6 = new RadioPlayer();
rp1.next();
rp2.next();
rp2.prev();
@ -85,12 +86,17 @@ class RadioPlayerTest {
rp4.next();
rp5.changeRegion("BY");
rp5.prev();
rp6.changeRegion("BY");
rp6.saveStation();
rp6.next();
return Stream.of(
Arguments.of("Next Station Test for saved Stations", rp1, "Teddy"),
Arguments.of("Prev Station Test for saved Stations", rp2, "YouFM"),
Arguments.of("Prev works on first Station for saved Stations", rp3, "MegaHits"),
Arguments.of("changed Region and going to next station", rp4, "Bayern 1"),
Arguments.of("changed Region and going to prev station", rp5, "Hit Radio N1")
Arguments.of("changed Region and going to prev station", rp5, "Hit Radio N1"),
Arguments.of("changed Region, saved station and going to next station", rp6, "YouFM")
);
}
@ -187,21 +193,28 @@ class RadioPlayerTest {
@ParameterizedTest
@MethodSource("saveStationOptions")
void testSaveStation(String testName, RadioPlayer testRp, String expectedResult) {
String savedStation = testRp.savedPlaylist.get(testRp.savedPlaylist.size() - 1);
void testSaveStation(String testName, RadioPlayer testRp,String testTyp, String expectedResult) {
String savedStation;
if (testTyp == "normal") {
savedStation = testRp.savedPlaylist.get(testRp.savedPlaylist.size() - 1);}
else savedStation = Boolean.toString(testRp.regionPlaylist.isEmpty());
assertThat(savedStation).describedAs(testName).isEqualTo(expectedResult);
}
static Stream<Arguments> saveStationOptions() {
RadioPlayer rp1 = new RadioPlayer();
RadioPlayer rp2 = new RadioPlayer();
RadioPlayer rp3 = new RadioPlayer();
rp1.changeRegion("BY");
rp1.saveStation();
rp2.saveStation();
rp3.changeRegion("BY");
rp3.saveStation();
return Stream.of(
Arguments.of("Test for saving station in saved playlist", rp1, "Antenne Bayern"),
Arguments.of("Test for not saving station which is already in saved playlist", rp2, "MegaHits")
Arguments.of("Test for saving station in saved playlist", rp1, "normal", "Antenne Bayern"),
Arguments.of("Test for not saving station which is already in saved playlist", rp2, "normal", "MegaHits"),
Arguments.of("Test for after saving station jump back to saved playlist", rp3, "jump", "true")
);
}
Loading…
Cancel
Save