unable to write a test spec for a controller's methodWhat’s the difference between ScalaTest and Scala Specs unit test frameworks?How to mock void methods with MockitoMaking a mocked method return an argument that was passed to itCan Mockito capture arguments of a method called multiple times?Mockito: Trying to spy on method is calling the original methodHow to verify that a specific method was not called using Mockito?Use Mockito to mock some methods but not othersMockito test a void method throws an exceptionMocking static methods with MockitoFakeRequest seem to be Null when passed to a controller in unit test

Slitherlink Fillomino hybrid

Is it possible to perform a regression where you have an unknown / unknowable feature variable?

Confirming resignation after resignation letter ripped up

Is there any method of inflicting the incapacitated condition and no other condition?

How to prevent clipped screen edges on my TV, HDMI-connected?

Why in most German places is the church the tallest building?

Is immersion of utensils (tevila) valid before koshering (hagala)?

Was there ever a treaty between 2 entities with significantly different translations to the detriment of one party?

Justifying the use of directed energy weapons

Does travel insurance for short flight delays exist?

Do they have Supervillain(s)?

Is gzip atomic?

How to find multiple values on the same line in any permutation using Notepad++?

Identify a problem where a potentially winning move draws because of the 50 move rule

Why did MS-DOS applications built using Turbo Pascal fail to start with a division by zero error on faster systems?

Algorithms vs LP or MIP

Did a flight controller ever answer Flight with a no-go?

How to find out the average duration of the peer-review process for a given journal?

Sitecore PowerShell script to get all images where the File Path is empty

State-of-the-art algorithms for solving linear programming problems

Does norwegian.no airline overbook flights?

What is this symbol: semicircles facing each other?

Different kernel versions across different machines

Why does The Ancient One think differently about Doctor Strange in Endgame than the film Doctor Strange?



unable to write a test spec for a controller's method


What’s the difference between ScalaTest and Scala Specs unit test frameworks?How to mock void methods with MockitoMaking a mocked method return an argument that was passed to itCan Mockito capture arguments of a method called multiple times?Mockito: Trying to spy on method is calling the original methodHow to verify that a specific method was not called using Mockito?Use Mockito to mock some methods but not othersMockito test a void method throws an exceptionMocking static methods with MockitoFakeRequest seem to be Null when passed to a controller in unit test






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I am unit testing this method of my controller class. The method executes few asynchronous database queries and depending on the result, Redirects the request. The success of previous database query determines if the next query needs to be done or not.



def verifyUser(token:String) = Action.async 
implicit request =>
println("verifyUser action called with token: " + token) //TODOM - add proper handling and response

val result:Future[Result] = fortokenOption:Option[UserToken] <- userTokenRepo.findOne(UserTokenKey(UUID.fromString(token))) //generator 1 - get token from database
userOption:Option[User] <- if (tokenOption.isDefined) println(s"received tokenOption $tokenOption");userRepo.findOne(tokenOption.get.userKeys) else Future.successful(None) //generator2. found token, look for corresponding user to which the token belongs
modifiedUser:Option[User] <- if (userOption.isDefined) println(s"received userOption $userOption");confirmSignupforUser(userOption.get) else Future.successful(None) //generator 3. found user and token. Update profile
deletedToken:Option[UserTokenKey] <- if(modifiedUser.isDefined) println(s"received modified $modifiedUser");userTokenRepo.delete(UserTokenKey(UUID.fromString(token))) else Future.successful(None)

