title: Using Akka (with Java) how can I verify that my actor under test is watching another actor?
body: <p>I have the following actor for which I would like to create unit tests to verify the following behaviour:</p>
  
  <ol>
  <li><code>ListeningActor</code> correctly registers itself to watch the <code>listeningTo</code> actor.</li>
  <li><code>ListeningActor</code> correctly kills itself when the <code>listeningTo</code> actor terminates.</li>
  </ol>
  
  <p>How can I verify these two behaviours?</p>
  
  <p>I am using Akka 2.0.2 with Java.</p>
  
  <p>Thanks</p>
  
  <pre class="lang-java prettyprint-override"><code>public class ListeningActor extends UntypedActor {
      private final ActorRef listeningTo;
  
      public ListeningActor(final ActorRef listeningTo) {
          this.listeningTo = listeningTo;
      }
  
      @Override
      public void preStart() {
          super.preStart();
          context().watch(listeningTo);          // &lt;---- To verify
      }
  
      @Override
      public void onReceive(final Object o) throws Exception {
          if (o instanceof Terminated) {
              Terminated terminated = (Terminated) o;
              if (terminated.equals(listeningTo)) {
                  context().stop(self());        // &lt;---- To verify
              }
          } else {
              unhandled(o);
          }
      }
  }
  </code></pre>