title: Using Mokito to mock out an Akka Actor's log object
body: <p>I've tried a couple of things which seem to compile but throw NullPointer exceptions during unit testing so I'm wondering how I could potentially overcome the limitations in unit-testing.  I have a class which looks like this:</p>
  
  <pre><code>class LogWriter extends Actor{
    def receive{
      case x:Timing =&gt; log.info(x toString)
      case x:Event =&gt; log.info(x toString)
      case x:Any =&gt; log.warning("Improper message sent to LogWriter, %s".format(x toString))
    }
  }
  </code></pre>
  
  <p>But attempting to unit test using Specs2 and the Mockito support with something along the lines of:</p>
  
  <pre><code>class LogWriterSpec extends Mokito with Specification{
    val mockedLog = mock[Logger]
  
    class MockedLogWriter extends LogWriter{
      @transient override val log = mockedLog
    }
  
    val writer = actorOf(new MockedLogWriter).start
  
    def testTiming = {
      val message = Timing("testTiming", 15 seconds)
      writer !! (message, 400)
      there was one(mockedLog).info(message toString)
    }
  
    def is = "A LogWriter" ^
      "should write a Timing message to log.info" ! testTiming ^
    end
  }
  </code></pre>
  
  <p>while compiling results in the aforementioned <code>NullPointerException</code>:</p>
  
  <pre><code>[akka:event-driven:dispatcher:global-10] ERROR akka.actor.Actor$ - Problem
  java.lang.NullPointerException
      at akka.util.Logger.warning_$qmark(Logging.scala:43)
      at akka.util.Logger.warning(Logging.scala:117)
  </code></pre>
  
  <p>I tried changing it to use some mixin trait which overrode the "log" object of the Akka <code>Logging</code> trait but the compiler didn't allow it.  The compiler reply was something along the lines of "we don't want you making an inadvertent mistake."  Ugh! I want that "mistake."</p>
  
  <p>Anyone know of another way?  I'm not stuck to Mockito and welcome any suggestions.</p>