AbsoluteFunction implements Function { public String execute(List<String> parameterList, TestContext context) { if (CollectionUtils.isEmpty(parameterList)) { throw new InvalidFunctionUsageException("Function parameters must not be empty"); } String param = parameterList.get(0); if (param.contains(".")) { return String.valueOf(Math.abs(Double.valueOf(param))); } else { return String.valueOf(Math.abs(Integer.valueOf(param))); } }  String execute(List<String> parameterList, TestContext context);  }
@Test public void testFunction() { Assert.assertEquals(function.execute(Collections.singletonList("-0.0"), context), "0.0"); Assert.assertEquals(function.execute(Collections.singletonList("-0"), context), "0"); Assert.assertEquals(function.execute(Collections.singletonList("2.0"), context), "2.0"); Assert.assertEquals(function.execute(Collections.singletonList("2"), context), "2"); Assert.assertEquals(function.execute(Collections.singletonList("2.5"), context), "2.5"); Assert.assertEquals(function.execute(Collections.singletonList("-2.0"), context), "2.0"); Assert.assertEquals(function.execute(Collections.singletonList("-2"), context), "2"); Assert.assertEquals(function.execute(Collections.singletonList("-2.5"), context), "2.5"); }
@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); }