cdi-unit

CDI-Unit @Produces not working

送分小仙女□ 提交于 2019-12-24 11:36:11
问题 First off I googled intensively and according to http://jglue.org/cdi-unit-user-guide/ producing stuff to inject in a unit test should work just fine. My setup: @RunWith(CdiRunner.class) public abstract class CdiUnitBaseTest extends DBUnitBaseTest { @Produces public EntityManager em() { return em; //field from base class filled @BeforeClass } @Produces public Logger logger() { return LogManager.getLogger(); } } public class SurveyBeanTest extends CdiUnitBaseTest { @Inject private SurveyBean

Injection of @PersistenceContext in CDI-Unit

a 夏天 提交于 2019-12-09 06:57:33
问题 Here is the unit testing code. When we run unit test code (SampleServiceTest2); EntityManager injected in AbstractDao is always null! How can we inject em during unit test. *** SampleServiceTest2.java import javax.inject.Inject; import org.jglue.cdiunit.CdiRunner; import org.junit.Test; import org.junit.runner.RunWith; @RunWith(CdiRunner.class) public class SampleServiceTest2 { @Inject SampleService greeter; @Test public void testGreeter() throws Exception { System.out.println("before2");

CdiUnit test with Junit @Rule is impossible because of a public private field paradox

余生长醉 提交于 2019-12-06 01:45:50
问题 The following snippet is enough to reproduce my problem: Either I set the thrown attribute public and get the error org.jboss.weld.exceptions.DefinitionException: WELD-000075: Normal scoped managed bean implementation class has a public field Or I remove the public modifier and get the error org.junit.internal.runners.rules.ValidationError: The @Rule 'thrown' must be public. I also tried to let the public modifier in place and to add the @Dependent annotation scope on the class, but got error

Injection of @PersistenceContext in CDI-Unit

时光怂恿深爱的人放手 提交于 2019-12-03 08:52:30
Here is the unit testing code. When we run unit test code (SampleServiceTest2); EntityManager injected in AbstractDao is always null! How can we inject em during unit test. *** SampleServiceTest2.java import javax.inject.Inject; import org.jglue.cdiunit.CdiRunner; import org.junit.Test; import org.junit.runner.RunWith; @RunWith(CdiRunner.class) public class SampleServiceTest2 { @Inject SampleService greeter; @Test public void testGreeter() throws Exception { System.out.println("before2"); greeter.addSampleData(new SampleDataDto(), new KullaniciDto()); System.out.println("after2"); } } ***