I have a class that Autowires another class with @ConfigurationProperties.
Class with @ConfigurationProperties
@ConfigurationProperties(prefix = "report")
public class SomeProperties {
private String property1;
private String property2;
...
Class that Autowires above class SomeProperties
@Service
@Transactional
public class SomeService {
....
@Autowired
private SomeProperties someProperties;
.... // There are other things
Now, I want to test SomeService class and in my test class when I mock SomeProperties class, I am getting null
value for all the properties.
Test class
@RunWith(SpringRunner.class)
@SpringBootTest(classes = SomeProperties.class)
@ActiveProfiles("test")
@EnableConfigurationProperties
public class SomeServiceTest {
@InjectMocks
private SomeService someService;
@Mock // I tried @MockBean as well, it did not work
private SomeProperties someProperties;
How can I mock SomeProperties having properties from application-test.properties
file.