682ea88256adb646ad35e7fe9f25809c47d47283
[utils] / test / enterprise / src / test / java / org / wamblee / test / inject / JavaEETestInjectorFactoryTest.java
1 package org.wamblee.test.inject;
2
3 import javax.persistence.EntityManager;
4 import javax.persistence.PersistenceContext;
5
6 import org.junit.Test;
7 import org.wamblee.inject.InjectorBuilder;
8
9 import static org.mockito.Mockito.*;
10 import static junit.framework.TestCase.*;
11
12 public class JavaEETestInjectorFactoryTest {
13     
14     @PersistenceContext
15     private EntityManager entityManager; 
16     
17     private EntityManager entityManager2; 
18    
19     @PersistenceContext
20     public EntityManager getEntityManager() { 
21         return entityManager2;
22     }
23     
24     public void setEntityManager(EntityManager aEm) { 
25         entityManager2 = aEm;
26     }
27
28     @Test
29     public void testXyz() { 
30         EntityManager em = mock(EntityManager.class);
31         InjectorBuilder.setInjectorFactory(new JavaEETestInjectorFactory(em));
32        
33         assertNull(entityManager);
34         assertNull(entityManager2);
35         InjectorBuilder.getInjector().inject(this);
36         
37         assertNotNull(em);
38         assertSame(em, entityManager); 
39         assertSame(em, entityManager2);
40     }
41     
42     public static class X { 
43         @PersistenceContext
44         Integer wrongType; 
45     }
46     
47     @Test(expected = IllegalArgumentException.class)
48     public void testWrongType() { 
49         EntityManager em = mock(EntityManager.class);
50         InjectorBuilder.setInjectorFactory(new JavaEETestInjectorFactory(em));
51         X x= new X(); 
52         InjectorBuilder.getInjector().inject(x);
53     }
54 }