yield //check if we have user and token and modified user here. If any is missing, return error else success
println("db query results tokenOption: "+tokenOption+", userOption: "+userOption+" : modifiedUserOption: "+modifiedUser+", deletedToken: "+deletedToken)
if(tokenOption.isDefined && userOption.isDefined && modifiedUser.isDefined && deletedToken.isDefined)
Redirect("http://localhost:9000/home"+";signup=success")//TODOM - pick from config
else
if(tokenOption.isEmpty)
Redirect("http://localhost:9000/home"+";signup=error")//TODOM - pick from config
else if(userOption.isEmpty)
Redirect("http://localhost:9000/home"+";signup=error")//TODOM - pick from config
else if(modifiedUser.isEmpty)
Redirect("http://localhost:9000/home"+";signup=error")//TODOM - pick from config
else //this shouldn't happen. Unexpected
Redirect("http://localhost:9000/home"+";signup=error")//TODOM - pick from config

result.recover case x =>
println("Future failed in validateUserSession. Recovering. Returning Internal Server Error" + x)


result //returning Future[Result]




The controller also has a method confirmSignupforUser which is called by verifyUser method in the for loop



To test the code, I have written the following spec



"verify token method" should 
"work " in
val testEnv = new TestEnv(components.configuration)
when(testEnv.mockUserTokenRepository.findOne(ArgumentMatchers.any[UserTokenKey])).thenReturn(
Future
println(s"returning mocked token $testEnv.userToken")
Some(testEnv.userToken)
)

when(testEnv.mockUserRepository.findOne(ArgumentMatchers.any[UserKeys])).thenReturn(Future
println(s"returning mocked user $testEnv.user")
Some(testEnv.user)
)

when(testEnv.controller.confirmSignupforUser(ArgumentMatchers.any[User])).thenReturn(
Future
println(s"confirming mocked user $testEnv.user")
Some(testEnv.user)

)

when(testEnv.mockUserTokenRepository.delete(ArgumentMatchers.any[UserTokenKey])).thenReturn(
Future
println(s"returning mocked token key $testEnv.userTokenKey")
Some(testEnv.userTokenKey)

)


val request = FakeRequest("POST", s"ws/users/signup/$testEnv.mockHelperMethods.getUniqueID()")
println("sending request", request)

val resultFuture:Future[Result] = testEnv.controller.verifyUser(testEnv.mockHelperMethods.getUniqueID().toString()).apply(request)
val responseBody = contentAsString(resultFuture)
println(s"received response $responseBody")
1 mustBe 1




My test is throwing a null pointer exception.



created TestEnv with configuration...

confirming user: null
returning mocked user User(11111111-1111-1111-1111-111111111111,UserProfile(Some(InternalUserProfile(LoginInfo(credentials,test@test.com),1,true,Some(PasswordInfo(someHasher,somePassword,Some(someSalt))))),ExternalUserProfile(test@test.com,ln,fn,Some(somePassword))))
returning mocked token UserToken(11111111-1111-1111-1111-111111111111,11111111-1111-1111-1111-111111111111,UserKeys(1,test@test.com,LoginInfo(credentials,test@test.com),fn,ln),2019-03-27T17:08:43.861Z,true)

java.lang.NullPointerException was thrown.
java.lang.NullPointerException
at controllers.UserController.confirmSignupforUser(UserController.scala:442)


The piece of code which seem to cause the issue is



def confirmSignupforUser(user:User):Future[Option[User]] = 
println("confirming user: "+user)
...



The above code is being called from my spec it seems
when(testEnv.controller.confirmSignupforUser(ArgumentMatchers.any[User])).thenReturn(
Future
println(s"confirming mocked user $testEnv.user")
Some(testEnv.user)

)



I have few doubts.
question 1) I am not mocking testEnv.controller. Can I still use when in one of the methods of testEnv.controller (testEnv.controller.confirmSignupforUser(ArgumentMatchers.any[User]))?



Question 2) Am I correct that in the for loop, userTokenRepo.findOne should return mocked value Some(testEnv.userToken). This should be then be used userRepo.findOne(tokenOption.get.userKeys) which should return mocked value Some(testEnv.user). This should be used in confirmSignupforUser(userOption.get)?
Question 3) Why is confirmSignupforUser getting a null value?










