Browse Source

added third test case for RadioPlayer getOptions()

feature-pr-RadioPlayer-getOptions
Jan Ortner 2 years ago
parent
commit
9ca1d2a492
  1. 5
      src/main/java/device/radioPlayer/RadioPlayer.java
  2. 40
      src/test/java/device/radioPlayer/RadioPlayerTest.java

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

@ -151,13 +151,14 @@ public class RadioPlayer implements Device {
@Override @Override
public String getInfoText() { public String getInfoText() {
if(showStationInfo().equals("")) return buildInfoText();
if (showStationInfo().equals("")) return buildInfoText();
return (buildInfoText() + "\n Now playing: " + showStationInfo()); return (buildInfoText() + "\n Now playing: " + showStationInfo());
} }
private String buildInfoText() { private String buildInfoText() {
String infoText = playedStation; 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); else return ("Saved playlist: " + (savedPlaylist.indexOf(playedStation) + 1) + infoText);
} }

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

@ -1,12 +1,17 @@
package device.radioPlayer; package device.radioPlayer;
import device.Device;
import org.assertj.core.util.Strings; import org.assertj.core.util.Strings;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource; 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 java.util.stream.Stream;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
@ -366,6 +371,7 @@ class RadioPlayerTest {
Arguments.of("Test for mute RadioPlayer if volume is saved before muting", "saved", rp1, 30) Arguments.of("Test for mute RadioPlayer if volume is saved before muting", "saved", rp1, 30)
); );
} }
@Test @Test
void testUnmute() { void testUnmute() {
RadioPlayer rp = new RadioPlayer(); RadioPlayer rp = new RadioPlayer();
@ -379,13 +385,15 @@ class RadioPlayerTest {
@MethodSource("getInfoTextOptions") @MethodSource("getInfoTextOptions")
void testGetInfoText(String testName, String testTyp, RadioPlayer testRp, boolean expectedResult) { void testGetInfoText(String testName, String testTyp, RadioPlayer testRp, boolean expectedResult) {
Boolean bool; 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"); else bool = testRp.getInfoText().contains("Now playing");
assertThat(bool).describedAs(testName).isEqualTo(expectedResult); assertThat(bool).describedAs(testName).isEqualTo(expectedResult);
@ -418,11 +426,20 @@ class RadioPlayerTest {
Arguments.of("Test for getInfoText not contains station info if station not has one", "noStationInfo", rp7, false) Arguments.of("Test for getInfoText not contains station info if station not has one", "noStationInfo", rp7, false)
); );
} }
@ParameterizedTest @ParameterizedTest
@MethodSource("getOptionsOptions") @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);
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() { static Stream<Arguments> getOptionsOptions() {
@ -430,7 +447,8 @@ class RadioPlayerTest {
return Stream.of( return Stream.of(
Arguments.of("returnValue of getOptions is not null", "notNull", rp), Arguments.of("returnValue of getOptions is not null", "notNull", rp),
Arguments.of("should not return an empty array", "arrayLengthGreater0", 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