From 63db5393e8846bedaf0c237f6ffa6cf4043444a8 Mon Sep 17 00:00:00 2001 From: JPANZO Date: Tue, 15 Feb 2022 22:51:15 +0100 Subject: [PATCH 1/3] getOptions from CDPlayer tested on ArrayContainsInterfaceMethods. --- .../java/device/cdPlayer/CDPlayerTest.java | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/test/java/device/cdPlayer/CDPlayerTest.java b/src/test/java/device/cdPlayer/CDPlayerTest.java index dd985ed..56646dc 100644 --- a/src/test/java/device/cdPlayer/CDPlayerTest.java +++ b/src/test/java/device/cdPlayer/CDPlayerTest.java @@ -1,5 +1,6 @@ package device.cdPlayer; +import device.Device; import device.cdPlayer.exceptions.*; import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.params.ParameterizedTest; @@ -7,6 +8,10 @@ import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; import org.mockito.junit.jupiter.MockitoExtension; +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; @@ -231,19 +236,30 @@ class CDPlayerTest { @ParameterizedTest @MethodSource("getOptionsTestData") - void getOptionsTest(String testName,String testDirection, CDPlayer _cdPlayer, String expectedResult){ + void getOptionsTest(String testName,String testDirection, CDPlayer _cdPlayer){ if(testDirection.equals("ReturnValueNotNull")) { assertThat(_cdPlayer.getOptions()).describedAs(testName).isNotEqualTo(null); } if(testDirection.equals("ArrayLengthGreaterThen0")) { assertThat(_cdPlayer.getOptions().length).describedAs(testName).isNotEqualTo(0); } + if(testDirection.equals("ArrayContainsInterfaceMethods")) { + Method[]interfaceMethods=Device.class.getDeclaredMethods(); + List deviceMethods = new ArrayList(Arrays.asList(_cdPlayer.getOptions())); + for (int i = 0; i < interfaceMethods.length; i++) { + assertThat(deviceMethods.contains(interfaceMethods[i].getName())).describedAs(testName).isEqualTo(true); + } + + } + + } static Stream getOptionsTestData () { CDPlayer cdPlayer1 = new CDPlayer(); return Stream.of( - Arguments.of("[getOptions(): shouldNotReturnNull] => ReturnValueNotNull", "ReturnValueNotNull", cdPlayer1,null), - Arguments.of("[getOptions(): shouldReturnAnArrayWithLengthGreaterThen0] => ArrayLengthGreaterThen0", "ArrayLengthGreaterThen0", cdPlayer1,null) + Arguments.of("[getOptions(): shouldNotReturnNull] => ReturnValueNotNull", "ReturnValueNotNull", cdPlayer1), + Arguments.of("[getOptions(): shouldReturnAnArrayWithLengthGreaterThen0] => ArrayLengthGreaterThen0", "ArrayLengthGreaterThen0", cdPlayer1), + Arguments.of("[getOptions(): shouldReturnAnArrayWithInAllInterfaceMethods] => ArrayContainsInterfaceMethods", "ArrayContainsInterfaceMethods", cdPlayer1) ); } From 0e4bbd07dde28221c124d042f2c07c935b626bba Mon Sep 17 00:00:00 2001 From: JPANZO Date: Wed, 16 Feb 2022 18:12:52 +0100 Subject: [PATCH 2/3] Method getVolume of CDPlayer tested on getVolumeReturnValueBetween0And100. --- src/test/java/device/cdPlayer/CDPlayerTest.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/test/java/device/cdPlayer/CDPlayerTest.java b/src/test/java/device/cdPlayer/CDPlayerTest.java index 56646dc..3bcc1db 100644 --- a/src/test/java/device/cdPlayer/CDPlayerTest.java +++ b/src/test/java/device/cdPlayer/CDPlayerTest.java @@ -2,6 +2,7 @@ package device.cdPlayer; import device.Device; import device.cdPlayer.exceptions.*; +import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; @@ -249,10 +250,7 @@ class CDPlayerTest { for (int i = 0; i < interfaceMethods.length; i++) { assertThat(deviceMethods.contains(interfaceMethods[i].getName())).describedAs(testName).isEqualTo(true); } - } - - } static Stream getOptionsTestData () { CDPlayer cdPlayer1 = new CDPlayer(); @@ -263,6 +261,15 @@ class CDPlayerTest { ); } - + @Test + void getVolumeReturnValueBetween0And100(){ + CDPlayer cdPlayer1 = new CDPlayer(); + boolean volumeIstInValueRange=false; + int volume=cdPlayer1.getVolume(); + if(volume>=0 && volume <=100){ + volumeIstInValueRange=true; + } + assertThat(volumeIstInValueRange).isEqualTo(true); + } } \ No newline at end of file From 0e9662561a8188138ec8e83fbac713782c5d980b Mon Sep 17 00:00:00 2001 From: JPANZO Date: Wed, 16 Feb 2022 18:17:55 +0100 Subject: [PATCH 3/3] changes on Interface 4. --- src/main/java/device/Device.java | 7 +++++-- src/main/java/device/cdPlayer/CDPlayer.java | 10 ++++++++++ src/main/java/device/radioPlayer/RadioPlayer.java | 10 ++++++++++ src/main/java/device/usbPlayer/UsbPlayer.java | 10 ++++++++++ 4 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/main/java/device/Device.java b/src/main/java/device/Device.java index a2a8c3f..276e029 100644 --- a/src/main/java/device/Device.java +++ b/src/main/java/device/Device.java @@ -7,6 +7,7 @@ public interface Device { int getVolume(); void next(); void prev(); + String play(); //get deviceName, Album and current Item String getInfoText(); //get a list of public methods @@ -15,6 +16,8 @@ public interface Device { String chooseItem(int itemNr); // get the actual album String[] getItemList(); - String play(); - + //mute the Volume and returns an Info. + String mute(); + //unmute the Volume and returns an Info. + String unmute(); } diff --git a/src/main/java/device/cdPlayer/CDPlayer.java b/src/main/java/device/cdPlayer/CDPlayer.java index bdf1995..f5f93cc 100644 --- a/src/main/java/device/cdPlayer/CDPlayer.java +++ b/src/main/java/device/cdPlayer/CDPlayer.java @@ -90,6 +90,16 @@ public class CDPlayer implements Device { return loadedCD.getPlayList(); } + @Override + public String mute() { + return null; + } + + @Override + public String unmute() { + return null; + } + @Override public String play() { if(isCdFlapOpen()){ diff --git a/src/main/java/device/radioPlayer/RadioPlayer.java b/src/main/java/device/radioPlayer/RadioPlayer.java index 858cf13..2bd5401 100644 --- a/src/main/java/device/radioPlayer/RadioPlayer.java +++ b/src/main/java/device/radioPlayer/RadioPlayer.java @@ -166,6 +166,16 @@ public class RadioPlayer implements Device { return null; } + @Override + public String mute() { + return null; + } + + @Override + public String unmute() { + return null; + } + @Override public String play() { diff --git a/src/main/java/device/usbPlayer/UsbPlayer.java b/src/main/java/device/usbPlayer/UsbPlayer.java index bf403d6..b1440e3 100644 --- a/src/main/java/device/usbPlayer/UsbPlayer.java +++ b/src/main/java/device/usbPlayer/UsbPlayer.java @@ -160,6 +160,16 @@ public class UsbPlayer implements Device { return null; } + @Override + public String mute() { + return null; + } + + @Override + public String unmute() { + return null; + } + @Override public String play() {