Skip to content
Snippets Groups Projects
Commit 3bbf9262 authored by felmer's avatar felmer
Browse files

LMS-257 bug in Template.createFreshCopy() fixed

SVN: 4653
parent 2fede76e
No related merge requests found
......@@ -250,15 +250,17 @@ public class Template
public Template createFreshCopy()
{
LinkedHashMap<String, VariableToken> map = new LinkedHashMap<String, VariableToken>();
for (VariableToken variableToken : variableTokens.values())
{
String variableName = variableToken.getVariableName();
map.put(variableName, new VariableToken(variableName));
}
ArrayList<IToken> list = new ArrayList<IToken>();
for (IToken token : tokens)
{
if (token instanceof VariableToken)
{
String variableName = ((VariableToken) token).getVariableName();
VariableToken variableToken = new VariableToken(variableName);
map.put(variableName, variableToken);
list.add(variableToken);
list.add(map.get(((VariableToken) token).getVariableName()));
} else
{
list.add(token);
......
......@@ -165,16 +165,24 @@ public class TemplateTest
@Test
public void testCreateFreshCopy()
{
Template template = new Template("hello ${name}!");
Template template = new Template("hello ${name}.${name}!");
Template template1 = template.createFreshCopy();
try
{
template1.createText();
fail("IllegalStateException expected");
} catch (IllegalStateException e)
{
assertEquals("The following variables are not bound: name ", e.getMessage());
}
template1.bind("name", "world");
assertEquals("hello world!", template1.createText());
assertEquals("hello ${name}!", template.createText(false));
assertEquals("hello world.world!", template1.createText());
assertEquals("hello ${name}.${name}!", template.createText(false));
Template template2 = template.createFreshCopy();
template2.bind("name", "universe");
assertEquals("hello universe!", template2.createText());
assertEquals("hello world!", template1.createText());
assertEquals("hello ${name}!", template.createText(false));
assertEquals("hello universe.universe!", template2.createText());
assertEquals("hello world.world!", template1.createText());
assertEquals("hello ${name}.${name}!", template.createText(false));
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment