Browse Source

revised all test for setDevices now testing if every installed devices has the right instance & added productive code

feature-pr-BordComputer-setDevices
Jan Ortner 3 years ago
parent
commit
ab054d5dfe
  1. 3
      src/main/java/BordComputer.java
  2. 27
      src/test/java/BordComputerTest.java

3
src/main/java/BordComputer.java

@ -11,7 +11,7 @@ public class BordComputer {
Device[] installedDevices;
Device activeDevice = null;
public void readConfig() {
public void readConfig() throws ClassNotFoundException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
try (FileReader reader = new FileReader("Geraete.config")) {
Properties properties = new Properties();
@ -24,6 +24,7 @@ public class BordComputer {
} catch (Exception e) {
e.printStackTrace();
}
setDevices();
activeDevice = installedDevices[0];
}

27
src/test/java/BordComputerTest.java

@ -1,5 +1,7 @@
import device.Device;
import device.cdPlayer.CDPlayer;
import device.radioPlayer.RadioPlayer;
import device.usbPlayer.UsbPlayer;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
@ -35,7 +37,7 @@ class BordComputerTest {
}
}
static Stream<Arguments> readConfigOptions() {
static Stream<Arguments> readConfigOptions() throws ClassNotFoundException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
BordComputer bc1 = new BordComputer();
bc1.readConfig();
@ -50,24 +52,24 @@ class BordComputerTest {
@ParameterizedTest
@MethodSource("setDevicesOptions")
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);
void setDevicesTest(String testName, BordComputer testBc, String testTyp, Boolean bool) {
Boolean boolActual = null;
if (testTyp.equals("0")) boolActual = (testBc.installedDevices[0] instanceof CDPlayer);
if (testTyp.equals("1")) boolActual = (testBc.installedDevices[1] instanceof RadioPlayer);
if (testTyp.equals("2")) boolActual = (testBc.installedDevices[2] instanceof UsbPlayer);
assertThat(boolActual).describedAs(testName).isEqualTo(bool);
}
static Stream<Arguments> setDevicesOptions() throws ClassNotFoundException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
BordComputer bc = new BordComputer();
bc.readConfig();
bc.setDevices();
return Stream.of(
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")
Arguments.of("Test if installedDevices[0] is instance of CDPlayer", bc, "0", true),
Arguments.of("Test if installedDevices[1] is instance of RadioPlayer", bc, "1", true),
Arguments.of("Test if installedDevices[2] is instance of UsbPlayer", bc, "2", true)
);
}
public int fileReaderCount() {
int count = 0;
try (FileReader reader = new FileReader("Geraete.config")) {
@ -76,6 +78,7 @@ class BordComputerTest {
count = properties.size();
} catch (IOException e) {
e.printStackTrace();
} return count;
}
return count;
}
}
Loading…
Cancel
Save