@Test public void testInitInvalidClass() { MockControl mockRendererComponentFactoryDescriptorControl = MockClassControl.createControl(RendererComponentFactoryDescriptor.class); RendererComponentFactoryDescriptor mockRendererComponentFactoryDescriptor = (RendererComponentFactoryDescriptor) mockRendererComponentFactoryDescriptorControl.getMock(); Mock mockPlugin = new Mock(Plugin.class); mockRendererComponentFactoryDescriptor.getPlugin(); mockRendererComponentFactoryDescriptorControl.setReturnValue(null); Map params = new HashMap(); params.put("rendererComponentClass", "com.test.invalid.class"); mockRendererComponentFactoryDescriptor.getParams(); mockRendererComponentFactoryDescriptorControl.setReturnValue(params); mockRendererComponentFactoryDescriptor.getCompleteKey(); mockRendererComponentFactoryDescriptorControl.setReturnValue("pluginkey"); mockRendererComponentFactoryDescriptor.getPlugin(); mockRendererComponentFactoryDescriptorControl.setReturnValue(mockPlugin.proxy()); mockPlugin.expectAndThrow( "loadClass", new Constraint[] {new IsEqual("com.test.invalid.class"), new IsAnything()}, new ClassNotFoundException()); mockRendererComponentFactoryDescriptorControl.replay(); SimpleRendererComponentFactory simpleRendererComponentFactory = new SimpleRendererComponentFactory() { RendererComponent loadRendererComponent(Class rendererComponentClass) throws ClassNotFoundException { throw new ClassNotFoundException(); } }; try { simpleRendererComponentFactory.init(mockRendererComponentFactoryDescriptor); fail("Expected exception"); } catch (PluginParseException e) { assertTrue(e.getMessage().indexOf("Could not load renderer") >= 0); assertTrue(e.getMessage().indexOf("pluginkey") > 0); assertTrue(e.getMessage().indexOf("com.test.invalid.class") > 0); } }
public void testBuildsValidatorsForAliasError() { boolean pass = false; try { mockValidatorFileParser.expectAndReturn( "parseActionValidatorConfigs", C.args( C.IS_NOT_NULL, C.IS_NOT_NULL, C.eq("com/opensymphony/xwork2/TestBean-validation.xml")), new ArrayList()); mockValidatorFileParser.expectAndThrow( "parseActionValidatorConfigs", C.args( C.IS_NOT_NULL, C.IS_NOT_NULL, C.eq("com/opensymphony/xwork2/TestBean-badtest-validation.xml")), new ConfigurationException()); List validatorList = actionValidatorManager.getValidators(TestBean.class, "badtest"); } catch (XWorkException ex) { pass = true; } mockValidatorFileParser.verify(); assertTrue("Didn't throw exception on load failure", pass); }