是否可以模拟(当前使用 Mockito,也可能是其他测试库)类中的字段“sf”,如下所示:
public class SomeFilter implements Filter {
private Logger log = Logger.getLogger(getClass());
private SomeField sf = new SomeField();
@Override
public void init(FilterConfig fc) throws ServletException {
log.info("");
}
@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain fc) throws IOException, ServletException {
fc.doFilter(request, response);
}
@Override
public void destroy() {
log.info("");
}
}
如果是这样,怎么做?