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に設定しようとしましたが、nullポインター例外が発生しました。問題を解決するために私を助けてください。以下は私のコードです
if(request.getUserPrincipal()!=null){ username=request.getUserPrincipal().getName(); }
条件を偽にしたい。
私は解決策を見つけました...
junit から MockHttpServletRequest を取得し、userprinciple を null に設定します
MockHttpServletRequest httpServletRequest = new MockHttpServletRequest(); httpServletRequest.setUserPrincipal(null);