سؤال

i want to set the UserPrincipal() to null from junit of my application. For that i have tried to set the request to null but i got null pointer exception. Please help me to resolve the problem. Below is my code

if(request.getUserPrincipal()!=null){
     username=request.getUserPrincipal().getName();
}

i want to get the condition false.

هل كانت مفيدة؟

المحلول

i have found the solution...

get MockHttpServletRequest from junit and set userprinciple to null

MockHttpServletRequest httpServletRequest = new MockHttpServletRequest();
httpServletRequest.setUserPrincipal(null);
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top