【发布时间】:2021-10-15 21:06:43
【问题描述】:
在我的服务类中我有这个
CacheLookupPolling_Darwin CacheLookupPolling_Darwin_FRAGMENT = beanFactory.getBean(CacheLookupPolling_Darwin.class);
String s = CacheLookupPolling_Darwin_FRAGMENT.cacheLookupPolling_Darwin(String, httpHeaders);
CacheLookupPolling_Darwin 类定义了一个像这样的 DefaultHttpServletRequest
private DefaultHttpServletRequest Request;
在这个类中,函数 cacheLookupPolling_Darwin 执行以下初始化:
Request = (DefaultHttpServletRequest) ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest();
如何在我的测试类中模拟这个请求行为,.getRequest() 会抛出一个 nullPointerException。
有什么建议吗?
【问题讨论】:
标签: java spring-boot junit mocking mockito