From: Erik Brakkee Date: Fri, 23 Jul 2010 19:26:17 +0000 (+0000) Subject: (no commit message) X-Git-Tag: wamblee-utils-0.7~191 X-Git-Url: http://wamblee.org/gitweb/?a=commitdiff_plain;h=e1e12c6f6eb2be95334740b06c4615b763456603;p=utils --- 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 index 00000000..0ca9c021 --- /dev/null +++ b/test/enterprise/src/test/java/org/wamblee/test/inject/JavaEETestInjectorFactoryTest.java @@ -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); + } +}