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?