From 74242d1cb56c19f9f495e8f83bff632b578377ea Mon Sep 17 00:00:00 2001 From: JPANZO Date: Tue, 15 Feb 2022 18:48:39 +0100 Subject: [PATCH 1/4] changes in the Interface. --- src/main/java/device/Device.java | 6 +----- src/main/java/device/cdPlayer/CDPlayer.java | 7 +++---- src/main/java/device/radioPlayer/RadioPlayer.java | 5 ++--- src/main/java/device/usbPlayer/UsbPlayer.java | 5 ++--- src/test/java/device/cdPlayer/CDPlayerTest.java | 2 +- 5 files changed, 9 insertions(+), 16 deletions(-) diff --git a/src/main/java/device/Device.java b/src/main/java/device/Device.java index 621e540..47162d9 100644 --- a/src/main/java/device/Device.java +++ b/src/main/java/device/Device.java @@ -8,12 +8,8 @@ public interface Device { void next(); void prev(); String getInfoText(); - //returns an array with Method-Names to bee listed String[] getOptions(); - //returns an array with contents to bee played - String[] getItemList(); - + String chooseOption(); String play(); - } diff --git a/src/main/java/device/cdPlayer/CDPlayer.java b/src/main/java/device/cdPlayer/CDPlayer.java index 618159d..b332775 100644 --- a/src/main/java/device/cdPlayer/CDPlayer.java +++ b/src/main/java/device/cdPlayer/CDPlayer.java @@ -69,15 +69,14 @@ public class CDPlayer implements Device { @Override public String[] getOptions() { - return new String[0]; + return loadedCD.getPlayList(); } @Override - public String[] getItemList() { - return loadedCD.getPlayList(); + public String chooseOption() { + 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 73d5625..6a6363d 100644 --- a/src/main/java/device/radioPlayer/RadioPlayer.java +++ b/src/main/java/device/radioPlayer/RadioPlayer.java @@ -157,11 +157,10 @@ public class RadioPlayer implements Device { } @Override - public String[] getItemList() { - return new String[0]; + public String chooseOption() { + return null; } - @Override public String play() { if (regionPlaylist.contains(playedStation)) diff --git a/src/main/java/device/usbPlayer/UsbPlayer.java b/src/main/java/device/usbPlayer/UsbPlayer.java index 1f395c8..1856068 100644 --- a/src/main/java/device/usbPlayer/UsbPlayer.java +++ b/src/main/java/device/usbPlayer/UsbPlayer.java @@ -151,11 +151,10 @@ public class UsbPlayer implements Device { } @Override - public String[] getItemList() { - return new String[0]; + public String chooseOption() { + return null; } - @Override public String play() { String result = "USB : "; diff --git a/src/test/java/device/cdPlayer/CDPlayerTest.java b/src/test/java/device/cdPlayer/CDPlayerTest.java index d26aa95..37cb277 100644 --- a/src/test/java/device/cdPlayer/CDPlayerTest.java +++ b/src/test/java/device/cdPlayer/CDPlayerTest.java @@ -193,7 +193,7 @@ class CDPlayerTest { return Stream.of( Arguments.of("[getActualPlayTrack() after 1x next() starting by firstSong] => SecondSongSelected","SecondSongSelected", cdPlayer1, 1, cdPlayer1.getSongByNumber(1)), Arguments.of("[getActualPlayTrack() after 2x next() starting by firstSong] => ThirdSongSelected","ThirdSongSelected" ,cdPlayer2,2,cdPlayer2.getSongByNumber(2)), - Arguments.of("[getActualPlayTrack() after 1x next() starting by lastSong] => FirstSongSelected","FirstSongSelected", cdPlayer3,cdPlayer3.getItemList().length,cdPlayer3.getSongByNumber(0)) + Arguments.of("[getActualPlayTrack() after 1x next() starting by lastSong] => FirstSongSelected","FirstSongSelected", cdPlayer3,cdPlayer3.getOptions().length,cdPlayer3.getSongByNumber(0)) ); } From 31e51d9a3f6d42ee5d5e4c5c73b8aec15f8d3e55 Mon Sep 17 00:00:00 2001 From: JPANZO Date: Tue, 15 Feb 2022 19:21:01 +0100 Subject: [PATCH 2/4] changes in the Interface 0.2. --- src/main/java/device/Device.java | 7 ++++++- src/main/java/device/cdPlayer/CDPlayer.java | 7 ++++++- src/main/java/device/radioPlayer/RadioPlayer.java | 8 +++++++- src/main/java/device/usbPlayer/UsbPlayer.java | 8 +++++++- 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/main/java/device/Device.java b/src/main/java/device/Device.java index 47162d9..66a376d 100644 --- a/src/main/java/device/Device.java +++ b/src/main/java/device/Device.java @@ -7,9 +7,14 @@ public interface Device { int getVolume(); void next(); void prev(); + //get deviceName, Album and current Item String getInfoText(); + //get a list of public methods String[] getOptions(); - String chooseOption(); + //get an Item of the Album + String chooseItem(int itemNr); + // get the actual album + String getItemList(); String play(); } diff --git a/src/main/java/device/cdPlayer/CDPlayer.java b/src/main/java/device/cdPlayer/CDPlayer.java index b332775..e7c0ec5 100644 --- a/src/main/java/device/cdPlayer/CDPlayer.java +++ b/src/main/java/device/cdPlayer/CDPlayer.java @@ -73,7 +73,12 @@ public class CDPlayer implements Device { } @Override - public String chooseOption() { + public String chooseItem(int itemNr) { + return null; + } + + @Override + public String getItemList() { return null; } diff --git a/src/main/java/device/radioPlayer/RadioPlayer.java b/src/main/java/device/radioPlayer/RadioPlayer.java index 6a6363d..f491dbc 100644 --- a/src/main/java/device/radioPlayer/RadioPlayer.java +++ b/src/main/java/device/radioPlayer/RadioPlayer.java @@ -157,10 +157,16 @@ public class RadioPlayer implements Device { } @Override - public String chooseOption() { + public String chooseItem(int itemNr) { return null; } + @Override + public String getItemList() { + return null; + } + + @Override public String play() { if (regionPlaylist.contains(playedStation)) diff --git a/src/main/java/device/usbPlayer/UsbPlayer.java b/src/main/java/device/usbPlayer/UsbPlayer.java index 1856068..da599bc 100644 --- a/src/main/java/device/usbPlayer/UsbPlayer.java +++ b/src/main/java/device/usbPlayer/UsbPlayer.java @@ -151,10 +151,16 @@ public class UsbPlayer implements Device { } @Override - public String chooseOption() { + public String chooseItem(int itemNr) { return null; } + @Override + public String getItemList() { + return null; + } + + @Override public String play() { String result = "USB : "; From aa3c6ef4d45af4925cd2af63875b8220441601d1 Mon Sep 17 00:00:00 2001 From: JPANZO Date: Tue, 15 Feb 2022 20:43:33 +0100 Subject: [PATCH 3/4] getOptions from CDPlayer tested on Returning Null. changes in the Interface 0.3. --- src/main/java/device/Device.java | 2 +- src/main/java/device/cdPlayer/CDPlayer.java | 6 +++--- .../java/device/radioPlayer/RadioPlayer.java | 2 +- src/main/java/device/usbPlayer/UsbPlayer.java | 2 +- src/test/java/device/cdPlayer/CDPlayerTest.java | 17 ++++++++++++++++- 5 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/main/java/device/Device.java b/src/main/java/device/Device.java index 66a376d..a2a8c3f 100644 --- a/src/main/java/device/Device.java +++ b/src/main/java/device/Device.java @@ -14,7 +14,7 @@ public interface Device { //get an Item of the Album String chooseItem(int itemNr); // get the actual album - String getItemList(); + String[] getItemList(); String play(); } diff --git a/src/main/java/device/cdPlayer/CDPlayer.java b/src/main/java/device/cdPlayer/CDPlayer.java index e7c0ec5..66d8bfb 100644 --- a/src/main/java/device/cdPlayer/CDPlayer.java +++ b/src/main/java/device/cdPlayer/CDPlayer.java @@ -69,7 +69,7 @@ public class CDPlayer implements Device { @Override public String[] getOptions() { - return loadedCD.getPlayList(); + return new String[]{}; } @Override @@ -78,8 +78,8 @@ public class CDPlayer implements Device { } @Override - public String getItemList() { - return null; + public String[] getItemList() { + return loadedCD.getPlayList(); } @Override diff --git a/src/main/java/device/radioPlayer/RadioPlayer.java b/src/main/java/device/radioPlayer/RadioPlayer.java index f491dbc..858cf13 100644 --- a/src/main/java/device/radioPlayer/RadioPlayer.java +++ b/src/main/java/device/radioPlayer/RadioPlayer.java @@ -162,7 +162,7 @@ public class RadioPlayer implements Device { } @Override - public String getItemList() { + public String[] getItemList() { return null; } diff --git a/src/main/java/device/usbPlayer/UsbPlayer.java b/src/main/java/device/usbPlayer/UsbPlayer.java index da599bc..bf403d6 100644 --- a/src/main/java/device/usbPlayer/UsbPlayer.java +++ b/src/main/java/device/usbPlayer/UsbPlayer.java @@ -156,7 +156,7 @@ public class UsbPlayer implements Device { } @Override - public String getItemList() { + public String[] getItemList() { return null; } diff --git a/src/test/java/device/cdPlayer/CDPlayerTest.java b/src/test/java/device/cdPlayer/CDPlayerTest.java index 37cb277..171dda9 100644 --- a/src/test/java/device/cdPlayer/CDPlayerTest.java +++ b/src/test/java/device/cdPlayer/CDPlayerTest.java @@ -193,7 +193,7 @@ class CDPlayerTest { return Stream.of( Arguments.of("[getActualPlayTrack() after 1x next() starting by firstSong] => SecondSongSelected","SecondSongSelected", cdPlayer1, 1, cdPlayer1.getSongByNumber(1)), Arguments.of("[getActualPlayTrack() after 2x next() starting by firstSong] => ThirdSongSelected","ThirdSongSelected" ,cdPlayer2,2,cdPlayer2.getSongByNumber(2)), - Arguments.of("[getActualPlayTrack() after 1x next() starting by lastSong] => FirstSongSelected","FirstSongSelected", cdPlayer3,cdPlayer3.getOptions().length,cdPlayer3.getSongByNumber(0)) + Arguments.of("[getActualPlayTrack() after 1x next() starting by lastSong] => FirstSongSelected","FirstSongSelected", cdPlayer3,cdPlayer3.getItemList().length,cdPlayer3.getSongByNumber(0)) ); } @@ -228,4 +228,19 @@ class CDPlayerTest { Arguments.of("[getActualPlayTrack() after 1x prev() starting by firstSong] => FirstSongSelected", "StartingByFirstSong", cdPlayer1, 1, cdPlayer1.getSongByNumber(0)) ); } + + @ParameterizedTest + @MethodSource("getOptionsTestData") + void getOptionsTest(String testName,String testDirection, CDPlayer _cdPlayer, String expectedResult){ + assertThat(_cdPlayer.getOptions()).describedAs(testName).isNotEqualTo(null); + } + static Stream getOptionsTestData () { + CDPlayer cdPlayer1 = new CDPlayer(); + return Stream.of( + Arguments.of("[getOptions(): shouldNotReturnsNull] => ReturnValueNotNull", "ReturnValueNotNull", cdPlayer1,null) + ); + } + + + } \ No newline at end of file From 6c5989e12f15df61ecedbb5357c3e8c7688c9b23 Mon Sep 17 00:00:00 2001 From: JPANZO Date: Tue, 15 Feb 2022 21:00:25 +0100 Subject: [PATCH 4/4] getOptions from CDPlayer tested on ArrayLengthGreaterThen 0. --- src/main/java/device/cdPlayer/CDPlayer.java | 10 +++++++++- src/test/java/device/cdPlayer/CDPlayerTest.java | 10 ++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/main/java/device/cdPlayer/CDPlayer.java b/src/main/java/device/cdPlayer/CDPlayer.java index 66d8bfb..bdf1995 100644 --- a/src/main/java/device/cdPlayer/CDPlayer.java +++ b/src/main/java/device/cdPlayer/CDPlayer.java @@ -2,6 +2,8 @@ package device.cdPlayer; import device.Device; import device.cdPlayer.exceptions.*; + +import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -69,7 +71,13 @@ public class CDPlayer implements Device { @Override public String[] getOptions() { - return new String[]{}; + Method[] methods=this.getClass().getDeclaredMethods(); + String[] outMethods=new String[methods.length]; + + for (int i = 0; i getOptionsTestData () { CDPlayer cdPlayer1 = new CDPlayer(); return Stream.of( - Arguments.of("[getOptions(): shouldNotReturnsNull] => ReturnValueNotNull", "ReturnValueNotNull", cdPlayer1,null) + Arguments.of("[getOptions(): shouldNotReturnNull] => ReturnValueNotNull", "ReturnValueNotNull", cdPlayer1,null), + Arguments.of("[getOptions(): shouldReturnAnArrayWithLengthGreaterThen0] => ArrayLengthGreaterThen0", "ArrayLengthGreaterThen0", cdPlayer1,null) ); }