I have a situation where I'm fairly certain exceptions will not occur. However, due to the design of the APIs consumed, I must account for them anyway. In the unlikely case these exceptions are thrown, I will be throwing a RuntimeException that will bubble up to the UI. Here's a simple case:
public class SomethingUsingJaxB{
private JAXBContext jaxbContext;
public SomethingUsingJaxB(){
try{
jaxbContext = JAXBContext.newInstance(Input.class);
}catch(JAXBException e){
throw new RuntimeException(e);
}
}
public Output getOutput(Input input){
//Do stuff with jaxbContext that also throws checked exceptions;
}
}
In the full version of this class, I also have a TransformerFactory
, Templates
, and DocumentBuilderFactory
which all throw checked exceptions, AND these factories return objects which themselves throw checked exceptions. I can't think of any situation where these exceptions are actually going to be thrown, but I'd like unit tests to account for them anyway.
Is there a "clean" way of unit testing these that doesn't heavily involve mocking frameworks?