From 4bd3d5acd261a64d00699d9f8f0038cfe624a412 Mon Sep 17 00:00:00 2001 From: alpina0707 Date: Thu, 17 Feb 2022 19:40:52 +0100 Subject: [PATCH] added second and third test case for setDevices() & productive code --- src/main/java/BordComputer.java | 6 ++++-- src/test/java/BordComputerTest.java | 12 ++++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/main/java/BordComputer.java b/src/main/java/BordComputer.java index dbf777c..5f92057 100644 --- a/src/main/java/BordComputer.java +++ b/src/main/java/BordComputer.java @@ -29,7 +29,9 @@ public class BordComputer { public void setDevices() throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException, ClassNotFoundException { Class c; - c= Class.forName(deviceNames[0]); - installedDevices[0] = (Device) c.getConstructor().newInstance(); + for(int i = 0;i < deviceNames.length; i++) { + c = Class.forName(deviceNames[i]); + installedDevices[i] = (Device) c.getConstructor().newInstance(); + } } } diff --git a/src/test/java/BordComputerTest.java b/src/test/java/BordComputerTest.java index 834a958..8a38b9b 100644 --- a/src/test/java/BordComputerTest.java +++ b/src/test/java/BordComputerTest.java @@ -50,8 +50,11 @@ class BordComputerTest { @ParameterizedTest @MethodSource("setDevicesOptions") - void setDevicesTest(String testName, BordComputer testBc) { - Device dev = testBc.installedDevices[0]; + void setDevicesTest(String testName, BordComputer testBc, String testTyp) { + Device dev = null; + if(testTyp.equals("0")) dev = testBc.installedDevices[0]; + if(testTyp.equals("1")) dev = testBc.installedDevices[1]; + if(testTyp.equals("2")) dev = testBc.installedDevices[2]; assertThat(dev).describedAs(testName).isNotEqualTo(null); } @@ -60,8 +63,9 @@ class BordComputerTest { bc.readConfig(); bc.setDevices(); return Stream.of( - Arguments.of("Test if installedDevices[0] is not null", bc) - + Arguments.of("Test if installedDevices[0] is not null", bc, "0"), + Arguments.of("Test if installedDevices[1] is not null", bc, "1"), + Arguments.of("Test if installedDevices[2] is not null", bc, "2") ); } public int fileReaderCount() {