RoundFunction implements Function { public String execute(List<String> parameterList, TestContext context) { if (CollectionUtils.isEmpty(parameterList)) { throw new InvalidFunctionUsageException("Function parameters must not be empty"); } return Long.valueOf(Math.round(Double.valueOf((parameterList.get(0))))).toString(); }  String execute(List<String> parameterList, TestContext context);  }
@Test public void testFunction() { Assert.assertEquals(function.execute(Collections.singletonList("5.0"), context), "5"); Assert.assertEquals(function.execute(Collections.singletonList("5.2"), context), "5"); Assert.assertEquals(function.execute(Collections.singletonList("5.7"), context), "6"); Assert.assertEquals(function.execute(Collections.singletonList("-5.0"), context), "-5"); Assert.assertEquals(function.execute(Collections.singletonList("-5.2"), context), "-5"); Assert.assertEquals(function.execute(Collections.singletonList("-5.7"), context), "-6"); Assert.assertEquals(function.execute(Collections.singletonList("5"), context), "5"); Assert.assertEquals(function.execute(Collections.singletonList("-5"), context), "-5"); Assert.assertEquals(function.execute(Collections.singletonList("5.5"), context), "6"); }
@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); }