For doing unit tests, I am trying to mock a method which is defined in an actor class.
This is something I am trying to do
Actor actor = mock(Actor.class)
when(actor.methodInActor(any())).thenReturn(0);
System.out.println(actor.methodInActor());
// This prints 1 and hence it works
However, this is pretty much useless to me. What I am more interested about is,
TestActorRef ref = TestActorRef.create(testSystem,props, “testA”);
Actor actor = ref.underlyingActor()
when(actor.methodInActor(any())).thenReturn(0);
// This throws a Nullpointer exception
Actor actor = mock(ref.underlyingActor()) // This also throws an error
The reason why I was trying to do something like this is because my unit test tries to execute the actor with ref.tell(msg, testActor()) and I need to mock the method from an instance of the Actor Class
Any help will be appreciated