### Question:
TailorHelper { public static String replaceVars(final CommandTransformation trafo, String text) { final Map<String, String> inputArguments = trafo.getArguments(); if (inputArguments == null || inputArguments.isEmpty()) { return text; } final Matcher matcher = VAR_PATTERN.matcher(text); while (matcher.find()) { final String placeholder = matcher.group(1); String inputValue = null; if ("*".equals(placeholder)) { final String[] split = inputArguments.get("").split(" "); inputValue = split[split.length - 1]; } else { inputValue = inputArguments.get(placeholder); } if (inputValue != null) { String replace = matcher.group().replace("$", "\\$"); replace = replace.replace("{", "\\{"); replace = replace.replace("}", "\\}"); replace = replace.replace("*", "\\*"); text = text.replaceAll(replace, inputValue); } } return text; }  static void removeComment(final CommentedLine commentedLine); static String replaceVars(final CommandTransformation trafo, String text);  }### Answer:
@Test public void testReplaceVars() { final CommandTransformation rooCommand = new CommandTransformation( "project --topLevelPackage com.foo.sample --projectName test --domain otherdomainname"); final String result = TailorHelper.replaceVars(rooCommand, "module create --moduleName ${domain} --topLevelPackage ${topLevelPackage}"); final String expectedResult = "module create --moduleName otherdomainname --topLevelPackage com.foo.sample"; Assert.assertEquals("Unexpected result: " + result, expectedResult, result); }
@Test public void testReplaceVarsDuplicatePlaceholders() { final CommandTransformation rooCommand = new CommandTransformation( "project --topLevelPackage com.foo.sample --projectName test --domain otherdomainname"); final String result = TailorHelper.replaceVars(rooCommand, "module create --moduleName ${domain} --topLevelPackage ${topLevelPackage}.${domain}"); final String expectedResult = "module create --moduleName otherdomainname --topLevelPackage com.foo.sample.otherdomainname"; Assert.assertEquals("Unexpected result: " + result, expectedResult, result); }
@Test public void testReplaceVarsForUnnamedArgument() { final CommandTransformation rooCommand = new CommandTransformation("cd test-data"); final String result = TailorHelper.replaceVars(rooCommand, "module focus --moduleName ${*}"); Assert.assertTrue("* was not replaced: " + result, result.endsWith("test-data")); }
@Test public void testReplaceVarsSimilarPlaceholders() { final CommandTransformation rooCommand = new CommandTransformation( "project --topLevelPackage com.foo.sample --projectName test --domain otherdomainname"); final String result = TailorHelper.replaceVars(rooCommand, "module create --moduleName ${xdomain} --topLevelPackage ${topLevelPackagex}"); final String expectedResult = "module create --moduleName ${xdomain} --topLevelPackage ${topLevelPackagex}"; Assert.assertEquals("Unexpected result: " + result, expectedResult, result); }