I want to mock a static method taking two parameters, HttpServletRequest and Principal.
//Here is the method signature
public static String getRole(HttpServletRequest request, Principal principal) throws Exception {
}
I am defining the security test config for injecting security credentials into the test class.
// security test config
@Configuration
@EnableWebSecurity
@EnableWebMvc
static class Config extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
}
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication().withUser("user").password("password")
.roles("USER");
}
}
I am writing the junit test case for a method that internally calls the above static method. How to write the expectation for the above static method in the junit class?
when(StaticClassA.getRole(??????, ??????)).thenReturn("ROLE1");