From 1e7a8129ff9836cd6a22a038f2f0a3c48bd88c2d Mon Sep 17 00:00:00 2001 From: sahar Date: Fri, 18 Feb 2022 15:21:05 +0100 Subject: [PATCH] BordComputerTest.changeDeviceTest First case --- src/main/java/BordComputer.java | 10 ++++++++++ src/test/java/BordComputerTest.java | 27 +++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/src/main/java/BordComputer.java b/src/main/java/BordComputer.java index 7563899..cfc05d2 100644 --- a/src/main/java/BordComputer.java +++ b/src/main/java/BordComputer.java @@ -35,4 +35,14 @@ public class BordComputer { installedDevices[i] = (Device) c.getConstructor().newInstance(); } } + + public void changeDevice() { + Device[] tempDevices=new Device[installedDevices.length]; + tempDevices[0]=installedDevices[1]; + tempDevices[1]=installedDevices[2]; + tempDevices[2]=installedDevices[0]; + //replaces the lists + installedDevices=tempDevices; + + } } diff --git a/src/test/java/BordComputerTest.java b/src/test/java/BordComputerTest.java index 6772d99..eb9ab34 100644 --- a/src/test/java/BordComputerTest.java +++ b/src/test/java/BordComputerTest.java @@ -1,6 +1,7 @@ import device.Device; import device.cdPlayer.CDPlayer; import device.radioPlayer.RadioPlayer; +import device.usbPlayer.USB_Stick; import device.usbPlayer.UsbPlayer; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; @@ -80,5 +81,31 @@ class BordComputerTest { e.printStackTrace(); } return count; + }//changeDevice() + + @ParameterizedTest + @MethodSource("changeDeviceOptions") + void changeDeviceTest(String testName, BordComputer inputBC, Device[] oldDevices ,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(); + bc.changeDevice(); + + return Stream.of( + Arguments.of("The order of the installedDevices should be changed ", bc,currentDevices,1) + ); + } + + } \ No newline at end of file