From 8d012dd9b37295845a765534830a7181de72297f Mon Sep 17 00:00:00 2001 From: alpina0707 Date: Fri, 18 Feb 2022 14:04:18 +0100 Subject: [PATCH 01/10] cleaned up RadioPlayer and made help functions package private --- src/main/java/device/radioPlayer/RadioPlayer.java | 6 +++--- src/test/java/device/radioPlayer/RadioPlayerTest.java | 10 ++++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/main/java/device/radioPlayer/RadioPlayer.java b/src/main/java/device/radioPlayer/RadioPlayer.java index 0b341d4..7d9c503 100644 --- a/src/main/java/device/radioPlayer/RadioPlayer.java +++ b/src/main/java/device/radioPlayer/RadioPlayer.java @@ -24,7 +24,7 @@ public class RadioPlayer implements Device { int savedVolume; String playedStation; - public String getYouFMInfoByTime(int x) { + String getYouFMInfoByTime(int x) { if (x >= 5 && x < 10) return YouFMInfo[0]; else if (x >= 10 && x < 14) return YouFMInfo[1]; else if (x >= 14 && x < 18) return YouFMInfo[2]; @@ -36,7 +36,7 @@ public class RadioPlayer implements Device { String[] YouFMInfo = {"YOUFM Good Morning Show", "YOUFM Worktime", "YOUFM am Nachmittag", "YOUFM am Abend", "YOUFM Wir feiern euch", "YOUFM Deutschrap ideal", "YOUFM Junge Nacht der ARD"}; - public String getBR3InfoByTime(int x) { + String getBR3InfoByTime(int x) { if (x >= 5 && x < 9) return BR3Info[0]; else if (x >= 9 && x < 12) return BR3Info[1]; else if (x == 12) return BR3Info[2]; @@ -49,7 +49,7 @@ public class RadioPlayer implements Device { String[] BR3Info = {"Sebastian Winkler und die Frühaufdreher", "BAYERN 3 - und DU mittendrin!", "Update", "Hits, Hits, Hits für euren Nachmittag", "Die Zwei für euren Feierabend", "Was geht?!", "Matuschke - der etwas andere Abend", "Die Nacht"}; - public String getAntenneBYInfoByTime(int x) { + String getAntenneBYInfoByTime(int x) { if (x >= 5 && x < 9) return AntenneBYInfo[0]; else if (x >= 9 && x < 12) return AntenneBYInfo[1]; else if (x >= 12 && x < 15) return AntenneBYInfo[2]; diff --git a/src/test/java/device/radioPlayer/RadioPlayerTest.java b/src/test/java/device/radioPlayer/RadioPlayerTest.java index 680109c..3cc6ad0 100644 --- a/src/test/java/device/radioPlayer/RadioPlayerTest.java +++ b/src/test/java/device/radioPlayer/RadioPlayerTest.java @@ -6,7 +6,6 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; - import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Arrays; @@ -104,9 +103,12 @@ class RadioPlayerTest { @ParameterizedTest @MethodSource("infoByTimeOptions") void infoByTimeInfo(String testName, RadioPlayer testRp, String testTyp, int hour, String expectedResult) { - if(testTyp.equals("YouFM")) assertThat(testRp.getYouFMInfoByTime(hour)).describedAs(testName).isEqualTo(expectedResult); - if(testTyp.equals("BR3")) assertThat(testRp.getBR3InfoByTime(hour)).describedAs(testName).isEqualTo(expectedResult); - if(testTyp.equals("AntenneBY")) assertThat(testRp.getAntenneBYInfoByTime(hour)).describedAs(testName).isEqualTo(expectedResult); + if (testTyp.equals("YouFM")) + assertThat(testRp.getYouFMInfoByTime(hour)).describedAs(testName).isEqualTo(expectedResult); + if (testTyp.equals("BR3")) + assertThat(testRp.getBR3InfoByTime(hour)).describedAs(testName).isEqualTo(expectedResult); + if (testTyp.equals("AntenneBY")) + assertThat(testRp.getAntenneBYInfoByTime(hour)).describedAs(testName).isEqualTo(expectedResult); } static Stream infoByTimeOptions() { From ba914846c7c137d7a78edd900be8020fd19f16a7 Mon Sep 17 00:00:00 2001 From: sahar Date: Fri, 18 Feb 2022 17:30:34 +0100 Subject: [PATCH 02/10] changes commited --- src/main/java/device/usbPlayer/UsbPlayer.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/main/java/device/usbPlayer/UsbPlayer.java b/src/main/java/device/usbPlayer/UsbPlayer.java index acf923b..391d563 100644 --- a/src/main/java/device/usbPlayer/UsbPlayer.java +++ b/src/main/java/device/usbPlayer/UsbPlayer.java @@ -70,10 +70,7 @@ public class UsbPlayer implements Device { super(); isDefect = false; isConnected = true; - /*Playlist.add("Musik 01.mp3"); - Playlist.add("Musik 02.mp3"); - Playlist.add("Musik 03.mp3"); - playTrack = Playlist.get(0);*/ + try { Playlist = stick.getAlbum(); } catch (NoFolderFound e) { From fcaa3473ff0952a174b907e09c454d1a9332f93e Mon Sep 17 00:00:00 2001 From: sahar Date: Fri, 18 Feb 2022 19:38:46 +0100 Subject: [PATCH 03/10] BordComputerTest.changeDeviceTest first case --- src/main/java/BordComputer.java | 12 ++++++++++++ src/test/java/BordComputerTest.java | 27 +++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/src/main/java/BordComputer.java b/src/main/java/BordComputer.java index 7563899..c8b597a 100644 --- a/src/main/java/BordComputer.java +++ b/src/main/java/BordComputer.java @@ -35,4 +35,16 @@ public class BordComputer { installedDevices[i] = (Device) c.getConstructor().newInstance(); } } + + public String changeDevice() { + Device[] tempDevices = new Device[installedDevices.length]; + tempDevices[0] = installedDevices[1]; + tempDevices[1] = installedDevices[2]; + tempDevices[2] = installedDevices[0]; + //replaces the lists + installedDevices = tempDevices; + //setting activeDevice + activeDevice = installedDevices[0]; + return null; + } } diff --git a/src/test/java/BordComputerTest.java b/src/test/java/BordComputerTest.java index 6772d99..1118e4a 100644 --- a/src/test/java/BordComputerTest.java +++ b/src/test/java/BordComputerTest.java @@ -81,4 +81,31 @@ class BordComputerTest { } return count; } + + //// + @ParameterizedTest + @MethodSource("changeDeviceOptions") + void changeDeviceTest(String testName, BordComputer inputBC, Device[] oldDevices,Device prvDevice,String message ,int caseNr) { + Device[] newDevicesList = inputBC.installedDevices.clone(); + if (caseNr == 1 ) { + assertThat(newDevicesList).describedAs(testName).isNotEqualTo(oldDevices); + } + } + + static Stream changeDeviceOptions() throws ClassNotFoundException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException { + + //first case + BordComputer bc = new BordComputer(); + bc.readConfig(); + bc.setDevices(); + Device[] currentDevices = new Device[bc.installedDevices.length]; + currentDevices = bc.installedDevices.clone(); + String m = bc.changeDevice(); + + + + return Stream.of( + Arguments.of("The order of the installedDevices should be changed ", bc,currentDevices,null,"",1) + ); + } } \ No newline at end of file From 0ba1d23c8ce5e925ee7b7904d328eb6fa1c53d1f Mon Sep 17 00:00:00 2001 From: sahar Date: Fri, 18 Feb 2022 19:41:18 +0100 Subject: [PATCH 04/10] BordComputerTest.changeDeviceTest second case --- src/main/java/BordComputer.java | 1 + src/test/java/BordComputerTest.java | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/main/java/BordComputer.java b/src/main/java/BordComputer.java index c8b597a..38d24d1 100644 --- a/src/main/java/BordComputer.java +++ b/src/main/java/BordComputer.java @@ -45,6 +45,7 @@ public class BordComputer { installedDevices = tempDevices; //setting activeDevice activeDevice = installedDevices[0]; + return null; } } diff --git a/src/test/java/BordComputerTest.java b/src/test/java/BordComputerTest.java index 1118e4a..056b5f3 100644 --- a/src/test/java/BordComputerTest.java +++ b/src/test/java/BordComputerTest.java @@ -89,6 +89,9 @@ class BordComputerTest { Device[] newDevicesList = inputBC.installedDevices.clone(); if (caseNr == 1 ) { assertThat(newDevicesList).describedAs(testName).isNotEqualTo(oldDevices); + }else if (caseNr == 2) { + Device currentDevice = inputBC.activeDevice; + assertThat(currentDevice).describedAs(testName).isNotEqualTo(prvDevice); } } @@ -102,10 +105,18 @@ class BordComputerTest { currentDevices = bc.installedDevices.clone(); String m = bc.changeDevice(); + //second case + BordComputer bc1 = new BordComputer(); + bc1.readConfig(); + bc1.setDevices(); + Device prvDevice = bc1.activeDevice; + m =bc1.changeDevice(); + return Stream.of( - Arguments.of("The order of the installedDevices should be changed ", bc,currentDevices,null,"",1) + Arguments.of("The order of the installedDevices should be changed ", bc,currentDevices,null,"",1), + Arguments.of("The active Device should be changed ", bc1,null,prvDevice,"",2) ); } } \ No newline at end of file From af618f21a189b90db3e7d04d3ab0b8297b011c4d Mon Sep 17 00:00:00 2001 From: sahar Date: Fri, 18 Feb 2022 19:43:58 +0100 Subject: [PATCH 05/10] BordComputerTest.changeDeviceTest third case --- src/main/java/BordComputer.java | 20 +++++++++++++++++++- src/test/java/BordComputerTest.java | 11 ++++++++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/main/java/BordComputer.java b/src/main/java/BordComputer.java index 38d24d1..439078e 100644 --- a/src/main/java/BordComputer.java +++ b/src/main/java/BordComputer.java @@ -1,4 +1,6 @@ import device.Device; +import device.cdPlayer.CD; +import device.cdPlayer.CDPlayer; import java.io.FileReader; import java.lang.reflect.InvocationTargetException; @@ -46,6 +48,22 @@ public class BordComputer { //setting activeDevice activeDevice = installedDevices[0]; - return null; + String infoText=""; + if(activeDevice instanceof CDPlayer){ + CDPlayer cdPlayer=(CDPlayer) activeDevice; + String[] audioPlayList=new String[]{"Audio 01","Audio 02","Audio 03","Audio 04","Audio 05"}; + //some CDs + CD audioCD1=new CD("Audio",audioPlayList); + audioCD1.setAlbumName("Love Songs"); + + cdPlayer.tapOnCdFlap(); + cdPlayer.setCD(audioCD1); + cdPlayer.tapOnCdFlap(); + cdPlayer.setInfoText(); + infoText = cdPlayer.getInfoText(); + }else{ + infoText=activeDevice.getInfoText()+" ist activate"; + } + return infoText; } } diff --git a/src/test/java/BordComputerTest.java b/src/test/java/BordComputerTest.java index 056b5f3..422d7ef 100644 --- a/src/test/java/BordComputerTest.java +++ b/src/test/java/BordComputerTest.java @@ -92,6 +92,8 @@ class BordComputerTest { }else if (caseNr == 2) { Device currentDevice = inputBC.activeDevice; assertThat(currentDevice).describedAs(testName).isNotEqualTo(prvDevice); + }else if (caseNr == 3) { + assertThat(inputBC.changeDevice()).describedAs(testName).isNotNull(); } } @@ -112,11 +114,18 @@ class BordComputerTest { Device prvDevice = bc1.activeDevice; m =bc1.changeDevice(); + //third case + BordComputer bc2 = new BordComputer(); + bc2.readConfig(); + bc2.setDevices(); + m =bc2.changeDevice(); + return Stream.of( Arguments.of("The order of the installedDevices should be changed ", bc,currentDevices,null,"",1), - Arguments.of("The active Device should be changed ", bc1,null,prvDevice,"",2) + Arguments.of("The active Device should be changed ", bc1,null,prvDevice,"",2), + Arguments.of("The new Device returns a String ", bc2,null,prvDevice,bc2.activeDevice.toString(),3) ); } } \ No newline at end of file From 2a566d0a29c73a3c6ee176e6101e62f8c406bf4d Mon Sep 17 00:00:00 2001 From: sahar Date: Fri, 18 Feb 2022 19:47:06 +0100 Subject: [PATCH 06/10] BordComputerTest.changeDeviceTest forth case --- src/test/java/BordComputerTest.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/test/java/BordComputerTest.java b/src/test/java/BordComputerTest.java index 422d7ef..e801a36 100644 --- a/src/test/java/BordComputerTest.java +++ b/src/test/java/BordComputerTest.java @@ -94,6 +94,8 @@ class BordComputerTest { assertThat(currentDevice).describedAs(testName).isNotEqualTo(prvDevice); }else if (caseNr == 3) { assertThat(inputBC.changeDevice()).describedAs(testName).isNotNull(); + }else if (caseNr == 4) { + assertThat(inputBC.changeDevice()).describedAs(testName).isNotNull(); } } @@ -120,12 +122,20 @@ class BordComputerTest { bc2.setDevices(); m =bc2.changeDevice(); + //forth case + BordComputer bc3 = new BordComputer(); + bc3.readConfig(); + bc3.setDevices(); + m =bc3.changeDevice(); + m =bc3.changeDevice(); //CDPlayer + return Stream.of( Arguments.of("The order of the installedDevices should be changed ", bc,currentDevices,null,"",1), Arguments.of("The active Device should be changed ", bc1,null,prvDevice,"",2), - Arguments.of("The new Device returns a String ", bc2,null,prvDevice,bc2.activeDevice.toString(),3) + Arguments.of("The new Device returns a String ", bc2,null,prvDevice,bc2.activeDevice.toString(),3), + Arguments.of("The new Device returns a String ", bc3,null,prvDevice,null,4) ); } } \ No newline at end of file From 4d75bcf8cc301740231a5ff195a842fc67e68c1f Mon Sep 17 00:00:00 2001 From: sahar Date: Fri, 18 Feb 2022 19:48:50 +0100 Subject: [PATCH 07/10] BordComputerTest.changeDeviceTest fifth case --- src/test/java/BordComputerTest.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/test/java/BordComputerTest.java b/src/test/java/BordComputerTest.java index e801a36..6606f02 100644 --- a/src/test/java/BordComputerTest.java +++ b/src/test/java/BordComputerTest.java @@ -96,6 +96,8 @@ class BordComputerTest { assertThat(inputBC.changeDevice()).describedAs(testName).isNotNull(); }else if (caseNr == 4) { assertThat(inputBC.changeDevice()).describedAs(testName).isNotNull(); + }else if (caseNr == 5) { + assertThat(inputBC.changeDevice()).describedAs(testName).isNotNull(); } } @@ -129,13 +131,20 @@ class BordComputerTest { m =bc3.changeDevice(); m =bc3.changeDevice(); //CDPlayer - + //fifth case + BordComputer bc4 = new BordComputer(); + bc4.readConfig(); + bc4.setDevices(); + m =bc4.changeDevice(); + m =bc4.changeDevice(); //CDPlayer + m =bc4.changeDevice(); return Stream.of( Arguments.of("The order of the installedDevices should be changed ", bc,currentDevices,null,"",1), Arguments.of("The active Device should be changed ", bc1,null,prvDevice,"",2), Arguments.of("The new Device returns a String ", bc2,null,prvDevice,bc2.activeDevice.toString(),3), - Arguments.of("The new Device returns a String ", bc3,null,prvDevice,null,4) + Arguments.of("The new Device returns a String ", bc3,null,prvDevice,null,4), + Arguments.of("The new Device returns a String ", bc4,null,prvDevice,null,5) ); } } \ No newline at end of file From 080badc8cf770da8c80826e9c190f10a44e14803 Mon Sep 17 00:00:00 2001 From: sahar Date: Fri, 18 Feb 2022 19:50:29 +0100 Subject: [PATCH 08/10] BordComputerTest.changeDeviceTest 6th case --- src/test/java/BordComputerTest.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/test/java/BordComputerTest.java b/src/test/java/BordComputerTest.java index 6606f02..0491de9 100644 --- a/src/test/java/BordComputerTest.java +++ b/src/test/java/BordComputerTest.java @@ -98,6 +98,8 @@ class BordComputerTest { assertThat(inputBC.changeDevice()).describedAs(testName).isNotNull(); }else if (caseNr == 5) { assertThat(inputBC.changeDevice()).describedAs(testName).isNotNull(); + }else if (caseNr == 6) { + assertThat(inputBC.changeDevice()).describedAs(testName).contains("USB Player"); } } @@ -139,12 +141,19 @@ class BordComputerTest { m =bc4.changeDevice(); //CDPlayer m =bc4.changeDevice(); + //sixth case + BordComputer bc5 = new BordComputer(); + bc5.readConfig(); + bc5.setDevices(); + m =bc5.changeDevice(); + return Stream.of( Arguments.of("The order of the installedDevices should be changed ", bc,currentDevices,null,"",1), Arguments.of("The active Device should be changed ", bc1,null,prvDevice,"",2), Arguments.of("The new Device returns a String ", bc2,null,prvDevice,bc2.activeDevice.toString(),3), Arguments.of("The new Device returns a String ", bc3,null,prvDevice,null,4), - Arguments.of("The new Device returns a String ", bc4,null,prvDevice,null,5) + Arguments.of("The new Device returns a String ", bc4,null,prvDevice,null,5), + Arguments.of("The new Device returns Info ", bc5,null,prvDevice,null,6) ); } } \ No newline at end of file From 59d88fb2f2f78e4997e7ea22d24a457c225d8aaa Mon Sep 17 00:00:00 2001 From: sahar Date: Fri, 18 Feb 2022 19:52:03 +0100 Subject: [PATCH 09/10] BordComputerTest.changeDeviceTest 7th case --- src/test/java/BordComputerTest.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/test/java/BordComputerTest.java b/src/test/java/BordComputerTest.java index 0491de9..71a7376 100644 --- a/src/test/java/BordComputerTest.java +++ b/src/test/java/BordComputerTest.java @@ -100,6 +100,8 @@ class BordComputerTest { assertThat(inputBC.changeDevice()).describedAs(testName).isNotNull(); }else if (caseNr == 6) { assertThat(inputBC.changeDevice()).describedAs(testName).contains("USB Player"); + }else if (caseNr == 7) { + assertThat(inputBC.changeDevice()).describedAs(testName).contains("CDPlayer"); } } @@ -147,13 +149,21 @@ class BordComputerTest { bc5.setDevices(); m =bc5.changeDevice(); + //seventh case + BordComputer bc6 = new BordComputer(); + bc6.readConfig(); + bc6.setDevices(); + m =bc6.changeDevice(); + m =bc6.changeDevice(); + return Stream.of( Arguments.of("The order of the installedDevices should be changed ", bc,currentDevices,null,"",1), Arguments.of("The active Device should be changed ", bc1,null,prvDevice,"",2), Arguments.of("The new Device returns a String ", bc2,null,prvDevice,bc2.activeDevice.toString(),3), Arguments.of("The new Device returns a String ", bc3,null,prvDevice,null,4), Arguments.of("The new Device returns a String ", bc4,null,prvDevice,null,5), - Arguments.of("The new Device returns Info ", bc5,null,prvDevice,null,6) + Arguments.of("The new Device returns Info ", bc5,null,prvDevice,null,6), + Arguments.of("The new Device returns Info ", bc6,null,prvDevice,null,7) ); } } \ No newline at end of file From d424ff222154de20c8b39c70ebeeb9b2d9f8f65c Mon Sep 17 00:00:00 2001 From: sahar Date: Fri, 18 Feb 2022 19:55:22 +0100 Subject: [PATCH 10/10] BordComputerTest.changeDeviceTest 8th case --- src/test/java/BordComputerTest.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/test/java/BordComputerTest.java b/src/test/java/BordComputerTest.java index 71a7376..8abb5df 100644 --- a/src/test/java/BordComputerTest.java +++ b/src/test/java/BordComputerTest.java @@ -102,6 +102,8 @@ class BordComputerTest { assertThat(inputBC.changeDevice()).describedAs(testName).contains("USB Player"); }else if (caseNr == 7) { assertThat(inputBC.changeDevice()).describedAs(testName).contains("CDPlayer"); + }else if (caseNr == 8) { + assertThat(inputBC.changeDevice()).describedAs(testName).contains("playlist"); } } @@ -156,6 +158,14 @@ class BordComputerTest { m =bc6.changeDevice(); m =bc6.changeDevice(); + //eighth case + BordComputer bc7 = new BordComputer(); + bc7.readConfig(); + bc7.setDevices(); + m =bc7.changeDevice(); + m =bc7.changeDevice(); + m =bc7.changeDevice(); + return Stream.of( Arguments.of("The order of the installedDevices should be changed ", bc,currentDevices,null,"",1), Arguments.of("The active Device should be changed ", bc1,null,prvDevice,"",2), @@ -163,7 +173,8 @@ class BordComputerTest { Arguments.of("The new Device returns a String ", bc3,null,prvDevice,null,4), Arguments.of("The new Device returns a String ", bc4,null,prvDevice,null,5), Arguments.of("The new Device returns Info ", bc5,null,prvDevice,null,6), - Arguments.of("The new Device returns Info ", bc6,null,prvDevice,null,7) + Arguments.of("The new Device returns Info ", bc6,null,prvDevice,null,7), + Arguments.of("The new Device returns Info ", bc6,null,prvDevice,null,8) ); } } \ No newline at end of file