java Mock使用Mockito和PowerMock获取HttpServletRequest和Principal的静态方法
我想模拟一个包含两个参数的静态方法,HttpServletRequest和Principal
//Here is the method signature
public static String getRole(HttpServletRequest request, Principal principal) throws Exception {
}
我正在定义安全测试配置,以便将安全凭据注入测试类
// 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");
}
}
我正在为一个内部调用上述静态方法的方法编写junit测试用例。如何在junit类中编写对上述静态方法的预期
when(StaticClassA.getRole(??????, ??????)).thenReturn("ROLE1");
共 (0) 个答案