@Test public void testReplacePropertiesSyntaxError() throws Exception { final Properties props = initProperties(); try { final String value = (String) getReplacePropertiesMethod().invoke( null, "${a", new PropertiesExpander(props), null); fail("expected to fail, instead got: " + value); } catch (InvocationTargetException ex) { assertEquals("Invalid exception cause message", "Syntax error in property: ${a", ex.getCause().getMessage()); } }
@Test public void testReplacePropertiesMissingProperty() throws Exception { final Properties props = initProperties(); try { final String value = (String) getReplacePropertiesMethod().invoke( null, "${c}", new PropertiesExpander(props), null); fail("expected to fail, instead got: " + value); } catch (InvocationTargetException ex) { assertEquals("Invalid exception cause message", "Property ${c} has not been set", ex.getCause().getMessage()); } }
@Test public void testReplacePropertiesNoReplace() throws Exception { final String[] testValues = {null, "", "a", "$a", "{a", "{a}", "a}", "$a}", "$", "a$b", }; final Properties props = initProperties(); for (String testValue : testValues) { final String value = (String) getReplacePropertiesMethod().invoke( null, testValue, new PropertiesExpander(props), null); assertEquals("\"" + testValue + "\"", value, testValue); } }
@Test public void testReplacePropertiesReplace() throws Exception { final String[][] testValues = { {"${a}", "A"}, {"x${a}", "xA"}, {"${a}x", "Ax"}, {"${a}${b}", "AB"}, {"x${a}${b}", "xAB"}, {"${a}x${b}", "AxB"}, {"${a}${b}x", "ABx"}, {"x${a}y${b}", "xAyB"}, {"${a}x${b}y", "AxBy"}, {"x${a}${b}y", "xABy"}, {"x${a}y${b}z", "xAyBz"}, {"$$", "$"}, }; final Properties props = initProperties(); for (String[] testValue : testValues) { final String value = (String) getReplacePropertiesMethod().invoke( null, testValue[0], new PropertiesExpander(props), null); assertEquals("\"" + testValue[0] + "\"", testValue[1], value); } }