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") ); }