--- /dev/null
+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);
+ }
+}