title: Unit testing play controller actions that have json parsers
body: <p>I have a controller action that I would like to test however I am getting the error below. I feel like there is something small that I could be missing but can't quite figure out what it is.I wrote out some small code to help illustrate the problem. </p>
  
  <p>Abit of more context, I would like to be able to supply mock dependencies to the controller thats why I am manaully taking over its instantiation.</p>
  
  <pre><code>java.lang.UnsupportedOperationException: NoMaterializer does not provide an ExecutionContext
  [info]   at play.api.test.NoMaterializer$.executionContext(Helpers.scala:661)
  [info]   at play.api.mvc.PlayBodyParsers.$anonfun$enforceMaxLength$1(BodyParsers.scala:866)
  [info]   at akka.stream.impl.Compose.apply(TraversalBuilder.scala:164)
  [info]   at akka.stream.impl.PhasedFusingActorMaterializer.materialize(PhasedFusingActorMaterializer.scala:488)
  [info]   at akka.stream.impl.PhasedFusingActorMaterializer.materialize(PhasedFusingActorMaterializer.scala:424)
  [info]   at akka.stream.impl.PhasedFusingActorMaterializer.materialize(PhasedFusingActorMaterializer.scala:415)
  [info]   at akka.stream.scaladsl.RunnableGraph.run(Flow.scala:496)
  </code></pre>
  
  <p>Below is the controller I wrote to help illustrate the problem</p>
  
  <pre><code>case class Location(lat: Double, long: Double)
  
  object Location {
  
    implicit val locationReads: Reads[Location] = (
      (JsPath \ "lat").read[Double](min(-90.0) keepAnd max(90.0)) and
        (JsPath \ "long").read[Double](min(-180.0) keepAnd max(180.0))
      ) (Location.apply _)
  }
  
  class HomeController @Inject()(
      cc: ControllerComponents,
      mat: Materializer
  )(implicit val ec: ExecutionContext) extends AbstractController(cc) {
  
  
    def savePlace: Action[JsValue] = Action(parse.json) { request: Request[JsValue] =&gt;
      val placeResult = request.body.validate[Location]
      placeResult.fold(
        errors =&gt; {
          BadRequest(Json.obj("status" -&gt; "KO", "message" -&gt; JsError.toJson(errors)))
        },
        place =&gt; {
          Ok(Json.obj("status" -&gt; "OK", "message" -&gt; "Location saved"))
        }
      )
    }
  }
  </code></pre>
  
  <p>and the test code    </p>
  
  <pre><code>class HomeControllerSpec extends PlaySpec with Injecting with Inside with GuiceOneAppPerSuite with BeforeAndAfterEach with Results with BeforeAndAfterAll {
    implicit lazy override val app: play.api.Application = new GuiceApplicationBuilder().configure().build()
    implicit lazy val materializer: Materializer = app.materializer
    implicit lazy val components = Helpers.stubControllerComponents()
  
    "savePlace" must {
  
      val api = new HomeController(components, mat = materializer)
  
      val payload = Json.obj(
        "location" -&gt; Json.obj("lat" -&gt; 51.235685, "lng" -&gt; -1.309197)
      )
  
      "just demo" in {
        val request = FakeRequest(POST, "/location").withJsonBody(payload)
  
        val result = call(api.savePlace, request)
        status(result) mustBe UNAUTHORIZED
      }
    }
  }
  </code></pre>
  
  <p>I am using play 2.6.3</p>