'Unit test always returns scala match error null or null pointer exception

Currently trying to test authentication controller using specs2 and scalatest, my application runs fine, but the test always return NullPointerException or Scala Match error null

  val userRepository: UserRepository = mock[UserRepository]
  val userService: UserService = mock[UserService]
  val authenticator: Authenticator = mock[Authenticator]
  val authenticationService: AuthenticationService = mock[AuthenticationService]
  implicit val ec = mock[ExecutionContext]
  implicit val materializer = mock[Materializer]
  val authenticationController = new AuthenticationController(Helpers.stubControllerComponents(
    playBodyParsers = Helpers.stubPlayBodyParsers(materializer)
  ), authenticationService, authenticator, userService)

    "User" should "login successfully" in {
      val request = FakeRequest(POST, "/api/login").withHeaders(CONTENT_TYPE -> "application/json")
        .withBody[JsValue](Json.parse("""{"email": "[email protected]", "password": "a12306789H@"}"""))
      val result: Future[Result] = authenticationController.login().apply(request)
      result.map {data => data.header.status shouldBe OK}
    }
}

When using Intellij debugger, the exception seems to be here, but I dont really understand how to fix it

  def login: Action[JsValue] = Action(parse.json) {
    implicit request =>
      UserLoginForm.form.bindFromRequest.fold(
        formWithErrors => badRequestWarning(formWithErrors.errors),
        user => {
-->       authenticationService.verify(user) match {
            case Success(result) => success(UserPayload.encode(result))
            case Failure(exception) => exception match {
              case _: PasswordNotMatch => error(Unauthorized, 401, "Password not match")
              case _: EntityNotFoundException =>  error(Unauthorized, 400, "Email not found")
              case _ => error(InternalServerError, 500, "An error occurred")
            }
          }
        }
      )
  }


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source