From 9d3e9a742824f7bcb7ab82ba7b4bde7e7d93c82b Mon Sep 17 00:00:00 2001 From: Frank Delporte Date: Mon, 29 Jul 2024 10:57:22 +0200 Subject: [PATCH] Add unit test --- .../boot/ContextAutoConfigurationTests.java | 7 ++++ .../com/pi4j/spring/boot/ContextTest.java | 35 +++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 pi4j-spring-boot/src/test/java/com/pi4j/spring/boot/ContextTest.java diff --git a/pi4j-spring-boot/src/test/java/com/pi4j/spring/boot/ContextAutoConfigurationTests.java b/pi4j-spring-boot/src/test/java/com/pi4j/spring/boot/ContextAutoConfigurationTests.java index bf4425a..73f08b1 100644 --- a/pi4j-spring-boot/src/test/java/com/pi4j/spring/boot/ContextAutoConfigurationTests.java +++ b/pi4j-spring-boot/src/test/java/com/pi4j/spring/boot/ContextAutoConfigurationTests.java @@ -1,9 +1,12 @@ package com.pi4j.spring.boot; import org.springframework.boot.test.context.runner.ApplicationContextRunner; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; import static org.springframework.boot.autoconfigure.AutoConfigurations.of; +@Configuration public class ContextAutoConfigurationTests { private final ApplicationContextRunner contextRunner = @@ -14,4 +17,8 @@ public class ContextAutoConfigurationTests { ) ); + @Bean + public ContextConfiguration contextConfiguration() { + return new ContextConfiguration(); + } } diff --git a/pi4j-spring-boot/src/test/java/com/pi4j/spring/boot/ContextTest.java b/pi4j-spring-boot/src/test/java/com/pi4j/spring/boot/ContextTest.java new file mode 100644 index 0000000..5cdfcb7 --- /dev/null +++ b/pi4j-spring-boot/src/test/java/com/pi4j/spring/boot/ContextTest.java @@ -0,0 +1,35 @@ +package com.pi4j.spring.boot; + +import com.pi4j.boardinfo.definition.BoardModel; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; + +import static org.junit.jupiter.api.Assertions.*; + +@SpringBootTest(classes = ContextAutoConfigurationTests.class) +class ContextTest { + + @Autowired + ContextConfiguration contextConfiguration; + + @Test + void contextLoads() { + assertAll( + () -> assertNotNull(contextConfiguration.context()), + () -> assertNotNull(contextConfiguration.context().boardInfo().getBoardModel()) + ); + } + + @Test + void boardUnkownIfNotRunningOnPi() { + String osName = System.getProperty("os.name").toLowerCase(); + String osArch = System.getProperty("os.arch").toLowerCase(); + if (osName.contains("linux") && osArch.contains("arm")) { + assertNotEquals(BoardModel.UNKNOWN, contextConfiguration.context().boardInfo().getBoardModel()); + } else { + assertEquals(BoardModel.UNKNOWN, contextConfiguration.context().boardInfo().getBoardModel()); + } + } + +}