最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

java - How to add params other than @PathVariable in the mockMvc junit testing for an REST API - Stack Overflow

programmeradmin3浏览0评论

Method is as follows:

@PreAuthorize("hasAuthority('name.r') ")
  public ResponseEntity<String> getName(
      @PathVariable("name") String name, UserContext uc) 
{
uc.getAppName();
// method code goes here
}

For Junit of this method, I have used mockMvc as follows:

 this.mockMvc
        .perform(
            get("/name/dummyName"))
        .andExpect(status().isOk())

However, I am getting NullPointerException for "uc.getAppName()" as uc is not getting set and it's not a PathVariable. How to pass the mock of UserContext or any value for this while executing the test using mockMvc?

发布评论

评论列表(0)

  1. 暂无评论