From: erik Date: Fri, 23 Jul 2010 19:26:17 +0000 (+0000) Subject: (no commit message) X-Git-Tag: wamblee-utils-0.4~11 X-Git-Url: http://wamblee.org/gitweb/?a=commitdiff_plain;ds=inline;h=54229c38bf29738b9497d1d2bd3d5da5501c77f6;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); + } +}