When testing Actors one should rather test the behaviours (the messages
sent to and from an Actor) instead of mocking.

Please note that since mockito (great tool) holds values in thread locals
and may not work as you'd expect it to with multithreaded code. Unless that
has changed I'd recommend against mixing mockito with Actor tests.

On Wed, May 27, 2015 at 11:48 PM, Harit Himanshu <
harit.subscripti...@gmail.com> wrote:

> I need to run a static method on a Java class (provided as a jar
> dependency).
> I also wanted to be able to write test on that. I created a wrapper class
> in Scala that will call this method. It looks like
>
> object CurrentLogProcessor {
> }
>
> class CurrentLogProcessor {
>   def run: Unit = LogReaderDisruptor.main(Array())
> }
>
>
> case object LogProcessRequest
>
> object LProcessor {
>   def props(currentLogProcessor: CurrentLogProcessor) = Props(new
> LProcessor(currentLogProcessor))
> }
>
> class LProcessor(currentLogProcessor: CurrentLogProcessor) extends Actor {
>   val log = Logging(context.system, this)
>
>   def receive = {
>     case LogProcessRequest => log.debug("starting log processing")
>       currentLogProcessor run
>   }
> }
>
> and in my App I call this actor as
>
>   val logProcessor = system.actorOf(LProcessor.props(new
> CurrentLogProcessor), "logProcessor")
>   logProcessor ! LogProcessRequest
>
>
> This compiles and works fine. Also, I am planning to
> mock(CurrentLogProcessor) so that I may be able to test it.
>
> Does this approach looks good? I am new to akka so wanted to make sure I
> am not making mistakes here
>
> Thank you
>
> --
> >>>>>>>>>> Read the docs: http://akka.io/docs/
> >>>>>>>>>> Check the FAQ:
> http://doc.akka.io/docs/akka/current/additional/faq.html
> >>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
> ---
> You received this message because you are subscribed to the Google Groups
> "Akka User List" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to akka-user+unsubscr...@googlegroups.com.
> To post to this group, send email to akka-user@googlegroups.com.
> Visit this group at http://groups.google.com/group/akka-user.
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Cheers,
Konrad 'ktoso' Malawski
Akka <http://akka.io/> @ Typesafe <http://typesafe.com/>

-- 
>>>>>>>>>>      Read the docs: http://akka.io/docs/
>>>>>>>>>>      Check the FAQ: 
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>>      Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups "Akka 
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to akka-user+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to