Browse Source

Merge commit '561d5f6bc27a64088b1bc2d52587508230337ab3' into HEAD

feature-pr-RadioPlayer-getOptions
Jenkins 3 years ago
parent
commit
e9946609b5
  1. 9
      src/main/java/device/radioPlayer/RadioPlayer.java
  2. 45
      src/test/java/device/radioPlayer/RadioPlayerTest.java

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

@ -149,7 +149,14 @@ public class RadioPlayer implements Device {
@Override
public String getInfoText() {
return null;
if(showStationInfo().equals("")) return buildInfoText();
return (buildInfoText() + "\n Now playing: " + showStationInfo());
}
private String buildInfoText() {
String infoText = playedStation;
if(regionPlaylist.contains(playedStation)) return ("Regional playlist: " + (regionPlaylist.indexOf(playedStation) + 1) + infoText);
else return ("Saved playlist: " + (savedPlaylist.indexOf(playedStation) + 1) + infoText);
}
@Override

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

@ -1,6 +1,7 @@
package device.radioPlayer;
import org.assertj.core.util.Strings;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
@ -373,4 +374,48 @@ class RadioPlayerTest {
rp.unmute();
assertThat(rp.getVolume()).describedAs("Test if unmute is setting the saved volume").isEqualTo(rp.savedVolume);
}
@ParameterizedTest
@MethodSource("getInfoTextOptions")
void testGetInfoText(String testName, String testTyp, RadioPlayer testRp, boolean expectedResult) {
Boolean bool;
if(testTyp.equals("null")) bool = Strings.isNullOrEmpty(testRp.getInfoText());
else if(testTyp.contains("station")) bool = testRp.getInfoText().contains(testRp.playedStation);
else if(testTyp.contains("region")) bool = testRp.getInfoText().contains("Regional playlist");
else if(testTyp.contains("saved")) bool = testRp.getInfoText().contains("Saved playlist");
else if(testTyp.contains("savedNum")) bool = testRp.getInfoText().contains(("0") + testRp.savedPlaylist.indexOf(testRp.playedStation) + 1);
else if(testTyp.contains("regionNum")) bool = testRp.getInfoText().contains(("0") + testRp.regionPlaylist.indexOf(testRp.playedStation) + 1);
else if(testTyp.contains("stationInfo")) bool = testRp.getInfoText().contains("Now playing");
else bool = testRp.getInfoText().contains("Now playing");
assertThat(bool).describedAs(testName).isEqualTo(expectedResult);
}
static Stream<Arguments> getInfoTextOptions() {
RadioPlayer rp = new RadioPlayer();
RadioPlayer rp1 = new RadioPlayer();
RadioPlayer rp2 = new RadioPlayer();
rp2.changeRegion("BY");
RadioPlayer rp3 = new RadioPlayer();
RadioPlayer rp4 = new RadioPlayer();
rp4.next();
RadioPlayer rp5 = new RadioPlayer();
rp5.changeRegion("HE");
rp5.next();
RadioPlayer rp6 = new RadioPlayer();
rp6.changeRegion("BY");
RadioPlayer rp7 = new RadioPlayer();
rp7.next();
return Stream.of(
Arguments.of("Test for getInfoText is not empty or null", "null", rp, false),
Arguments.of("Test for getInfoText contains played station", "station", rp1, true),
Arguments.of("Test for getInfoText contains regional playlist if played station is in it", "region", rp2, true),
Arguments.of("Test for getInfoText contains saved playlist if played station is in it", "saved", rp3, true),
Arguments.of("Test for getInfoText contains station number in saved playlist", "savedNum", rp4, true),
Arguments.of("Test for getInfoText contains station number in regional playlist", "regionNum", rp5, true),
Arguments.of("Test for getInfoText contains station info if station has one", "stationInfo", rp6, true),
Arguments.of("Test for getInfoText not contains station info if station not has one", "noStationInfo", rp7, false)
);
}
}
Loading…
Cancel
Save