From 3bbf9262972c4a80dcb7b7e05207e9d822728b1b Mon Sep 17 00:00:00 2001 From: felmer <felmer> Date: Thu, 6 Mar 2008 10:08:29 +0000 Subject: [PATCH] LMS-257 bug in Template.createFreshCopy() fixed SVN: 4653 --- .../cisd/common/utilities/Template.java | 10 ++++++---- .../cisd/common/utilities/TemplateTest.java | 20 +++++++++++++------ 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/common/source/java/ch/systemsx/cisd/common/utilities/Template.java b/common/source/java/ch/systemsx/cisd/common/utilities/Template.java index 33462ec1250..49e196e023c 100644 --- a/common/source/java/ch/systemsx/cisd/common/utilities/Template.java +++ b/common/source/java/ch/systemsx/cisd/common/utilities/Template.java @@ -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); diff --git a/common/sourceTest/java/ch/systemsx/cisd/common/utilities/TemplateTest.java b/common/sourceTest/java/ch/systemsx/cisd/common/utilities/TemplateTest.java index 8e019e68490..96beb89adfa 100644 --- a/common/sourceTest/java/ch/systemsx/cisd/common/utilities/TemplateTest.java +++ b/common/sourceTest/java/ch/systemsx/cisd/common/utilities/TemplateTest.java @@ -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)); } } -- GitLab