admin管理员组

文章数量:1399306

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?

本文标签: javaHow to add params other than PathVariable in the mockMvc junit testing for an REST APIStack Overflow