/** * Verifies that if the {@link Transformer} does not support an output property, the resulting * {@link IllegalArgumentException} is ignored and the transformer supplier for {@link * LoggingModule} will still return the {@link Transformer}. */ @Test public void testUnsupportedProperty_ignoresIllegalArgumentException() { LoggingModule.TransformerSupplier supplier = new LoggingModule.TransformerSupplier(); // Fetches a Transformer from the supplier and confirms no exceptions are thrown and the // Transformer is not null, even though it is configured to throw an exception when certain // properties are set. Transformer transformer = supplier.get(); assertNotNull("Factory returned a null transformer", transformer); // Verifies that setOutputProperty was actually called. If it wasn't, nothing was actually // tested. verify(transformer, atLeastOnce()).setOutputProperty(eq(OutputKeys.INDENT), anyString()); }
/** * Verifies that if the TransformerFactory throws a configuration exception from {@code * newTransformer}, the supplier from the logging module will return {@code null}. */ @Test public void testTransformerFactoryNewTransformerConfigException_returnsNull() { MockTransformerFactory.isThrowInNewTransformer = true; LoggingModule.TransformerSupplier supplier = new LoggingModule.TransformerSupplier(); Transformer transformer = supplier.get(); assertNull( "Supplier should have returned null when a configuration exception is thrown", transformer); }
/** * Verifies that if the TransformerFactory throws a configuration error from {@code newInstance}, * the supplier from the logging module will return {@code null}. */ @Test public void testTransformerFactoryNewInstanceConfigError_returnsNull() { MockTransformerFactory.isThrowInConstructor = true; LoggingModule.TransformerSupplier supplier = new LoggingModule.TransformerSupplier(); Transformer transformer = supplier.get(); assertNull( "Supplier should have returned null when a configuration error is thrown", transformer); }