Browse Source

Merge commit '9ca1d2a492283b9860b6d2a40adeb4596db5d13c' into HEAD

feature-pr-cdPlayer-showStationInfo
Jenkins 3 years ago
parent
commit
af8d3066c4
  1. 12
      src/main/java/device/radioPlayer/RadioPlayer.java
  2. 49
      src/test/java/device/radioPlayer/RadioPlayerTest.java

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

@ -2,8 +2,10 @@ package device.radioPlayer;
import device.Device;
import java.lang.reflect.Method;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
public class RadioPlayer implements Device {
@ -149,19 +151,23 @@ public class RadioPlayer implements Device {
@Override
public String getInfoText() {
if(showStationInfo().equals("")) return buildInfoText();
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);
if (regionPlaylist.contains(playedStation))
return ("Regional playlist: " + (regionPlaylist.indexOf(playedStation) + 1) + infoText);
else return ("Saved playlist: " + (savedPlaylist.indexOf(playedStation) + 1) + infoText);
}
@Override
public String[] getOptions() {
return new String[0];
Method[] methods = this.getClass().getDeclaredMethods();
String[] returnMethods = Arrays.stream(methods).map(Method::getName).toArray(String[]::new);
return returnMethods;
}
@Override

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

@ -1,12 +1,17 @@
package device.radioPlayer;
import device.Device;
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;
import org.junit.jupiter.params.provider.MethodSource;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;
import static org.assertj.core.api.Assertions.assertThat;
@ -366,8 +371,9 @@ class RadioPlayerTest {
Arguments.of("Test for mute RadioPlayer if volume is saved before muting", "saved", rp1, 30)
);
}
@Test
void TestUnmute() {
void testUnmute() {
RadioPlayer rp = new RadioPlayer();
rp.setLautstaerke(40);
rp.mute();
@ -379,13 +385,15 @@ class RadioPlayerTest {
@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");
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);
@ -418,4 +426,29 @@ class RadioPlayerTest {
Arguments.of("Test for getInfoText not contains station info if station not has one", "noStationInfo", rp7, false)
);
}
@ParameterizedTest
@MethodSource("getOptionsOptions")
void testGetOptions(String testName, String testTyp, RadioPlayer testRp) {
if (testTyp.equals("notNull")) assertThat(testRp.getOptions()).describedAs(testName).isNotEqualTo(null);
if (testTyp.equals("arrayLengthGreater0"))
assertThat(testRp.getOptions().length).describedAs(testName).isNotEqualTo(0);
else {
Method[] interfaceMethods = Device.class.getDeclaredMethods();
List<String> deviceMethods = new ArrayList<>(Arrays.asList(testRp.getOptions()));
for (Method interfaceMethod : interfaceMethods) {
assertThat(deviceMethods.contains(interfaceMethod.getName())).describedAs(testName).isEqualTo(true);
}
}
}
static Stream<Arguments> getOptionsOptions() {
RadioPlayer rp = new RadioPlayer();
return Stream.of(
Arguments.of("returnValue of getOptions is not null", "notNull", rp),
Arguments.of("should not return an empty array", "arrayLengthGreater0", rp),
Arguments.of("Test if all methods declared in interface device are available", "device", rp)
);
}
}
Loading…
Cancel
Save