|
@ -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(); |
|
@ -383,8 +389,10 @@ class RadioPlayerTest { |
|
|
else if (testTyp.contains("station")) bool = testRp.getInfoText().contains(testRp.playedStation); |
|
|
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("region")) bool = testRp.getInfoText().contains("Regional playlist"); |
|
|
else if (testTyp.contains("saved")) bool = testRp.getInfoText().contains("Saved 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("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 if (testTyp.contains("stationInfo")) bool = testRp.getInfoText().contains("Now playing"); |
|
|
else bool = testRp.getInfoText().contains("Now playing"); |
|
|
else bool = testRp.getInfoText().contains("Now playing"); |
|
|
|
|
|
|
|
@ -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) { |
|
|
void testGetOptions(String testName, String testTyp, RadioPlayer testRp) { |
|
|
if (testTyp.equals("notNull")) assertThat(testRp.getOptions()).describedAs(testName).isNotEqualTo(null); |
|
|
if (testTyp.equals("notNull")) assertThat(testRp.getOptions()).describedAs(testName).isNotEqualTo(null); |
|
|
if(testTyp.equals("arrayLengthGreater0")) assertThat(testRp.getOptions().length).describedAs(testName).isNotEqualTo(0); |
|
|
|
|
|
|
|
|
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) |
|
|
); |
|
|
); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |