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()); + } + } + +}