share|improve this question






























    0















    I am unit testing this method of my controller class. The method executes few asynchronous database queries and depending on the result, Redirects the request. The success of previous database query determines if the next query needs to be done or not.



    def verifyUser(token:String) = Action.async 
    implicit request =>
    println("verifyUser action called with token: " + token) //TODOM - add proper handling and response

    val result:Future[Result] = fortokenOption:Option[UserToken] <- userTokenRepo.findOne(UserTokenKey(UUID.fromString(token))) //generator 1 - get token from database
    userOption:Option[User] <- if (tokenOption.isDefined) println(s"received tokenOption $tokenOption");userRepo.findOne(tokenOption.get.userKeys) else Future.successful(None) //generator2. found token, look for corresponding user to which the token belongs
    modifiedUser:Option[User] <- if (userOption.isDefined) println(s"received userOption $userOption");confirmSignupforUser(userOption.get) else Future.successful(None) //generator 3. found user and token. Update profile
    deletedToken:Option[UserTokenKey] <- if(modifiedUser.isDefined) println(s"received modified $modifiedUser");userTokenRepo.delete(UserTokenKey(UUID.fromString(token))) else Future.successful(None)

    yield //check if we have user and token and modified user here. If any is missing, return error else success
    println("db query results tokenOption: "+tokenOption+", userOption: "+userOption+" : modifiedUserOption: "+modifiedUser+", deletedToken: "+deletedToken)
    if(tokenOption.isDefined && userOption.isDefined && modifiedUser.isDefined && deletedToken.isDefined)
    Redirect("http://localhost:9000/home"+";signup=success")//TODOM - pick from config
    else
    if(tokenOption.isEmpty)
    Redirect("http://localhost:9000/home"+";signup=error")//TODOM - pick from config
    else if(userOption.isEmpty)
    Redirect("http://localhost:9000/home"+";signup=error")//TODOM - pick from config
    else if(modifiedUser.isEmpty)
    Redirect("http://localhost:9000/home"+";signup=error")//TODOM - pick from config
    else //this shouldn't happen. Unexpected
    Redirect("http://localhost:9000/home"+";signup=error")//TODOM - pick from config

    result.recover case x =>
    println("Future failed in validateUserSession. Recovering. Returning Internal Server Error" + x)


    result //returning Future[Result]




    The controller also has a method confirmSignupforUser which is called by verifyUser method in the for loop



    To test the code, I have written the following spec



    "verify token method" should 
    "work " in
    val testEnv = new TestEnv(components.configuration)
    when(testEnv.mockUserTokenRepository.findOne(ArgumentMatchers.any[UserTokenKey])).thenReturn(
    Future
    println(s"returning mocked token $testEnv.userToken")
    Some(testEnv.userToken)
    )

    when(testEnv.mockUserRepository.findOne(ArgumentMatchers.any[UserKeys])).thenReturn(Future
    println(s"returning mocked user $testEnv.user")
    Some(testEnv.user)
    )

    when(testEnv.controller.confirmSignupforUser(ArgumentMatchers.any[User])).thenReturn(
    Future
    println(s"confirming mocked user $testEnv.user")
    Some(testEnv.user)

    )

    when(testEnv.mockUserTokenRepository.delete(ArgumentMatchers.any[UserTokenKey])).thenReturn(
    Future
    println(s"returning mocked token key $testEnv.userTokenKey")
    Some(testEnv.userTokenKey)

    )


    val request = FakeRequest("POST", s"ws/users/signup/$testEnv.mockHelperMethods.getUniqueID()")
    println("sending request", request)

    val resultFuture:Future[Result] = testEnv.controller.verifyUser(testEnv.mockHelperMethods.getUniqueID().toString()).apply(request)
    val responseBody = contentAsString(resultFuture)
    println(s"received response $responseBody")
    1 mustBe 1




    My test is throwing a null pointer exception.



    created TestEnv with configuration...

    confirming user: null
    returning mocked user User(11111111-1111-1111-1111-111111111111,UserProfile(Some(InternalUserProfile(LoginInfo(credentials,test@test.com),1,true,Some(PasswordInfo(someHasher,somePassword,Some(someSalt))))),ExternalUserProfile(test@test.com,ln,fn,Some(somePassword))))
    returning mocked token UserToken(11111111-1111-1111-1111-111111111111,11111111-1111-1111-1111-111111111111,UserKeys(1,test@test.com,LoginInfo(credentials,test@test.com),fn,ln),2019-03-27T17:08:43.861Z,true)

    java.lang.NullPointerException was thrown.
    java.lang.NullPointerException
    at controllers.UserController.confirmSignupforUser(UserController.scala:442)


    The piece of code which seem to cause the issue is



    def confirmSignupforUser(user:User):Future[Option[User]] = 
    println("confirming user: "+user)
    ...



    The above code is being called from my spec it seems
    when(testEnv.controller.confirmSignupforUser(ArgumentMatchers.any[User])).thenReturn(
    Future
    println(s"confirming mocked user $testEnv.user")
    Some(testEnv.user)

    )



    I have few doubts.
    question 1) I am not mocking testEnv.controller. Can I still use when in one of the methods of testEnv.controller (testEnv.controller.confirmSignupforUser(ArgumentMatchers.any[User]))?



    Question 2) Am I correct that in the for loop, userTokenRepo.findOne should return mocked value Some(testEnv.userToken). This should be then be used userRepo.findOne(tokenOption.get.userKeys) which should return mocked value Some(testEnv.user). This should be used in confirmSignupforUser(userOption.get)?
    Question 3) Why is confirmSignupforUser getting a null value?










    share|improve this question


























      0












      0








      0








      I am unit testing this method of my controller class. The method executes few asynchronous database queries and depending on the result, Redirects the request. The success of previous database query determines if the next query needs to be done or not.



      def verifyUser(token:String) = Action.async 
      implicit request =>
      println("verifyUser action called with token: " + token) //TODOM - add proper handling and response

      val result:Future[Result] = fortokenOption:Option[UserToken] <- userTokenRepo.findOne(UserTokenKey(UUID.fromString(token))) //generator 1 - get token from database
      userOption:Option[User] <- if (tokenOption.isDefined) println(s"received tokenOption $tokenOption");userRepo.findOne(tokenOption.get.userKeys) else Future.successful(None) //generator2. found token, look for corresponding user to which the token belongs
      modifiedUser:Option[User] <- if (userOption.isDefined) println(s"received userOption $userOption");confirmSignupforUser(userOption.get) else Future.successful(None) //generator 3. found user and token. Update profile
      deletedToken:Option[UserTokenKey] <- if(modifiedUser.isDefined) println(s"received modified $modifiedUser");userTokenRepo.delete(UserTokenKey(UUID.fromString(token))) else Future.successful(None)

      yield //check if we have user and token and modified user here. If any is missing, return error else success
      println("db query results tokenOption: "+tokenOption+", userOption: "+userOption+" : modifiedUserOption: "+modifiedUser+", deletedToken: "+deletedToken)
      if(tokenOption.isDefined && userOption.isDefined && modifiedUser.isDefined && deletedToken.isDefined)
      Redirect("http://localhost:9000/home"+";signup=success")//TODOM - pick from config
      else
      if(tokenOption.isEmpty)
      Redirect("http://localhost:9000/home"+";signup=error")//TODOM - pick from config
      else if(userOption.isEmpty)
      Redirect("http://localhost:9000/home"+";signup=error")//TODOM - pick from config
      else if(modifiedUser.isEmpty)
      Redirect("http://localhost:9000/home"+";signup=error")//TODOM - pick from config
      else //this shouldn't happen. Unexpected
      Redirect("http://localhost:9000/home"+";signup=error")//TODOM - pick from config

      result.recover case x =>
      println("Future failed in validateUserSession. Recovering. Returning Internal Server Error" + x)


      result //returning Future[Result]




      The controller also has a method confirmSignupforUser which is called by verifyUser method in the for loop



      To test the code, I have written the following spec



      "verify token method" should 
      "work " in
      val testEnv = new TestEnv(components.configuration)
      when(testEnv.mockUserTokenRepository.findOne(ArgumentMatchers.any[UserTokenKey])).thenReturn(
      Future
      println(s"returning mocked token $testEnv.userToken")
      Some(testEnv.userToken)
      )

      when(testEnv.mockUserRepository.findOne(ArgumentMatchers.any[UserKeys])).thenReturn(Future
      println(s"returning mocked user $testEnv.user")
      Some(testEnv.user)
      )

      when(testEnv.controller.confirmSignupforUser(ArgumentMatchers.any[User])).thenReturn(
      Future
      println(s"confirming mocked user $testEnv.user")
      Some(testEnv.user)

      )

      when(testEnv.mockUserTokenRepository.delete(ArgumentMatchers.any[UserTokenKey])).thenReturn(
      Future
      println(s"returning mocked token key $testEnv.userTokenKey")
      Some(testEnv.userTokenKey)

      )


      val request = FakeRequest("POST", s"ws/users/signup/$testEnv.mockHelperMethods.getUniqueID()")
      println("sending request", request)

      val resultFuture:Future[Result] = testEnv.controller.verifyUser(testEnv.mockHelperMethods.getUniqueID().toString()).apply(request)
      val responseBody = contentAsString(resultFuture)
      println(s"received response $responseBody")
      1 mustBe 1




      My test is throwing a null pointer exception.



      created TestEnv with configuration...

      confirming user: null
      returning mocked user User(11111111-1111-1111-1111-111111111111,UserProfile(Some(InternalUserProfile(LoginInfo(credentials,test@test.com),1,true,Some(PasswordInfo(someHasher,somePassword,Some(someSalt))))),ExternalUserProfile(test@test.com,ln,fn,Some(somePassword))))
      returning mocked token UserToken(11111111-1111-1111-1111-111111111111,11111111-1111-1111-1111-111111111111,UserKeys(1,test@test.com,LoginInfo(credentials,test@test.com),fn,ln),2019-03-27T17:08:43.861Z,true)

      java.lang.NullPointerException was thrown.
      java.lang.NullPointerException
      at controllers.UserController.confirmSignupforUser(UserController.scala:442)


      The piece of code which seem to cause the issue is



      def confirmSignupforUser(user:User):Future[Option[User]] = 
      println("confirming user: "+user)
      ...



      The above code is being called from my spec it seems
      when(testEnv.controller.confirmSignupforUser(ArgumentMatchers.any[User])).thenReturn(
      Future
      println(s"confirming mocked user $testEnv.user")
      Some(testEnv.user)

      )



      I have few doubts.
      question 1) I am not mocking testEnv.controller. Can I still use when in one of the methods of testEnv.controller (testEnv.controller.confirmSignupforUser(ArgumentMatchers.any[User]))?



      Question 2) Am I correct that in the for loop, userTokenRepo.findOne should return mocked value Some(testEnv.userToken). This should be then be used userRepo.findOne(tokenOption.get.userKeys) which should return mocked value Some(testEnv.user). This should be used in confirmSignupforUser(userOption.get)?
      Question 3) Why is confirmSignupforUser getting a null value?










      share|improve this question














      I am unit testing this method of my controller class. The method executes few asynchronous database queries and depending on the result, Redirects the request. The success of previous database query determines if the next query needs to be done or not.



      def verifyUser(token:String) = Action.async 
      implicit request =>
      println("verifyUser action called with token: " + token) //TODOM - add proper handling and response

      val result:Future[Result] = fortokenOption:Option[UserToken] <- userTokenRepo.findOne(UserTokenKey(UUID.fromString(token))) //generator 1 - get token from database
      userOption:Option[User] <- if (tokenOption.isDefined) println(s"received tokenOption $tokenOption");userRepo.findOne(tokenOption.get.userKeys) else Future.successful(None) //generator2. found token, look for corresponding user to which the token belongs
      modifiedUser:Option[User] <- if (userOption.isDefined) println(s"received userOption $userOption");confirmSignupforUser(userOption.get) else Future.successful(None) //generator 3. found user and token. Update profile
      deletedToken:Option[UserTokenKey] <- if(modifiedUser.isDefined) println(s"received modified $modifiedUser");userTokenRepo.delete(UserTokenKey(UUID.fromString(token))) else Future.successful(None)

      yield //check if we have user and token and modified user here. If any is missing, return error else success
      println("db query results tokenOption: "+tokenOption+", userOption: "+userOption+" : modifiedUserOption: "+modifiedUser+", deletedToken: "+deletedToken)
      if(tokenOption.isDefined && userOption.isDefined && modifiedUser.isDefined && deletedToken.isDefined)
      Redirect("http://localhost:9000/home"+";signup=success")//TODOM - pick from config
      else
      if(tokenOption.isEmpty)
      Redirect("http://localhost:9000/home"+";signup=error")//TODOM - pick from config
      else if(userOption.isEmpty)
      Redirect("http://localhost:9000/home"+";signup=error")//TODOM - pick from config
      else if(modifiedUser.isEmpty)
      Redirect("http://localhost:9000/home"+";signup=error")//TODOM - pick from config
      else //this shouldn't happen. Unexpected
      Redirect("http://localhost:9000/home"+";signup=error")//TODOM - pick from config

      result.recover case x =>
      println("Future failed in validateUserSession. Recovering. Returning Internal Server Error" + x)


      result //returning Future[Result]




      The controller also has a method confirmSignupforUser which is called by verifyUser method in the for loop



      To test the code, I have written the following spec



      "verify token method" should 
      "work " in
      val testEnv = new TestEnv(components.configuration)
      when(testEnv.mockUserTokenRepository.findOne(ArgumentMatchers.any[UserTokenKey])).thenReturn(
      Future
      println(s"returning mocked token $testEnv.userToken")
      Some(testEnv.userToken)
      )

      when(testEnv.mockUserRepository.findOne(ArgumentMatchers.any[UserKeys])).thenReturn(Future
      println(s"returning mocked user $testEnv.user")
      Some(testEnv.user)
      )

      when(testEnv.controller.confirmSignupforUser(ArgumentMatchers.any[User])).thenReturn(
      Future
      println(s"confirming mocked user $testEnv.user")
      Some(testEnv.user)

      )

      when(testEnv.mockUserTokenRepository.delete(ArgumentMatchers.any[UserTokenKey])).thenReturn(
      Future
      println(s"returning mocked token key $testEnv.userTokenKey")
      Some(testEnv.userTokenKey)

      )


      val request = FakeRequest("POST", s"ws/users/signup/$testEnv.mockHelperMethods.getUniqueID()")
      println("sending request", request)

      val resultFuture:Future[Result] = testEnv.controller.verifyUser(testEnv.mockHelperMethods.getUniqueID().toString()).apply(request)
      val responseBody = contentAsString(resultFuture)
      println(s"received response $responseBody")
      1 mustBe 1




      My test is throwing a null pointer exception.



      created TestEnv with configuration...

      confirming user: null
      returning mocked user User(11111111-1111-1111-1111-111111111111,UserProfile(Some(InternalUserProfile(LoginInfo(credentials,test@test.com),1,true,Some(PasswordInfo(someHasher,somePassword,Some(someSalt))))),ExternalUserProfile(test@test.com,ln,fn,Some(somePassword))))
      returning mocked token UserToken(11111111-1111-1111-1111-111111111111,11111111-1111-1111-1111-111111111111,UserKeys(1,test@test.com,LoginInfo(credentials,test@test.com),fn,ln),2019-03-27T17:08:43.861Z,true)

      java.lang.NullPointerException was thrown.
      java.lang.NullPointerException
      at controllers.UserController.confirmSignupforUser(UserController.scala:442)


      The piece of code which seem to cause the issue is



      def confirmSignupforUser(user:User):Future[Option[User]] = 
      println("confirming user: "+user)
      ...



      The above code is being called from my spec it seems
      when(testEnv.controller.confirmSignupforUser(ArgumentMatchers.any[User])).thenReturn(
      Future
      println(s"confirming mocked user $testEnv.user")
      Some(testEnv.user)

      )



      I have few doubts.
      question 1) I am not mocking testEnv.controller. Can I still use when in one of the methods of testEnv.controller (testEnv.controller.confirmSignupforUser(ArgumentMatchers.any[User]))?



      Question 2) Am I correct that in the for loop, userTokenRepo.findOne should return mocked value Some(testEnv.userToken). This should be then be used userRepo.findOne(tokenOption.get.userKeys) which should return mocked value Some(testEnv.user). This should be used in confirmSignupforUser(userOption.get)?
      Question 3) Why is confirmSignupforUser getting a null value?







      mockito scalatest playframework-2.6






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 27 at 17:23









      Manu ChadhaManu Chadha

      4,3866 gold badges23 silver badges61 bronze badges




      4,3866 gold badges23 silver badges61 bronze badges

























          1 Answer
          1






          active

          oldest

          votes


















          0















          my bad. I realise that I cannot use when and pass controller's method as I am not mocking the controller. I deleted the below line as thhe test has moved forward



          //don't need this
          when(testEnv.controller.confirmSignupforUser(ArgumentMatchers.any[User])).thenReturn(
          Future
          println(s"confirming mocked user $testEnv.user")
          Some(testEnv.user)

          )





          share|improve this answer
























            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55383164%2funable-to-write-a-test-spec-for-a-controllers-method%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0















            my bad. I realise that I cannot use when and pass controller's method as I am not mocking the controller. I deleted the below line as thhe test has moved forward



            //don't need this
            when(testEnv.controller.confirmSignupforUser(ArgumentMatchers.any[User])).thenReturn(
            Future
            println(s"confirming mocked user $testEnv.user")
            Some(testEnv.user)

            )





            share|improve this answer





























              0















              my bad. I realise that I cannot use when and pass controller's method as I am not mocking the controller. I deleted the below line as thhe test has moved forward



              //don't need this
              when(testEnv.controller.confirmSignupforUser(ArgumentMatchers.any[User])).thenReturn(
              Future
              println(s"confirming mocked user $testEnv.user")
              Some(testEnv.user)

              )





              share|improve this answer



























                0














                0










                0









                my bad. I realise that I cannot use when and pass controller's method as I am not mocking the controller. I deleted the below line as thhe test has moved forward



                //don't need this
                when(testEnv.controller.confirmSignupforUser(ArgumentMatchers.any[User])).thenReturn(
                Future
                println(s"confirming mocked user $testEnv.user")
                Some(testEnv.user)

                )





                share|improve this answer













                my bad. I realise that I cannot use when and pass controller's method as I am not mocking the controller. I deleted the below line as thhe test has moved forward



                //don't need this
                when(testEnv.controller.confirmSignupforUser(ArgumentMatchers.any[User])).thenReturn(
                Future
                println(s"confirming mocked user $testEnv.user")
                Some(testEnv.user)

                )






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 27 at 17:26









                Manu ChadhaManu Chadha

                4,3866 gold badges23 silver badges61 bronze badges




                4,3866 gold badges23 silver badges61 bronze badges



















                    Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







                    Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55383164%2funable-to-write-a-test-spec-for-a-controllers-method%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                    용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

                    155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해