我有下一段代码:
public void init() {
facultyList = new ArrayList<>();
localeFile = new Properties();
try {
localeFile.load(Thread.currentThread().getContextClassLoader().getResourceAsStream(loadFileName()));
} catch (IOException | NullPointerException e) {
LOG.error("Host: " + ((HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest()).getRemoteHost()
+ " | Error in constructing of LocaleModel. More: " + e);
}
}
模拟Thread.currentThread().getContextClassLoader()
的任何可能解决方案或如何测试此catch
块?
答案 0 :(得分:2)
您可以设置自定义上下文类加载器。跟踪原始上下文类加载器并在测试完成后将其重新置于上下文中非常重要。