| 1 | package fr.sii.ogham.testing.extension.spring; | |
| 2 | ||
| 3 | import org.slf4j.Logger; | |
| 4 | import org.slf4j.LoggerFactory; | |
| 5 | import org.springframework.beans.factory.annotation.AnnotatedGenericBeanDefinition; | |
| 6 | import org.springframework.beans.factory.config.BeanDefinition; | |
| 7 | import org.springframework.context.ApplicationContext; | |
| 8 | import org.springframework.context.ApplicationContextInitializer; | |
| 9 | import org.springframework.context.ConfigurableApplicationContext; | |
| 10 | import org.springframework.context.support.GenericApplicationContext; | |
| 11 | import org.springframework.core.env.Environment; | |
| 12 | import org.springframework.test.context.support.TestPropertySourceUtils; | |
| 13 | ||
| 14 | import com.icegreen.greenmail.junit4.GreenMailRule; | |
| 15 | ||
| 16 | import fr.sii.ogham.testing.util.RandomPortUtils; | |
| 17 | ||
| 18 | /** | |
| 19 | * Initializer for Spring Boot tests that registers: | |
| 20 | * <ul> | |
| 21 | * <li>{@code "greenmail.smtp.port"} property in Spring {@link Environment}</li> | |
| 22 | * <li>{@link GreenMailRule} bean in Spring {@link ApplicationContext} through | |
| 23 | * {@link GreenMailTestConfiguration} in order to use the port defined by | |
| 24 | * {@code "greenmail.smtp.port"} property</li> | |
| 25 | * </ul> | |
| 26 | * | |
| 27 | * @author Aurélien Baudet | |
| 28 | * | |
| 29 | */ | |
| 30 | public class GreenMailInitializer implements ApplicationContextInitializer<ConfigurableApplicationContext> { | |
| 31 | private static final Logger LOG = LoggerFactory.getLogger(GreenMailInitializer.class); | |
| 32 | ||
| 33 | @Override | |
| 34 | public void initialize(ConfigurableApplicationContext applicationContext) { | |
| 35 |
3
1. initialize : negated conditional → NO_COVERAGE 2. initialize : negated conditional → KILLED 3. initialize : negated conditional → KILLED |
if (applicationContext instanceof GenericApplicationContext) { |
| 36 | BeanDefinition configBean = new AnnotatedGenericBeanDefinition(GreenMailTestConfiguration.class); | |
| 37 |
3
1. initialize : removed call to org/springframework/context/support/GenericApplicationContext::registerBeanDefinition → NO_COVERAGE 2. initialize : removed call to org/springframework/context/support/GenericApplicationContext::registerBeanDefinition → KILLED 3. initialize : removed call to org/springframework/context/support/GenericApplicationContext::registerBeanDefinition → KILLED |
((GenericApplicationContext) applicationContext).registerBeanDefinition("greenMailTestConfiguration", configBean); |
| 38 | } | |
| 39 | int port = RandomPortUtils.findAvailableTcpPort(); | |
| 40 | LOG.debug("Registering {} port for GreenMail SMTP", port); | |
| 41 |
3
1. initialize : removed call to org/springframework/test/context/support/TestPropertySourceUtils::addInlinedPropertiesToEnvironment → NO_COVERAGE 2. initialize : removed call to org/springframework/test/context/support/TestPropertySourceUtils::addInlinedPropertiesToEnvironment → TIMED_OUT 3. initialize : removed call to org/springframework/test/context/support/TestPropertySourceUtils::addInlinedPropertiesToEnvironment → KILLED |
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(applicationContext, "greenmail.smtp.port=" + port); |
| 42 | } | |
| 43 | } | |
Mutations | ||
| 35 |
1.1 2.2 3.3 |
|
| 37 |
1.1 2.2 3.3 |
|
| 41 |
1.1 2.2 3.3 |