title: How to Unit test a controller in Play/Scala
body: <p>I'm having trouble when trying to test a controller that sends a POST request to the API. I've tried different ways of testing it but I keep on getting the same "400" response. I believe the format of the json val is correct because I've tested it using Swagger and it works fine. Can anybody help me to understand what I'm missing here. Many thanks. </p>
  
  <pre><code>val json: JsValue = Json.parse("""[{"id":"1","address":"my address"}]""")
  val mockAddressFinder = mock(classOf[AddressFinder])
  
  "Example test" should {
    "should be valid" in {
     val controller = new Match(mockAddressFinder)
     val results = controller.match.apply(FakeRequest(
      POST,
        "test/test",
        FakeHeaders(Seq("Content-type"-&gt;("application/json"))),
      json
     ))
     results.onComplete {
      case Success(_) =&gt; results.map(s =&gt; println("hello" + s.header.status))
      case _=&gt; println("did not work")
    }
  }
  </code></pre>