Browse Source

added BordComputer & BordComputerTest

added first test for readConfig & productive code
feature-pr-BordComputer-readConfig
Jan Ortner 3 years ago
parent
commit
5c1b1bd8a2
  1. 19
      src/main/java/BordComputer.java
  2. 41
      src/test/java/BordComputerTest.java

19
src/main/java/BordComputer.java

@ -0,0 +1,19 @@
import java.io.FileReader;
import java.util.Properties;
public class BordComputer {
String[] deviceNames;
public void readConfig() {
try (FileReader reader = new FileReader("Geraete.config")) {
Properties properties = new Properties();
properties.load(reader);
String[] values = properties.values().toArray(new String[0]);
deviceNames = new String[values.length];
} catch (Exception e) {
e.printStackTrace();
}
}
}

41
src/test/java/BordComputerTest.java

@ -0,0 +1,41 @@
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.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) {
if (testTyp.equals("count")) {
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();
}
assertThat(count).describedAs(testName).isEqualTo(testBc.deviceNames.length);
}
}
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)
);
}
}
Loading…
Cancel
Save