2 Replies Latest reply on Oct 9, 2013 2:57 PM by THIAGO VARGAS

    NullPointerException with @Inject

    Gustavo Figueiredo Newbie

      Guys, for 2 weeks, I'm trying to put Arquillian to work, but i'm always getting NullPointerException, so in my project we use, ant + ivy to build de appliccation, and jboss6.

       

      This is my project structure:

      estrutura projeto.jpg

       

      This is  the naive teste, i'm trying to run.

       

       

      @RunWith(Arquillian.class)
      public class SayHelloTest {
      
        @EJB
        SayHelloInterface say;
      
        @Deployment
        public static JavaArchive createDeployment(){
             JavaArchive jar = ShrinkWrap.create(JavaArchive.class);
             jar.addClasses(SayHello.class).addClasses(SayHelloInterface.class);
             jar.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
             System.out.println(jar.toString(true));
         
             return jar;
         }
         
        @Test
        public void sayHallo(){
         //say = new SayHello();
             String result = say.sayHello("hehe");
             assertEquals("Hallo hehe", result);
          }
         
         
        @Test
        public void number(){
             assertEquals("Hallo hehe", "Hallo hehe");
        }
      }
      

       

      This is the dependencys that I put on ivy.xml

       

       <dependency org="org.jboss.spec" name="jboss-javaee-6.0" rev="${version.jboss_javaee6_spec}" conf="test-weld-embedded->compile(*)"/>
        <dependency org="javax.enterprise" name="cdi-api" rev="1.1-20130403"/>
                  
              <dependency org="org.jboss.arquillian.junit" name="arquillian-junit-container" rev="${version.arquillian}" conf="test->default(*)"/>
              <dependency org="org.jboss.arquillian" name="arquillian-bom" rev="${version.arquillian}"  conf="test->default(*)"/>
              <dependency org="junit" name="junit" rev="${version.junit}" conf="test->default(*)"/>
              <dependency org="org.hamcrest" name="hamcrest-core" rev="${version.hamcrest}" conf="test->default(*)"/>
      
      
              <dependency org="org.jboss.weld.arquillian.container" name="arquillian-weld-ee-embedded-1.1" rev="${version.arquillian}" conf="test-weld-embedded->default(*)"/>
              <dependency org="org.jboss.spec" name="jboss-javaee-6.0" rev="${version.jboss_javaee6_spec}" conf="test-weld-embedded->compile(*)"/>
              <dependency org="org.jboss.arquillian.container" name="arquillian-jbossas-embedded-6" rev="1.0.0.CR3" conf="test-weld-embedded->compile(*)"/>
              <dependency org="javax.inject" name="javax.inject" rev="1"/>
                  
                  
      
      
              <dependency org="org.jboss.weld" name="weld-core" rev="${version.weld_core}" conf="test-weld-embedded->default(*)"/>
              <dependency org="org.slf4j" name="slf4j-log4j12" rev="${version.slf4j}" conf="test-weld-embedded->default(*)"/>
              <dependency org="log4j" name="log4j" rev="${version.log4j}" conf="test-weld-embedded->default(*)"/>
      

       

       

      And this is the error:

       

      Testsuite: br.gov.rj.mis.controller.sessionBean.SayHelloTest

      Tests run: 2, Failures: 0, Errors: 1, Time elapsed: 0,24 sec

       

       

      Testcase: number took 0,018 sec

      Testcase: sayHallo took 0,009 sec

        Caused an ERROR

      null

      java.lang.NullPointerException

        at br.gov.rj.mis.controller.sessionBean.SayHelloTest.sayHallo(SayHelloTest.java:35)

        at org.jboss.arquillian.junit.Arquillian$6$1.invoke(Arquillian.java:270)

        at org.jboss.arquillian.container.test.impl.execution.LocalTestExecuter.execute(LocalTestExecuter.java:60)

        at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)

        at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:99)

        at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:81)

        at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:135)

        at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:115)

        at org.jboss.arquillian.core.impl.EventImpl.fire(EventImpl.java:67)

        at org.jboss.arquillian.container.test.impl.execution.ClientTestExecuter.execute(ClientTestExecuter.java:53)

        at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)

        at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:99)

        at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:81)

        at org.jboss.arquillian.container.test.impl.client.ContainerEventController.createContext(ContainerEventController.java:142)

        at org.jboss.arquillian.container.test.impl.client.ContainerEventController.createTestContext(ContainerEventController.java:129)

        at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)

        at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)

        at org.jboss.arquillian.test.impl.TestContextHandler.createTestContext(TestContextHandler.java:89)

        at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)

        at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)

        at org.jboss.arquillian.test.impl.TestContextHandler.createClassContext(TestContextHandler.java:75)

        at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)

        at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)

        at org.jboss.arquillian.test.impl.TestContextHandler.createSuiteContext(TestContextHandler.java:60)

        at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)

        at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)

        at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:135)

        at org.jboss.arquillian.test.impl.EventTestRunnerAdaptor.test(EventTestRunnerAdaptor.java:111)

        at org.jboss.arquillian.junit.Arquillian$6.evaluate(Arquillian.java:263)

        at org.jboss.arquillian.junit.Arquillian$4.evaluate(Arquillian.java:226)

        at org.jboss.arquillian.junit.Arquillian.multiExecute(Arquillian.java:314)

        at org.jboss.arquillian.junit.Arquillian.access$100(Arquillian.java:46)

        at org.jboss.arquillian.junit.Arquillian$5.evaluate(Arquillian.java:240)

        at org.jboss.arquillian.junit.Arquillian$2.evaluate(Arquillian.java:185)

        at org.jboss.arquillian.junit.Arquillian.multiExecute(Arquillian.java:314)

        at org.jboss.arquillian.junit.Arquillian.access$100(Arquillian.java:46)

        at org.jboss.arquillian.junit.Arquillian$3.evaluate(Arquillian.java:199)

        at org.jboss.arquillian.junit.Arquillian.run(Arquillian.java:147)

       

      What I'm doing wrong ?