1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
package info.magnolia.module.blossom.support; |
35 |
|
|
36 |
|
import org.junit.Test; |
37 |
|
import org.springframework.beans.BeansException; |
38 |
|
import org.springframework.beans.factory.config.BeanFactoryPostProcessor; |
39 |
|
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; |
40 |
|
import org.springframework.context.support.ClassPathXmlApplicationContext; |
41 |
|
import static org.junit.Assert.assertEquals; |
42 |
|
import static org.junit.Assert.assertFalse; |
43 |
|
import static org.junit.Assert.assertSame; |
44 |
|
import static org.junit.Assert.assertTrue; |
45 |
|
import static org.mockito.Mockito.mock; |
46 |
|
|
47 |
|
import info.magnolia.module.blossom.dispatcher.BlossomDispatcher; |
48 |
|
import info.magnolia.module.blossom.dispatcher.BlossomDispatcherAwareBeanPostProcessor; |
49 |
|
import info.magnolia.module.blossom.dispatcher.BlossomDispatcherInitializedEvent; |
50 |
|
|
51 |
|
|
52 |
|
@since |
53 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (15) |
Complexity: 2 |
Complexity Density: 0.15 |
|
54 |
|
public class AbstractBeanDetectorTest { |
55 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
56 |
1 |
@Test... |
57 |
|
public void testBeanDetection() { |
58 |
|
|
59 |
1 |
final BlossomDispatcher dispatcher = mock(BlossomDispatcher.class); |
60 |
1 |
final ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[] {"classpath:info/magnolia/module/blossom/support/AbstractBeanDetector-test.xml"}, false); |
61 |
1 |
context.addBeanFactoryPostProcessor(new BeanFactoryPostProcessor() { |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
62 |
1 |
@Override... |
63 |
|
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { |
64 |
1 |
beanFactory.addBeanPostProcessor(new BlossomDispatcherAwareBeanPostProcessor(dispatcher)); |
65 |
|
} |
66 |
|
}); |
67 |
1 |
context.refresh(); |
68 |
1 |
context.publishEvent(new BlossomDispatcherInitializedEvent(dispatcher)); |
69 |
|
|
70 |
1 |
MockBeanDetector bean = (MockBeanDetector) context.getBean("tester"); |
71 |
1 |
assertEquals(2, bean.getNumMatches()); |
72 |
1 |
assertFalse(bean.matched("abstract")); |
73 |
1 |
assertTrue(bean.matched("prototype")); |
74 |
1 |
assertTrue(bean.matched("singleton")); |
75 |
1 |
assertEquals(String.class, bean.getType()); |
76 |
1 |
assertSame(context, bean.getApplicationContext()); |
77 |
|
} |
78 |
|
} |