### Question:
DefaultVariableManager implements VariableManager { @Override public String expandVariables( final Context context, final String source ) { final StringBuilder result = new StringBuilder(); for( int i = 0; i < source.length(); i++ ) { if( source.charAt(i) == '{' ) { if( i < source.length()-2 && source.charAt(i+1) == '$' ) { final int end = source.indexOf( '}', i ); if( end != -1 ) { final String varname = source.substring( i+2, end ); String value; try { value = getValue( context, varname ); } catch( final NoSuchVariableException | IllegalArgumentException e ) { value = e.getMessage(); } result.append( value ); i = end; } } else { result.append( '{' ); } } else { result.append( source.charAt(i) ); } } return result.toString(); } DefaultVariableManager( final Properties props ); @Override String parseAndGetValue( final Context context, final String link ); @Override // FIXME: somewhat slow. String expandVariables( final Context context, final String source ); @Override String getValue( final Context context, final String varName, final String defValue ); @Override String getVariable( final Context context, final String name ); @Override String getValue( final Context context, final String varName );  }### Answer:
@Test public void testExpand1() { final String res = m_variableManager.expandVariables( m_context, "Testing {$pagename}..." ); Assertions.assertEquals( "Testing "+PAGE_NAME+"...", res ); }
@Test public void testExpand2() { final String res = m_variableManager.expandVariables( m_context, "{$pagename} tested..." ); Assertions.assertEquals( PAGE_NAME+" tested...", res ); }
@Test public void testExpand3() { final String res = m_variableManager.expandVariables( m_context, "Testing {$pagename}, {$applicationname}" ); Assertions.assertEquals( "Testing "+PAGE_NAME+", JSPWiki", res ); }
@Test public void testExpand4() { final String res = m_variableManager.expandVariables( m_context, "Testing {}, {{{}" ); Assertions.assertEquals( "Testing {}, {{{}", res ); }