Play framework 2.2.1: Create Http.Context for tests

后端 未结 4 1394
半阙折子戏
半阙折子戏 2020-12-29 10:35

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

4条回答
  •  甜味超标
    2020-12-29 10:46

    Looks like this seems to have fixed it for me:

    @Before
    public void setUp() throws Exception {
        Map flashData = Collections.emptyMap();
        Map argData = Collections.emptyMap();
        Long id = 2L;
        play.api.mvc.RequestHeader header = mock(play.api.mvc.RequestHeader.class);
        Http.Context context = new Http.Context(id, header, request, flashData, flashData, argData);
        Http.Context.current.set(context);
    }
    

    The part that fixes it specifically is:

    Http.Context.current.set(context);
    

提交回复
热议问题