I have implemented a map in my yaml file as below
replacement:
ID:
0000000016: 9000000011
0000000013: 8000000014
0000000002: 9000000000
Config class :-
@Configuration
@NoArgsConstructor
@AllArgsConstructor
@ConfigurationProperties(prefix = "replacement")
@Getter
@Setter
public class SourceConfig {
private Map<String, String> ID = new HashMap<>();
}
Test class:-
@ExtendWith(SpringExtension.class)
@EnableConfigurationProperties(value = SourceConfig.class)
@TestPropertySource("classpath:yaml file name")
class SourceConfigTest {
@Autowired
private SourceConfig sourceconfig;
@Test
void getID() {
assertThat(sourceconfig).isNotNull();
assertTrue(sourceconfig.getID().containsKey("0000000016"));
}
}
When I run the test class sourceconfig.getID() throws a null pointer exception. Please help/suggest
I expected the assert to be true and also fetch my values from map