5
votes

My controller method:

def postCategory = Action(parse.tolerantText) { request =>
    Ok("")
  }

and this is my test:

val result = categoryController.postCategory.apply(FakeRequest())
      status(result) mustEqual OK //error this line

I have this error:

Error:(63, 14) type mismatch; found : play.api.libs.streams.Accumulator[akka.util.ByteString,play.api.mvc.Result] required: scala.concurrent.Future[play.api.mvc.Result] status(result) mustEqual OK ^

It seem that using a custom parser parse.* makes it returns Accumulator rather than Future[Result]

I'm using play 2.5-RC2

2
You're right about Accumulator. Check this out playframework.com/documentation/2.5.x/…mfirry

2 Answers

4
votes

You do should use result.run getting instance of Materializer with Guice

would look like:

import akka.stream.Materializer
//...

def mockApp = new GuiceApplicationBuilder().build()
val mtrlzr = mockApp.injector.instanceOf[Materializer]

val result: Accumulator[ByteString, Result] = controller.accessToken()(FakeRequest())
val runResult: Future[Result] = result.run()(mtrlzr)    
2
votes

You can try with something like this:

  val result = categoryController.postCategory.apply(FakeRequest())
  status(result.run) must equalTo(OK)

It basically looks like Accumulator has a nice run() method that returns a Future.