Skip to content

Commit

Permalink
Add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
FDelporte committed Jul 29, 2024
1 parent b852320 commit 9d3e9a7
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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 =
Expand All @@ -14,4 +17,8 @@ public class ContextAutoConfigurationTests {
)
);

@Bean
public ContextConfiguration contextConfiguration() {
return new ContextConfiguration();
}
}
Original file line number Diff line number Diff line change
@@ -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());
}
}

}

0 comments on commit 9d3e9a7

Please sign in to comment.