I\'ve been trying to create an Http.Context for tests using its constructor unsuccessfully. Does anybody see what I\'m doing wrong?
I\'ve looked at the following but
As a combination of the other answers:
In build.sbt:
libraryDependencies += "org.mockito" % "mockito-core" % "1.10.19" % "test"
In your test class:
import play.mvc.Http;
import static org.mockito.Mockito.*;
@Before
public void setUp() throws Exception {
Http.Context context = mock(Http.Context.class);
Http.Flash flash = mock(Http.Flash.class);
when(context.flash()).thenReturn(flash);
Http.Context.current.set(context);
}
If you need more, just Mockito's functionalities. In case you are seeing any exceptions, just inspect the compiled code. IN my case, it was in target/scala-2.11/twirl/main/views/html/main.template.scala.