unit testing - mocking generic method using Mockito and Scala -
i'm trying write test following function in finatra httpclient.
def executejson[t: manifest]( request: request, expectedstatus: status = status.ok): future[t] = {...}
according question answered on stackoverflow. mocking generic scala method in mockito. shorthand for:
def executejson[t]( request: request, expectedstatus: status = status.ok) (implicit t: manifest[t]): futuren[t] = {...}
so tried,
verify(httpclientmock, times(1)).executejson[jiraproject] (argthat(new requestmatcher(req)))(matchers.any())
unfortunately, didn't solve problem. still got following error.
invalid use of argument matchers! 0 matchers expected, 1 recorded: -> @ org.specs.mock.mockitostubs$class.argthat(mockito.scala:331) exception may occur if matchers combined raw values: //incorrect: somemethod(anyobject(), "raw string"); when using matchers, arguments have provided matchers. example: //correct: somemethod(anyobject(), eq("string matcher"));
i tried matchers.eq(manifest[jiraproject])
, complains value manifest of type scala.reflect.manifestfactory.type not take type parameters
.
i'm new scala , mockito, there did wrong or misunderstood?
thanks in advance help!
found out problem! executejson takes 3 params- request, expectedstatus, , manifest. however, because expectedstatus optional, didn't explicit pass it, that's why complained. so, final code should verify(httpclientmock, times(1)).executejson[jiraproject](argthat(new requestmatcher(req)), matchers.any[status])(matchers.any())
your problem you're using equality in first parameter , matcher second one. try using matchers arguments.
but bigger problem feel here you're trying mock 3rd party library - this should avoid. solve problem. here's read - enter link description here
Comments
Post a Comment