RandomNumberFunction implements Function { public String execute(List<String> parameterList, TestContext context) { int numberLength; boolean paddingOn = true; if (CollectionUtils.isEmpty(parameterList)) { throw new InvalidFunctionUsageException("Function parameters must not be empty"); } if (parameterList.size() > 2) { throw new InvalidFunctionUsageException("Too many parameters for function"); } numberLength = Integer.valueOf(parameterList.get(0)); if (numberLength < 0) { throw new InvalidFunctionUsageException("Invalid parameter definition. Number of letters must not be positive non-zero integer value"); } if (parameterList.size() > 1) { paddingOn = Boolean.valueOf(parameterList.get(1)); } return getRandomNumber(numberLength, paddingOn); }  String execute(List<String> parameterList, TestContext context); static String getRandomNumber(int numberLength, boolean paddingOn); static String checkLeadingZeros(String generated, boolean paddingOn);  }
@Test public void testFunction() { List<String> params = new ArrayList<String>(); params.add("3"); Assert.assertTrue(Integer.valueOf(function.execute(params, context)) < 1000); params = new ArrayList<String>(); params.add("3"); params.add("false"); String generated = function.execute(params, context); Assert.assertTrue(generated.length() <= 3); Assert.assertTrue(generated.length() > 0); }
@Test(expectedExceptions = {InvalidFunctionUsageException.class}) public void testWrongParameterUsage() { function.execute(Collections.singletonList("-1"), context); }
@Test(expectedExceptions = {InvalidFunctionUsageException.class}) public void testNoParameters() { function.execute(Collections.<String>emptyList(), context); }
@Test(expectedExceptions = {InvalidFunctionUsageException.class}) public void testTooManyParameters() { List<String> params = new ArrayList<String>(); params.add("3"); params.add("true"); params.add("too much"); function.execute(params, context); }