Browse Source

added second test case for getItemList() & and added productive code for RadioPlayer

feature-pr-RadioPlayer-getItemList
Jan Ortner 3 years ago
parent
commit
b7b79badda
  1. 3
      src/main/java/device/radioPlayer/RadioPlayer.java
  2. 12
      src/test/java/device/radioPlayer/RadioPlayerTest.java

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

@ -185,6 +185,9 @@ public class RadioPlayer implements Device {
@Override @Override
public String[] getItemList() { public String[] getItemList() {
if (regionPlaylist.contains(playedStation))
return regionPlaylist.toArray(new String[0]);
else
return savedPlaylist.toArray(new String[0]); return savedPlaylist.toArray(new String[0]);
} }

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

@ -320,18 +320,26 @@ class RadioPlayerTest {
Arguments.of("Test for change order in saved playlist with nr is than smaller than 0 at front of playlist", rp2, 0, "Teddy") Arguments.of("Test for change order in saved playlist with nr is than smaller than 0 at front of playlist", rp2, 0, "Teddy")
); );
} }
@ParameterizedTest @ParameterizedTest
@MethodSource("getItemListOptions") @MethodSource("getItemListOptions")
void testGetItemList(String testName, RadioPlayer testRp, String[] expectedResult) {
void testGetItemList(String testName, RadioPlayer testRp, String testTyp, String[] expectedResult) {
if (testTyp.equals("region")) {
testRp.changeRegion("BY");
}
String[] playList = testRp.getItemList(); String[] playList = testRp.getItemList();
assertThat(playList).describedAs(testName).isEqualTo(expectedResult); assertThat(playList).describedAs(testName).isEqualTo(expectedResult);
} }
static Stream<Arguments> getItemListOptions() { static Stream<Arguments> getItemListOptions() {
RadioPlayer rp = new RadioPlayer(); RadioPlayer rp = new RadioPlayer();
RadioPlayer rp1 = new RadioPlayer();
rp1.changeRegion("BY");
return Stream.of( return Stream.of(
Arguments.of("Test for return saved playlist", rp, rp.savedPlaylist.toArray(new String[0]))
Arguments.of("Test for return saved playlist", rp, "saved", rp.savedPlaylist.toArray(new String[0])),
Arguments.of("Test for return regional playlist", rp1, "region", rp1.regionPlaylist.toArray(new String[0]))
); );
} }
} }
Loading…
Cancel
Save