如何使用 Mockito 模拟用户定义的注释

问题描述

我正在为我的控制器层编写测试用例。我的控制器方法之一如下所示。

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@RestController
@RequestMapping("/v1")
public class MyController {

  private static Logger logger = LoggerFactory.getLogger(MyController.class);

  @Autowired
  private MyService service;

  @GetMapping("/{pathVar}/check")
  @MyAuthentication
  public ResponseEntity<Object> check(@PathVariable String pathVar,@MyAuthContext MyAuthInfo myAuthInfo) throws Exception {
    try {
      logger.info("Check API started by "+myAuthInfo.getUserId()+" and email "+ myAuthInfo.getUserEmail());
      return ResponseEntity
          .status(HttpStatus.OK)
          .body(service.isPartner(pathVar,myAuthInfo));
    } catch (Exception e) {
      logger.info("Check API encountered the error.",e);
      throw e;
    }
  }
}

有人可以在我编写测试用例时帮助模拟我的身份验证上下文吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)