I have records taking values from configuration properties:
@ConfigurationProperties(prefix = "car")
public record CarConfig(Type type) {
public record Type() {}
}
I cannot put there @Configuration
annotation cause as it is a record, it is immutable.
Now - I would like to test it and it's not a problem when I will use @SpringBootTest
with all context but I prefer to not do this.
Instead of this I created something like that:
@EnableConfigurationProperties(value = CarConfig.class)
@ExtendWith(SpringExtension.class)
class CarConfigTest {
@Autowired
private CarConfig carConfig;
@Test
void shouldReadConfigValues() {
// some assertions
}
I'm getting an error that it cannot autowire carConfig.class and it make sense as CarConfig is not Spring annotated class.
So my question is - is it possible to test CarConfig without @SpringBootTest annotation? If yes, what should I use?