BAEL-5027: Use BuildProperties bean for getting build information (#13794)

Co-authored-by: Tapan Avasthi <tavasthi@Tapans-MacBook-Air.local>
This commit is contained in:
Tapan Avasthi
2023-04-11 04:26:04 +05:30
committed by GitHub
parent 42dff48c7d
commit e8d8611e6e
2 changed files with 51 additions and 2 deletions
@@ -0,0 +1,30 @@
package com.baeldung.buildproperties;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.info.BuildProperties;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit.jupiter.SpringExtension;
@SpringBootTest
@ExtendWith(SpringExtension.class)
public class BuildPropertiesUnitTest {
@Autowired
private BuildProperties buildProperties;
@Test
void givenBuildPropertiesBean_WhenFetchDefaultBuildProperties_ThenGetValidValues() {
Assertions.assertEquals("spring-boot-properties", buildProperties.getArtifact());
Assertions.assertEquals("com.baeldung.spring-boot-modules", buildProperties.getGroup());
Assertions.assertEquals("0.0.1-SNAPSHOT", buildProperties.getVersion());
}
@Test
void givenBuildPropertiesBean_WhenFetchCustomBuildProprties_ThenGetValidValues() {
Assertions.assertEquals("123", buildProperties.get("custom.value"));
Assertions.assertNotNull(buildProperties.get("java.version"));
Assertions.assertEquals("Spring Boot Properties Module", buildProperties.get("description"));
}
}