From 5c1b1bd8a2dc375b236154b5d673134314c214da Mon Sep 17 00:00:00 2001 From: alpina0707 Date: Thu, 17 Feb 2022 17:57:06 +0100 Subject: [PATCH] added BordComputer & BordComputerTest added first test for readConfig & productive code --- src/main/java/BordComputer.java | 19 +++++++++++++ src/test/java/BordComputerTest.java | 41 +++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 src/main/java/BordComputer.java create mode 100644 src/test/java/BordComputerTest.java diff --git a/src/main/java/BordComputer.java b/src/main/java/BordComputer.java new file mode 100644 index 0000000..3b01ee2 --- /dev/null +++ b/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(); + } + } +} diff --git a/src/test/java/BordComputerTest.java b/src/test/java/BordComputerTest.java new file mode 100644 index 0000000..2659039 --- /dev/null +++ b/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 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) + ); + } + +} \ No newline at end of file