|
| 1 | +package com.baeldung; |
| 2 | + |
| 3 | +import org.junit.Test; |
| 4 | +import org.junit.runner.RunWith; |
| 5 | +import org.springframework.beans.BeansException; |
| 6 | +import org.springframework.beans.factory.InitializingBean; |
| 7 | +import org.springframework.context.ApplicationContext; |
| 8 | +import org.springframework.context.ApplicationContextAware; |
| 9 | +import org.springframework.context.annotation.Configuration; |
| 10 | +import org.springframework.test.context.ContextConfiguration; |
| 11 | +import org.springframework.test.context.junit4.SpringRunner; |
| 12 | + |
| 13 | +import java.util.concurrent.TimeUnit; |
| 14 | + |
| 15 | +import static org.junit.Assert.assertNotNull; |
| 16 | +import static org.junit.Assert.assertTrue; |
| 17 | + |
| 18 | +/** |
| 19 | + * @author aiet |
| 20 | + */ |
| 21 | +@RunWith(SpringRunner.class) |
| 22 | +@ContextConfiguration(classes = Spring5JUnit4ConcurrentIntegrationTest.SimpleConfiguration.class) |
| 23 | +public class Spring5JUnit4ConcurrentIntegrationTest implements ApplicationContextAware, InitializingBean { |
| 24 | + |
| 25 | + @Configuration |
| 26 | + public static class SimpleConfiguration { |
| 27 | + } |
| 28 | + |
| 29 | + private ApplicationContext applicationContext; |
| 30 | + |
| 31 | + private boolean beanInitialized = false; |
| 32 | + |
| 33 | + @Override |
| 34 | + public final void afterPropertiesSet() throws Exception { |
| 35 | + this.beanInitialized = true; |
| 36 | + } |
| 37 | + |
| 38 | + @Override |
| 39 | + public final void setApplicationContext(final ApplicationContext applicationContext) throws BeansException { |
| 40 | + this.applicationContext = applicationContext; |
| 41 | + } |
| 42 | + |
| 43 | + @Test |
| 44 | + public final void verifyApplicationContextSet() throws InterruptedException { |
| 45 | + TimeUnit.SECONDS.sleep(2); |
| 46 | + assertNotNull("The application context should have been set due to ApplicationContextAware semantics.", this.applicationContext); |
| 47 | + } |
| 48 | + |
| 49 | + @Test |
| 50 | + public final void verifyBeanInitialized() throws InterruptedException { |
| 51 | + TimeUnit.SECONDS.sleep(2); |
| 52 | + assertTrue("This test bean should have been initialized due to InitializingBean semantics.", this.beanInitialized); |
| 53 | + } |
| 54 | + |
| 55 | +} |
| 56 | + |
| 57 | + |
0 commit comments