(no commit message)
authorerik <erik@77661180-640e-0410-b3a8-9f9b13e6d0e0>
Fri, 23 Jul 2010 19:26:17 +0000 (19:26 +0000)
committererik <erik@77661180-640e-0410-b3a8-9f9b13e6d0e0>
Fri, 23 Jul 2010 19:26:17 +0000 (19:26 +0000)
test/enterprise/src/test/java/org/wamblee/test/inject/JavaEETestInjectorFactoryTest.java [new file with mode: 0644]

diff --git a/test/enterprise/src/test/java/org/wamblee/test/inject/JavaEETestInjectorFactoryTest.java b/test/enterprise/src/test/java/org/wamblee/test/inject/JavaEETestInjectorFactoryTest.java
new file mode 100644 (file)
index 0000000..0ca9c02
--- /dev/null
@@ -0,0 +1,54 @@
+package org.wamblee.test.inject;
+
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+
+import org.junit.Test;
+import org.wamblee.inject.InjectorFactoryBuilder;
+
+import static org.mockito.Mockito.*;
+import static junit.framework.TestCase.*;
+
+public class JavaEETestInjectorFactoryTest {
+    
+    @PersistenceContext
+    private EntityManager entityManager; 
+    
+    private EntityManager entityManager2; 
+   
+    @PersistenceContext
+    public EntityManager getEntityManager() { 
+        return entityManager2;
+    }
+    
+    public void setEntityManager(EntityManager aEm) { 
+        entityManager2 = aEm;
+    }
+
+    @Test
+    public void testXyz() { 
+        EntityManager em = mock(EntityManager.class);
+        InjectorFactoryBuilder.setInjectorFactory(new JavaEETestInjectorFactory(em));
+       
+        assertNull(entityManager);
+        assertNull(entityManager2);
+        InjectorFactoryBuilder.getInjector().inject(this);
+        
+        assertNotNull(em);
+        assertSame(em, entityManager); 
+        assertSame(em, entityManager2);
+    }
+    
+    public static class X { 
+        @PersistenceContext
+        Integer wrongType; 
+    }
+    
+    @Test(expected = IllegalArgumentException.class)
+    public void testWrongType() { 
+        EntityManager em = mock(EntityManager.class);
+        InjectorFactoryBuilder.setInjectorFactory(new JavaEETestInjectorFactory(em));
+        X x= new X(); 
+        InjectorFactoryBuilder.getInjector().inject(x);
+    }
+}