From ba914846c7c137d7a78edd900be8020fd19f16a7 Mon Sep 17 00:00:00 2001 From: sahar Date: Fri, 18 Feb 2022 17:30:34 +0100 Subject: [PATCH 01/15] 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 f526cacb404d08d00525b2b1ce3a5ced1d44c6cc Mon Sep 17 00:00:00 2001 From: JPANZO Date: Fri, 18 Feb 2022 17:42:33 +0100 Subject: [PATCH 02/15] BordComputer.play; instance of CDPlayer -> after all preconditions ShouldReturnAnItemToPlay. --- src/main/java/BordComputer.java | 43 +++++++++++++++++++ src/main/java/device/cdPlayer/CDPlayer.java | 9 +++- src/test/java/BordComputerTest.java | 17 ++++++++ .../java/device/cdPlayer/CDPlayerTest.java | 3 +- 4 files changed, 69 insertions(+), 3 deletions(-) diff --git a/src/main/java/BordComputer.java b/src/main/java/BordComputer.java index 7563899..6dda364 100644 --- a/src/main/java/BordComputer.java +++ b/src/main/java/BordComputer.java @@ -1,4 +1,8 @@ import device.Device; +import device.cdPlayer.CD; +import device.cdPlayer.CDPlayer; +import device.radioPlayer.RadioPlayer; +import device.usbPlayer.UsbPlayer; import java.io.FileReader; import java.lang.reflect.InvocationTargetException; @@ -35,4 +39,43 @@ public class BordComputer { installedDevices[i] = (Device) c.getConstructor().newInstance(); } } + + public String play(){ + String itemToPlay=activeDevice.play(); + return itemToPlay; + } + + //===== Hilf-Funktionen ====== + + public Object getInstanceByName(String deviceName){ + for (int i = 0; i playDate()throws ClassNotFoundException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException { + BordComputer bordComputer = new BordComputer(); + bordComputer.readConfig(); + return Stream.of( + Arguments.of("[CDPlayer-> play(): after all preconditions are met] => ShouldReturnAnItemToPlay","Case1",bordComputer,"CDPlayer") + ); + } + + } \ No newline at end of file diff --git a/src/test/java/device/cdPlayer/CDPlayerTest.java b/src/test/java/device/cdPlayer/CDPlayerTest.java index 06cdff8..d45992d 100644 --- a/src/test/java/device/cdPlayer/CDPlayerTest.java +++ b/src/test/java/device/cdPlayer/CDPlayerTest.java @@ -30,7 +30,8 @@ class CDPlayerTest { Exception newException=assertThrows(exception.getClass(),()->_cdPlayer.play()); assertEquals(expectedResult, newException.getMessage()); }else{ - assertThat(_cdPlayer.play()).describedAs(testName).isEqualTo(expectedResult); + _cdPlayer.play(); + assertThat(_cdPlayer.getStatus()).describedAs(testName).isEqualTo(expectedResult); } } static Stream playTestData () { From 73677960d4200a1f1f46d759c0d4a958701f56cd Mon Sep 17 00:00:00 2001 From: JPANZO Date: Fri, 18 Feb 2022 17:52:18 +0100 Subject: [PATCH 03/15] BordComputer.play; instance of RadioPlayer -> after all preconditions ShouldReturnAnItemToPlay. --- src/main/java/BordComputer.java | 15 +++++---------- src/test/java/BordComputerTest.java | 10 +++++++++- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/main/java/BordComputer.java b/src/main/java/BordComputer.java index 6dda364..b00ec43 100644 --- a/src/main/java/BordComputer.java +++ b/src/main/java/BordComputer.java @@ -47,18 +47,10 @@ public class BordComputer { //===== Hilf-Funktionen ====== - public Object getInstanceByName(String deviceName){ + public Device getInstanceByName(String deviceName){ for (int i = 0; i playDate()throws ClassNotFoundException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException { BordComputer bordComputer = new BordComputer(); bordComputer.readConfig(); return Stream.of( - Arguments.of("[CDPlayer-> play(): after all preconditions are met] => ShouldReturnAnItemToPlay","Case1",bordComputer,"CDPlayer") + Arguments.of("[CDPlayer-> play(): after all preconditions are met] => ShouldReturnAnItemToPlay","Case1",bordComputer,"CDPlayer"), + Arguments.of("[RadioPlayer-> play(): after all preconditions are met] => ShouldReturnAnItemToPlay","Case2",bordComputer,"RadioPlayer") ); } From ec49bb8a401a6ad8a065c3653c7ee73a2a556b01 Mon Sep 17 00:00:00 2001 From: JPANZO Date: Fri, 18 Feb 2022 18:04:13 +0100 Subject: [PATCH 04/15] BordComputer.play; instance of UsbPlayer -> after all preconditions ShouldReturnAnItemToPlay. --- src/main/java/BordComputer.java | 27 ++++++++++++------- src/main/java/device/usbPlayer/USB_Stick.java | 2 +- src/test/java/BordComputerTest.java | 9 ++++++- 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/src/main/java/BordComputer.java b/src/main/java/BordComputer.java index b00ec43..21f6b38 100644 --- a/src/main/java/BordComputer.java +++ b/src/main/java/BordComputer.java @@ -2,6 +2,7 @@ import device.Device; import device.cdPlayer.CD; import device.cdPlayer.CDPlayer; import device.radioPlayer.RadioPlayer; +import device.usbPlayer.USB_Stick; import device.usbPlayer.UsbPlayer; import java.io.FileReader; @@ -56,20 +57,28 @@ public class BordComputer { return null; } public void meetAllPreconditionForPlay(){ + if(activeDevice instanceof CDPlayer) { + String[] audioPlayList = new String[]{"Audio 01", "Audio 02", "Audio 03", "Audio 04", "Audio 05"}; + CD audioCD1 = new CD("Audio", "PopMusic", audioPlayList, "XAc20044"); + CD audioCD2 = new CD("Audio", "RockMusic", audioPlayList, "BLXPP78"); - String[] audioPlayList = new String[]{"Audio 01", "Audio 02", "Audio 03", "Audio 04", "Audio 05"}; - CD audioCD1 = new CD("Audio", "PopMusic", audioPlayList, "XAc20044"); - CD audioCD2=new CD("Audio","RockMusic",audioPlayList,"BLXPP78"); + CDPlayer cdPlayer = (CDPlayer) activeDevice; + cdPlayer.changePlaySource(); + cdPlayer.loadCDWechseler(audioCD1, 0); + cdPlayer.loadCDWechseler(audioCD2, 1); - CDPlayer cdPlayer=(CDPlayer) activeDevice; - cdPlayer.changePlaySource(); - cdPlayer.loadCDWechseler(audioCD1, 0); - cdPlayer.loadCDWechseler(audioCD2, 1); + cdPlayer.setCD(cdPlayer.getCdWechseler().getCDList().get(0)); + activeDevice = cdPlayer; + } + if(activeDevice instanceof UsbPlayer) { + USB_Stick USBDrive = new USB_Stick(); + UsbPlayer up1 = new UsbPlayer(USBDrive); + activeDevice = up1; + } - cdPlayer.setCD(cdPlayer.getCdWechseler().getCDList().get(0)); - activeDevice=cdPlayer; } + public void setActiveDevice(Device activeDevice) { this.activeDevice = activeDevice; } diff --git a/src/main/java/device/usbPlayer/USB_Stick.java b/src/main/java/device/usbPlayer/USB_Stick.java index 39817e9..5cf7b9f 100644 --- a/src/main/java/device/usbPlayer/USB_Stick.java +++ b/src/main/java/device/usbPlayer/USB_Stick.java @@ -8,7 +8,7 @@ public class USB_Stick { public ArrayList> Folders = new ArrayList<>(); int currentAlbum ; - USB_Stick() { + public USB_Stick() { ArrayList a1 = new ArrayList(); a1.add("Musik 01.mp3"); a1.add("Musik 02.mp3"); diff --git a/src/test/java/BordComputerTest.java b/src/test/java/BordComputerTest.java index fcdf1e3..31689aa 100644 --- a/src/test/java/BordComputerTest.java +++ b/src/test/java/BordComputerTest.java @@ -94,6 +94,12 @@ class BordComputerTest { bordComputer.setActiveDevice(radioPlayer); assertThat(bordComputer.play()).describedAs(testName).isNotEqualTo(null); } + if(testCase.equals("Case3")) { + Device usbPlayer=bordComputer.getInstanceByName(instanceName); + bordComputer.setActiveDevice(usbPlayer); + bordComputer.meetAllPreconditionForPlay(); + assertThat(bordComputer.play()).describedAs(testName).isNotEqualTo(null); + } } static Stream playDate()throws ClassNotFoundException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException { @@ -101,7 +107,8 @@ class BordComputerTest { bordComputer.readConfig(); return Stream.of( Arguments.of("[CDPlayer-> play(): after all preconditions are met] => ShouldReturnAnItemToPlay","Case1",bordComputer,"CDPlayer"), - Arguments.of("[RadioPlayer-> play(): after all preconditions are met] => ShouldReturnAnItemToPlay","Case2",bordComputer,"RadioPlayer") + Arguments.of("[RadioPlayer-> play(): after all preconditions are met] => ShouldReturnAnItemToPlay","Case2",bordComputer,"RadioPlayer"), + Arguments.of("[UsbPlayer-> play(): after all preconditions are met] => ShouldReturnAnItemToPlay","Case3",bordComputer,"UsbPlayer") ); } From 14c63c6a1ecafa7bc3fe8b6c17336cc553414c08 Mon Sep 17 00:00:00 2001 From: JPANZO Date: Fri, 18 Feb 2022 18:33:36 +0100 Subject: [PATCH 05/15] BordComputer.play; instance of CDPlayer -> without fulfilling preconditions: ShouldReturnAnException. --- src/main/java/BordComputer.java | 9 ++++++++- .../NoItemEvenAllPreconditionAreMet.java | 7 +++++++ src/test/java/BordComputerTest.java | 16 ++++++++++++++-- 3 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 src/main/java/exception/NoItemEvenAllPreconditionAreMet.java diff --git a/src/main/java/BordComputer.java b/src/main/java/BordComputer.java index 21f6b38..156e191 100644 --- a/src/main/java/BordComputer.java +++ b/src/main/java/BordComputer.java @@ -4,6 +4,7 @@ import device.cdPlayer.CDPlayer; import device.radioPlayer.RadioPlayer; import device.usbPlayer.USB_Stick; import device.usbPlayer.UsbPlayer; +import exception.NoItemEvenAllPreconditionAreMet; import java.io.FileReader; import java.lang.reflect.InvocationTargetException; @@ -42,7 +43,13 @@ public class BordComputer { } public String play(){ - String itemToPlay=activeDevice.play(); + String itemToPlay=null; + try { + itemToPlay=activeDevice.play(); + }catch (RuntimeException exception) { + throw new NoItemEvenAllPreconditionAreMet(); + } + return itemToPlay; } diff --git a/src/main/java/exception/NoItemEvenAllPreconditionAreMet.java b/src/main/java/exception/NoItemEvenAllPreconditionAreMet.java new file mode 100644 index 0000000..ec1be23 --- /dev/null +++ b/src/main/java/exception/NoItemEvenAllPreconditionAreMet.java @@ -0,0 +1,7 @@ +package exception; + +public class NoItemEvenAllPreconditionAreMet extends RuntimeException{ + public NoItemEvenAllPreconditionAreMet(){ + super("No Item returned even all preconditions are met."); + } +} diff --git a/src/test/java/BordComputerTest.java b/src/test/java/BordComputerTest.java index 31689aa..729d591 100644 --- a/src/test/java/BordComputerTest.java +++ b/src/test/java/BordComputerTest.java @@ -1,7 +1,9 @@ import device.Device; import device.cdPlayer.CDPlayer; +import device.cdPlayer.exceptions.NegativeInputException; import device.radioPlayer.RadioPlayer; import device.usbPlayer.UsbPlayer; +import exception.NoItemEvenAllPreconditionAreMet; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; @@ -100,15 +102,25 @@ class BordComputerTest { bordComputer.meetAllPreconditionForPlay(); assertThat(bordComputer.play()).describedAs(testName).isNotEqualTo(null); } + if(testCase.equals("Case4")) { + Exception newException = assertThrows(NoItemEvenAllPreconditionAreMet.class, () -> bordComputer.play()); + assertEquals(NoItemEvenAllPreconditionAreMet.class, newException.getClass()); + assertEquals(newException.getMessage(), "No Item returned even all preconditions are met."); + } } static Stream playDate()throws ClassNotFoundException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException { BordComputer bordComputer = new BordComputer(); - bordComputer.readConfig(); + bordComputer.readConfig(); + + BordComputer bordComputer2 = new BordComputer(); + bordComputer2.readConfig(); + return Stream.of( Arguments.of("[CDPlayer-> play(): after all preconditions are met] => ShouldReturnAnItemToPlay","Case1",bordComputer,"CDPlayer"), Arguments.of("[RadioPlayer-> play(): after all preconditions are met] => ShouldReturnAnItemToPlay","Case2",bordComputer,"RadioPlayer"), - Arguments.of("[UsbPlayer-> play(): after all preconditions are met] => ShouldReturnAnItemToPlay","Case3",bordComputer,"UsbPlayer") + Arguments.of("[UsbPlayer-> play(): after all preconditions are met] => ShouldReturnAnItemToPlay","Case3",bordComputer,"UsbPlayer"), + Arguments.of("[CDPlayer-> play(): without fulfilling preconditions] => ShouldReturnAnException","Case4",bordComputer2,"CDPlayer") ); } From 097a133d26bbded39934024f8decaec672ebac38 Mon Sep 17 00:00:00 2001 From: JPANZO Date: Fri, 18 Feb 2022 18:36:01 +0100 Subject: [PATCH 06/15] BordComputer.play; instance of UsbPlayer -> without fulfilling preconditions: ShouldReturnAnException. --- src/test/java/BordComputerTest.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/test/java/BordComputerTest.java b/src/test/java/BordComputerTest.java index 729d591..0242bcd 100644 --- a/src/test/java/BordComputerTest.java +++ b/src/test/java/BordComputerTest.java @@ -107,6 +107,11 @@ class BordComputerTest { assertEquals(NoItemEvenAllPreconditionAreMet.class, newException.getClass()); assertEquals(newException.getMessage(), "No Item returned even all preconditions are met."); } + if(testCase.equals("Case5")) { + Exception newException = assertThrows(NoItemEvenAllPreconditionAreMet.class, () -> bordComputer.play()); + assertEquals(NoItemEvenAllPreconditionAreMet.class, newException.getClass()); + assertEquals(newException.getMessage(), "No Item returned even all preconditions are met."); + } } static Stream playDate()throws ClassNotFoundException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException { @@ -120,7 +125,8 @@ class BordComputerTest { Arguments.of("[CDPlayer-> play(): after all preconditions are met] => ShouldReturnAnItemToPlay","Case1",bordComputer,"CDPlayer"), Arguments.of("[RadioPlayer-> play(): after all preconditions are met] => ShouldReturnAnItemToPlay","Case2",bordComputer,"RadioPlayer"), Arguments.of("[UsbPlayer-> play(): after all preconditions are met] => ShouldReturnAnItemToPlay","Case3",bordComputer,"UsbPlayer"), - Arguments.of("[CDPlayer-> play(): without fulfilling preconditions] => ShouldReturnAnException","Case4",bordComputer2,"CDPlayer") + Arguments.of("[CDPlayer-> play(): without fulfilling preconditions] => ShouldReturnAnException","Case4",bordComputer2,"CDPlayer"), + Arguments.of("[UsbPlayer-> play(): without fulfilling preconditions] => ShouldReturnAnException","Case5",bordComputer2,"UsbPlayer") ); } From f5aa15071da9ee2a522145d92af800cb683c61de Mon Sep 17 00:00:00 2001 From: JPANZO Date: Fri, 18 Feb 2022 18:48:44 +0100 Subject: [PATCH 07/15] BordComputer.play; instance of RadioPlayer -> without fulfilling preconditions: ShouldWorkWell. --- src/test/java/BordComputerTest.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/test/java/BordComputerTest.java b/src/test/java/BordComputerTest.java index 0242bcd..e9a8309 100644 --- a/src/test/java/BordComputerTest.java +++ b/src/test/java/BordComputerTest.java @@ -108,10 +108,17 @@ class BordComputerTest { assertEquals(newException.getMessage(), "No Item returned even all preconditions are met."); } if(testCase.equals("Case5")) { + Device usbPlayer=bordComputer.getInstanceByName(instanceName); + bordComputer.setActiveDevice(usbPlayer); Exception newException = assertThrows(NoItemEvenAllPreconditionAreMet.class, () -> bordComputer.play()); assertEquals(NoItemEvenAllPreconditionAreMet.class, newException.getClass()); assertEquals(newException.getMessage(), "No Item returned even all preconditions are met."); } + if(testCase.equals("Case6")) { + Device radioPlayer=bordComputer.getInstanceByName(instanceName); + bordComputer.setActiveDevice(radioPlayer); + assertDoesNotThrow(() -> bordComputer.play()); + } } static Stream playDate()throws ClassNotFoundException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException { @@ -126,7 +133,8 @@ class BordComputerTest { Arguments.of("[RadioPlayer-> play(): after all preconditions are met] => ShouldReturnAnItemToPlay","Case2",bordComputer,"RadioPlayer"), Arguments.of("[UsbPlayer-> play(): after all preconditions are met] => ShouldReturnAnItemToPlay","Case3",bordComputer,"UsbPlayer"), Arguments.of("[CDPlayer-> play(): without fulfilling preconditions] => ShouldReturnAnException","Case4",bordComputer2,"CDPlayer"), - Arguments.of("[UsbPlayer-> play(): without fulfilling preconditions] => ShouldReturnAnException","Case5",bordComputer2,"UsbPlayer") + Arguments.of("[UsbPlayer-> play(): without fulfilling preconditions] => ShouldReturnAnException","Case5",bordComputer2,"UsbPlayer"), + Arguments.of("[RadioPlayer-> play(): without fulfilling preconditions] => ShouldWorkWell","Case6",bordComputer2,"RadioPlayer") ); } From fcaa3473ff0952a174b907e09c454d1a9332f93e Mon Sep 17 00:00:00 2001 From: sahar Date: Fri, 18 Feb 2022 19:38:46 +0100 Subject: [PATCH 08/15] 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 09/15] 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 10/15] 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 11/15] 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 12/15] 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 13/15] 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 14/15] 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 15/15] 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