Hello

this patch fixes it:

Index:
container/openejb-junit/src/main/java/org/apache/openejb/junit/jee/statement/InjectStatement.java
===================================================================
---
container/openejb-junit/src/main/java/org/apache/openejb/junit/jee/statement/InjectStatement.java
(revision
1597526)
+++
container/openejb-junit/src/main/java/org/apache/openejb/junit/jee/statement/InjectStatement.java
(working
copy)
@@ -16,17 +16,21 @@
  */
 package org.apache.openejb.junit.jee.statement;

+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import java.util.Hashtable;
+
+import javax.ejb.embeddable.EJBContainer;
+import javax.naming.Context;
+
 import org.apache.openejb.Injector;
 import org.apache.openejb.OpenEJBException;
+import org.apache.openejb.injection.FallbackPropertyInjector;
 import org.apache.openejb.junit.jee.resources.TestResource;
+import org.apache.openejb.loader.SystemInstance;
+import org.apache.openejb.testing.TestInstance;
 import org.junit.runners.model.Statement;

-import javax.ejb.embeddable.EJBContainer;
-import javax.naming.Context;
-import java.lang.reflect.Field;
-import java.lang.reflect.Modifier;
-import java.util.Hashtable;
-
 public class InjectStatement extends Statement {
     private final StartingStatement startingStatement;
     private final Object test;
@@ -66,6 +70,8 @@
             }
         }
         if (test != null) {
+ SystemInstance.get().setComponent(TestInstance.class, new
TestInstance(test.getClass(), test));
+ SystemInstance.get().getComponent(FallbackPropertyInjector.class); //
force eager init (MockitoInjector initialize eveything in its constructor)
             Injector.inject(test);
         }
         if (statement != null) {


You just need to remove your Mockito.init call in your test then



Romain Manni-Bucau
Twitter: @rmannibucau
Blog: http://rmannibucau.wordpress.com/
LinkedIn: http://fr.linkedin.com/in/rmannibucau
Github: https://github.com/rmannibucau


2014-05-26 12:01 GMT+02:00 hwaastad <[email protected]>:

> I guess I must be doing something wrong here:
> Maybe the inject rule?
>
> https://github.com/hwaastad/ContainerTest.git
>
> @ClassRule
>     public static final EJBContainerRule CONTAINER_RULE = new
> EJBContainerRule();
>     @Rule
>     public final InjectRule injectRule = new InjectRule(this,
> CONTAINER_RULE);
>
>     @EJB
>     private HelloBeanLocal helloBeanLocal;
>
>
> @Properties({
>     @Property(key =
> "org.apache.openejb.injection.FallbackPropertyInjector",value =
> "org.apache.openejb.mockito.MockitoInjector")
> })
>
> @Mock
>     private TestBeanLocal mockTestBean;
>
> @Before
>     public void setUp() {
>         MockitoAnnotations.initMocks(this);
>     }
>
>  @Test
>     public void testSayHello() throws Exception {
>         Mockito.when(mockTestBean.doTest()).thenReturn("ompalompa");
>         helloBeanLocal.sayHello();
>     }
>
> But mocking is not working.
>
> No hurry here, i just wanted to implement parts of your blog :-)
>
> br hw
>
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/OpenEJB-TomEE-and-mocking-tp4669665p4669670.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>

Reply via email to