I have the next block of code:
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);
}
}
Any possible solutions to mock Thread.currentThread().getContextClassLoader() or how can I test this catch block?
You can set a custom context class loader. It is important to keep track of the original context class loader and put it back into context when your test is done.
http://docs.oracle.com/javase/7/docs/api/java/lang/Thread.html#setContextClassLoader(java.lang.ClassLoader)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With