POST method without body for testing

Currently using Play 2.6.13 (play-test_2.12-2.6.13)
Using the following API

final FakeRequest request =
                        new FakeRequest(POST, "<somurl>").withHeader("<myheader>", "headervalue");

final Result result = Helpers.route(fakeApplication, request);

This the above FakeRequest is a POST without body.
This seems to throw an NPE in Helpers.scala as it expects a non null body

// Java compatibility
  def jRoute[T](app: Application, r: RequestHeader, body: RequestBody): Option[Future[Result]] = {
    route(app, r, body.asBytes())

As per my understanding, POST need not have a body.

If so, is the above behaviour a bug, or I am missing something?

Hi @aditya,

Yes, I agree this looks like a bug.

A current workaround would be to set an empty body explicitly:

Http.Request request = Helpers.fakeRequest().bodyRaw(ByteString.empty()).build();
Helpers.route(app, request);

I appreciate if you can open an issue on Github so that we can add it to our todo list. :slight_smile:


Hi @marcospereira

Sure. I will open an issue on github and attach it here too.


@marcospereira Here is the github issue.

1 Like