/** * Ensure escalate appropriately if failure in extending the {@link HttpTemplateAutoWireSection}. */ public void testExtensionFailure() throws Exception { final Exception failure = new Exception("TEST"); // Record initiate this.recordReturn(this.sourceContext, this.sourceContext.isLoadingType(), false); this.recordReturn( this.sourceContext, this.sourceContext.loadClass(MockWoofTemplateExtensionSource.class.getName()), MockWoofTemplateExtensionSource.class); // Flag to throw exception MockWoofTemplateExtensionSource.reset(failure); // Test try { this.extendTemplate(MockWoofTemplateExtensionSource.class.getName()); } catch (WoofTemplateExtensionException ex) { assertEquals( "Incorrect exception", "Failed loading Template Extension " + MockWoofTemplateExtensionSource.class.getName() + ". TEST", ex.getMessage()); assertSame("Incorrect cause", failure, ex.getCause()); } }
/** * Ensure escalate appropriately if fail to instantiate the {@link * MockWoofTemplateExtensionSource}. */ public void testFailToInstantiateExtension() throws Exception { UnknownClassError error = new UnknownClassError("Unknown", "UNKNOWN"); // Record fail to instantiate this.recordReturn(this.sourceContext, this.sourceContext.isLoadingType(), false); this.sourceContext.loadClass("UNKNOWN"); this.control(this.sourceContext).setThrowable(error); // Test try { this.extendTemplate("UNKNOWN"); fail("Should not be successful"); } catch (WoofTemplateExtensionException ex) { assertEquals( "Incorrect exception", "Failed loading Template Extension UNKNOWN. Unknown", ex.getMessage()); assertSame("Incorrect cause", error, ex.getCause()); } }