Browse Source

added second and third test case for setDevices() & productive code

feature-pr-BordComputer-setDevices
Jan Ortner 3 years ago
parent
commit
4bd3d5acd2
  1. 6
      src/main/java/BordComputer.java
  2. 12
      src/test/java/BordComputerTest.java

6
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();
}
}
}

12
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() {

Loading…
Cancel
Save