Browse Source

added second test case for RadioPlayer getOptions() & added productive code

feature-pr-RadioPlayer-getOptions
Jan Ortner 3 years ago
parent
commit
f6361c27b8
  1. 7
      src/main/java/device/radioPlayer/RadioPlayer.java
  2. 11
      src/test/java/device/radioPlayer/RadioPlayerTest.java

7
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 {
@ -161,7 +163,10 @@ public class RadioPlayer implements Device {
@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

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

@ -420,18 +420,17 @@ class RadioPlayerTest {
}
@ParameterizedTest
@MethodSource("getOptionsOptions")
void testGetOptions(String testName, RadioPlayer testRp) {
assertThat(testRp.getOptions()).describedAs(testName).isNotEqualTo(null);
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);
}
static Stream<Arguments> getOptionsOptions() {
RadioPlayer rp = new RadioPlayer();
return Stream.of(
Arguments.of("returnValue of getOptions is not null", rp)
Arguments.of("returnValue of getOptions is not null", "notNull", rp),
Arguments.of("should not return an empty array", "arrayLengthGreater0", rp)
);
}
}
Loading…
Cancel
Save