Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想从我的应用程序的 junit 将 UserPrincipal() 设置为 null。为此,我尝试将请求设置为 null,但出现空指针异常。请帮我解决问题。下面是我的代码
if(request.getUserPrincipal()!=null){ username=request.getUserPrincipal().getName(); }
我想让条件为假。
我找到了解决方案...
从 junit 获取 MockHttpServletRequest 并将 userprinciple 设置为 null
MockHttpServletRequest httpServletRequest = new MockHttpServletRequest(); httpServletRequest.setUserPrincipal(null);