I recently refactored this multi-project project into just one and I'm trying to fix up the tests. This isn't exactly relevant to this repo since the code is slightly different, but I was wondering if anyone could give me a hand. One interesting test is the following:
"send a password recovery email if a user with the given email was found" in new Context {
new WithApplication(application) {
authTokenService.create(user.id, 5 minutes) returns Future.successful(authToken)
userService.retrieve(loginInfo) returns Future.successful(Some(user))
val request = FakeRequest().withJsonBody(Json.obj("email" -> email)).withCSRFToken
Response(
OK,
controller.recover(request),
"auth.password.recover.successful",
Messages("auth.reset.email.sent", email)
)
there was one(mailerClient).send(any[Email])
}
}
The context has a mocked AuthTokenService:
val authTokenService = mock[AuthTokenService].smart
But for some reason I am getting Mockito SmartNullPointerExceptions. I'm pretty perplexed - the spec does fine smart mocking other services but it has a lot of trouble with the create method:
org.mockito.exceptions.verification.SmartNullPointerException:
You have a NullPointerException here:
-> at controllers.PasswordController.$anonfun$recover$4(PasswordController.scala:70)
because this method call was *not* stubbed correctly:
-> at controllers.PasswordController.$anonfun$recover$4(PasswordController.scala:70)
authTokenService.create(
BSONObjectID("5ad93db11000001000c6cd7b"),
2 hours
);
org.mockito.exceptions.verification.SmartNullPointerException:
You have a NullPointerException here:
-> at controllers.PasswordController.$anonfun$recover$4(PasswordController.scala:70)
because this method call was *not* stubbed correctly:
-> at controllers.PasswordController.$anonfun$recover$4(PasswordController.scala:70)
authTokenService.create(
BSONObjectID("5ad93db11000001000c6cd7b"),
2 hours
);
at controllers.PasswordController.$anonfun$recover$4(PasswordController.scala:70)
at scala.concurrent.Future.$anonfun$flatMap$1(Future.scala:304)
at scala.concurrent.impl.Promise.$anonfun$transformWith$1(Promise.scala:37)
at scala.concurrent.impl.CallbackRunnable.run$$$capture(Promise.scala:60)
at scala.concurrent.impl.CallbackRunnable.run(Promise.scala)
at akka.dispatch.BatchingExecutor$AbstractBatch.processBatch(BatchingExecutor.scala:55)
at akka.dispatch.BatchingExecutor$BlockableBatch.$anonfun$run$1(BatchingExecutor.scala:91)
at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
at scala.concurrent.BlockContext$.withBlockContext(BlockContext.scala:81)
at akka.dispatch.BatchingExecutor$BlockableBatch.run(BatchingExecutor.scala:91)
at akka.dispatch.TaskInvocation.run(AbstractDispatcher.scala:40)
at akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(ForkJoinExecutorConfigurator.scala:43)
at akka.dispatch.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
at akka.dispatch.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)
at akka.dispatch.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
at akka.dispatch.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)
While the project is multi-project, there is no issue. Any ideas? :(
Hi,
I recently refactored this multi-project project into just one and I'm trying to fix up the tests. This isn't exactly relevant to this repo since the code is slightly different, but I was wondering if anyone could give me a hand. One interesting test is the following:
The context has a mocked
AuthTokenService
:and it is also bound correctly:
But for some reason I am getting Mockito SmartNullPointerExceptions. I'm pretty perplexed - the spec does fine smart mocking other services but it has a lot of trouble with the
create
method:While the project is multi-project, there is no issue. Any ideas? :(
Thanks