SumFunction implements Function { public String execute(List<String> parameterList, TestContext context) { if (CollectionUtils.isEmpty(parameterList)) { throw new InvalidFunctionUsageException("Function parameters must not be empty"); } double result = 0.0; for (String token : parameterList) { result += Double.valueOf(token); } return Double.valueOf(result).toString(); }  String execute(List<String> parameterList, TestContext context);  }
@Test public void testFunction() { List<String> params = new ArrayList<String>(); params.add("3"); params.add("5.3"); params.add("4.7"); params.add("0"); Assert.assertEquals(function.execute(params, context), "13.0"); }
@Test(expectedExceptions = {NumberFormatException.class}) public void testWrongParameterUsage() { function.execute(Collections.singletonList("no digit"), context); }
@Test(expectedExceptions = {InvalidFunctionUsageException.class}) public void testNoParameters() { function.execute(Collections.<String>emptyList(), context); }