I have two implementations of one interface - default and dev. I use @ConditionalOnProperty for default implementation and combination of @Profile and @ConditionalOnMissingBean for dev implementation.
@Service
@ConditionalOnProperty(prefix = "keystore", value = "file")
public class DefaultKeyStoreService implements KeyStoreService {
@Service
@Profile("dev")
@ConditionalOnMissingBean(KeyStoreService.class)
public class DevKeyStoreService implements KeyStoreService {
Now, the problem is in test DevKeyStoreServiceTest for DevKeyStoreService.
I have configuration like this:
@SpringBootTest(
classes = {DevKeyStoreService.class},
properties = {"keystore.file="}
)
@RunWith(SpringRunner.class)
@ActiveProfiles("dev")
public class DevKeyStoreServiceTest {
@Autowired
private DevKeyStoreService tested;
@Test
public void testPrivateKey() {
} //... etc.
The result is:
Negative matches:
-----------------
DevKeyStoreService:
Did not match:
- @ConditionalOnMissingBean (types: service.crypto.KeyStoreService; SearchStrategy: all) found bean 'devKeyStoreService' (OnBeanCondition)
and the typical org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'service.crypto.DevKeyStoreServiceTest'....
How can I configure the test class to be able to run it?