@Test public void testExecuteNullCondition() { Rule rule = new Rule(); try { rule.execute(); Assert.fail("Should not be able to execute a rule with no condition set."); } catch (SystemException e) { Assert.assertNotNull("Invalid exception message for executing rule with no condition", e.getMessage()); } }
@Test public void testGetTriggerValueInvalidTrigger() { SubordinateTrigger trigger = new MyInvalidTrigger(); AbstractCompare compare = new MyCompare(trigger, null); try { compare.execute(); Assert.fail("Should have thrown exception for invalid subordinate trigger."); } catch (SystemException e) { Assert.assertNotNull("Exception for invalid subordinate trigger should have a message", e.getMessage()); } }
/** * Test register - exception on register with key already in use. */ @Test public void testRegisterFail() { final String key = "test123"; WComponent component = new DefaultWComponent(); UIRegistryClassLoaderImpl reg = new UIRegistryClassLoaderImpl(); reg.register(key, component); try { reg.register(key, component); Assert.fail( "attempted registration with key already used should have thrown an exception"); } catch (SystemException e) { String expectedMessage = "Cannot re-register a component. Key = " + key; Assert.assertEquals("exceptions hould have contained message expected", expectedMessage, e.getMessage()); } }
@Test public void testGetProjectVersion() { String testVersion = "TEST VERSION"; Config.getInstance().setProperty(ConfigurationProperties.PROJECT_VERSION, testVersion); Assert.assertEquals("Wrong project version returned", testVersion, WebUtilities. getProjectVersion()); try { Config.getInstance().clearProperty(ConfigurationProperties.PROJECT_VERSION); WebUtilities.getProjectVersion(); Assert.fail("An exception should have been thrown for a null project version"); } catch (SystemException e) { Assert.assertNotNull("No error message included for null project version", e. getMessage()); } }
/** * Test register - exception on register with key already in use. */ @Test public void testRegisterFail() { final String key = "test123"; WComponent component = new DefaultWComponent(); UIRegistryAmicableImpl reg = new UIRegistryAmicableImpl(); reg.register(key, component); try { reg.register(key, component); Assert.fail( "attempted registration with key already used should have thrown an exception"); } catch (SystemException e) { String expectedMessage = "Cannot re-register a component. Key = " + key; Assert.assertEquals("exceptions hould have contained message expected", expectedMessage, e.getMessage()); } }
} catch (SystemException e) { Assert.assertNotNull("Exception should have a message for invalid string", e. getMessage()); } catch (SystemException e) { Assert.assertNotNull("Exception should have a message for unsupported data type", e. getMessage());
} catch (SystemException e) { Assert.assertNotNull("Exception should have a message for unsupported data type", e. getMessage()); } catch (SystemException e) { Assert.assertNotNull("Exception should have a message for unsupported data type", e. getMessage());
@Test public void testXssEscaping() throws IOException, SAXException, XpathException { WPartialDateField dateField = new WPartialDateField(); dateField.setData(getMaliciousContent()); try { assertSafeContent(dateField); Assert.fail("Invalid date should not have been parsed."); } catch (SystemException e) { Assert.assertNotNull("Exception has no message", e.getMessage()); } dateField.setData(null); dateField.setToolTip(getMaliciousAttribute("ui:datefield")); assertSafeContent(dateField); dateField.setAccessibleText(getMaliciousAttribute("ui:datefield")); assertSafeContent(dateField); } }
} catch (SystemException e) { Assert.assertNotNull("Exception should have a message for unsupported data type", e. getMessage());