I have a Spring bean that reads a configuration property value from application.yml
public class AutoDisableRolesService {
@Value("${cron.enabled}")
private boolean runTask;
// remainder of class omitted
}
In the application.yml this property is set to false
cron:
enabled: false
But when I run the test, I want it to be true. I've tried the following, but it does not seem to work
@SpringBootTest(properties = { "cron.enabled=true" })
@ExtendWith(MockitoExtension.class)
public class AutoDisableRolesServiceTests {
@Mock
private UserRoleRepository userRoleRepository;
@InjectMocks
private AutoDisableRolesService autoDisableRolesService;
// remainder of test class omitted
}
I've also tried the following, without success
@ContextConfiguration(classes = AutoDisableRolesService.class)
@TestPropertySource(properties = "cron.enabled=true")
@ExtendWith(MockitoExtension.class)
public class AutoDisableRolesServiceTests {
@Mock
private UserRoleRepository userRoleRepository;
@InjectMocks
private AutoDisableRolesService autoDisableRolesService;
// remainder of test class omitted
}