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