You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
77 lines
3.1 KiB
77 lines
3.1 KiB
import device.Device;
|
|
import device.radioPlayer.RadioPlayer;
|
|
import org.junit.jupiter.params.ParameterizedTest;
|
|
import org.junit.jupiter.params.provider.Arguments;
|
|
import org.junit.jupiter.params.provider.MethodSource;
|
|
|
|
import java.io.FileReader;
|
|
import java.io.IOException;
|
|
import java.lang.reflect.InvocationTargetException;
|
|
import java.util.Properties;
|
|
import java.util.stream.Stream;
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
import static org.junit.jupiter.api.Assertions.*;
|
|
|
|
class BordComputerTest {
|
|
|
|
@ParameterizedTest
|
|
@MethodSource("readConfigOptions")
|
|
void readConfigTest(String testName, String testTyp, BordComputer testBc, String expectedResult) {
|
|
if (testTyp.equals("count")) {
|
|
assertThat(fileReaderCount()).describedAs(testName).isEqualTo(testBc.deviceNames.length);
|
|
}
|
|
if (testTyp.equals("count1")) {
|
|
assertThat(fileReaderCount()).describedAs(testName).isEqualTo(testBc.installedDevices.length);
|
|
}
|
|
if (testTyp.equals("item1")) {
|
|
assertThat(testBc.deviceNames[0]).describedAs(testName).isEqualTo(expectedResult);
|
|
}
|
|
if (testTyp.equals("item2")) {
|
|
assertThat(testBc.deviceNames[1]).describedAs(testName).isEqualTo(expectedResult);
|
|
}
|
|
if (testTyp.equals("item3")) {
|
|
assertThat(testBc.deviceNames[2]).describedAs(testName).isEqualTo(expectedResult);
|
|
}
|
|
}
|
|
|
|
static Stream<Arguments> readConfigOptions() {
|
|
BordComputer bc1 = new BordComputer();
|
|
bc1.readConfig();
|
|
|
|
return Stream.of(
|
|
Arguments.of("Check if file reader is getting every item in Geraete.config", "count", bc1, ""),
|
|
Arguments.of("Check if file reader is getting the first element", "item1", bc1, "device.cdPlayer.CDPlayer"),
|
|
Arguments.of("Check if file reader is getting the second element", "item2", bc1, "device.radioPlayer.RadioPlayer"),
|
|
Arguments.of("Check if file reader is getting the third element", "item3", bc1, "device.usbPlayer.UsbPlayer"),
|
|
Arguments.of("Test if installed devices has the length", "count1", bc1, "")
|
|
);
|
|
}
|
|
|
|
@ParameterizedTest
|
|
@MethodSource("setDevicesOptions")
|
|
void setDevicesTest(String testName, BordComputer testBc) {
|
|
Device dev = testBc.installedDevices[0];
|
|
assertThat(dev).describedAs(testName).isNotEqualTo(null);
|
|
}
|
|
|
|
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)
|
|
|
|
);
|
|
}
|
|
public int fileReaderCount() {
|
|
int count = 0;
|
|
try (FileReader reader = new FileReader("Geraete.config")) {
|
|
Properties properties = new Properties();
|
|
properties.load(reader);
|
|
count = properties.size();
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
} return count;
|
|
}
|
|
}
|