From f6361c27b82eb63c2c57f2b6e5eae88a1c705811 Mon Sep 17 00:00:00 2001 From: alpina0707 Date: Thu, 17 Feb 2022 01:09:58 +0100 Subject: [PATCH] added second test case for RadioPlayer getOptions() & added productive code --- src/main/java/device/radioPlayer/RadioPlayer.java | 7 ++++++- src/test/java/device/radioPlayer/RadioPlayerTest.java | 11 +++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/main/java/device/radioPlayer/RadioPlayer.java b/src/main/java/device/radioPlayer/RadioPlayer.java index 7dcc37a..669d9c1 100644 --- a/src/main/java/device/radioPlayer/RadioPlayer.java +++ b/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 diff --git a/src/test/java/device/radioPlayer/RadioPlayerTest.java b/src/test/java/device/radioPlayer/RadioPlayerTest.java index b7cae0c..23078bb 100644 --- a/src/test/java/device/radioPlayer/RadioPlayerTest.java +++ b/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 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) ); } } \ No newline at end of file