From fcaa3473ff0952a174b907e09c454d1a9332f93e Mon Sep 17 00:00:00 2001 From: sahar Date: Fri, 18 Feb 2022 19:38:46 +0100 Subject: [PATCH] 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