gpt4 book ai didi

java - 模拟模拟 pageContext 的 httpRequest

转载 作者:行者123 更新时间:2023-11-29 08:55:06 28 4
gpt4 key购买 nike

有人知道如何模拟以下内容吗?

pageContext.getRequest().getParameter("par");// here I get a null pointer exception on getParameter

有没有办法在模拟的 pageContext 对象中注入(inject) httpRequest?

提前致谢。

最佳答案

stub 可以在链中使用。以下片段显示了这个想法

    PageContext pageContext = mock(PageContext.class);
HttpServletRequest request = mock(HttpServletRequest.class);
when(request.getParameter("par")).thenReturn("what you want");
when(pageContext.getRequest()).thenReturn(request);

关于java - 模拟模拟 pageContext 的 httpRequest,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20680864/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com