SubstringBeforeFunction implements Function { public String execute(List<String> parameterList, TestContext context) { if (parameterList == null || parameterList.size() < 2) { throw new InvalidFunctionUsageException("Function parameters not set correctly"); } String resultString = parameterList.get(0); if (parameterList.size()>1) { String searchString = parameterList.get(1); resultString = resultString.substring(0, resultString.indexOf(searchString)); } return resultString; }  String execute(List<String> parameterList, TestContext context);  }
@Test public void testFunction() { List<String> params = new ArrayList<String>(); params.add("Hallo,TestFramework"); params.add(","); Assert.assertEquals(function.execute(params, context), "Hallo"); params.clear(); params.add("This is a test"); params.add("a"); Assert.assertEquals(function.execute(params, context), "This is "); }
@Test(expectedExceptions = {InvalidFunctionUsageException.class}) public void testNoParameters() { function.execute(Collections.<String>emptyList(), context); }