TranslateFunction implements Function { public String execute(List<String> parameterList, TestContext context) { if (parameterList == null || parameterList.size() < 3) { throw new InvalidFunctionUsageException("Function parameters not set correctly"); } String resultString = parameterList.get(0); String regex = null; String replacement = null; if (parameterList.size()>1) { regex = parameterList.get(1); } if (parameterList.size()>2) { replacement = parameterList.get(2); } if (regex != null && replacement != null) { resultString = resultString.replaceAll(regex, replacement); } return resultString; }  String execute(List<String> parameterList, TestContext context);  }
@Test public void testFunction() { List<String> params = new ArrayList<String>(); params.add("H.llo TestFr.mework"); params.add("\\."); params.add("a"); Assert.assertEquals(function.execute(params, context), "Hallo TestFramework"); }
@Test(expectedExceptions = {InvalidFunctionUsageException.class}) public void testMissingParameter() { List<String> params = new ArrayList<String>(); params.add("H.llo TestFr.mework"); params.add("\\."); function.execute(params, context); }
@Test(expectedExceptions = {InvalidFunctionUsageException.class}) public void testNoParameters() { function.execute(Collections.<String>emptyList(), context); }