4 Replies Latest reply on Jan 5, 2014 2:00 PM by Radim Hanus

    Observing in Arquillian, event not propagated to injected bean

    Matthew Young Newbie

      Using Arquillian JUnit (version 1.1.1 respectively 4.11) to setup my CDI (1.0.0.CR7 on Weld 1.1.13.Final) embedded with JDK 1.7.25....


      Got the following classes:

      public class Receiver {

      private String message;


      public void catching(@Observes DummyEvent event) {

      System.out.println(String.format("message [%s], hash [%d]", event.getMessage(), hashCode()));

      this.message = event.getMessage();



      public String getMessage() {

      return this.message;




      public class Sender {

      @Inject @Any

      Event<DummyEvent> e;


      public void fire(String message) {

      System.out.println(String.format("fire message [%s], hash [%d]", message, hashCode()));


      DummyEvent de = new DummyEvent;







      public class Example {


      public static JavaArchive createDeployment() {

      return ShrinkWrap.create(JavaArchive.class).addClasses(Example .class, Receiver.class, Sender.class)

               .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");




      Receiver receiver;



      Sender sender;



      public void dummy() {

      System.out.println(String.format("sender hash [%d]", sender.hashCode()));

      sender.fire("Hello from me");


      System.out.println(String.format("message [%s], receiver hash: [%d]",

      receiver.getMessage(), receiver.hashCode()));




      What gets printed is the following:

      sender hash [785714873]

      firing event [value: Hello from me], hash [785714873]

      message [Hello from me], hash [632925108]

      message [null], receiver hash: [1085786565]


      What I don't get is why the receiver hash codes differ and the event is NOT propagated to the injected Receiver bean in the Example JUnit.  Rather the event is sent to some OTHER receiver bean.


      Has this something to do with scope (which should be the default @Dependent)?


      Tested with weld-se and a JUnit wrapper WeldJUnit4Runner and got same results.  Not an Arquillian issue.