RandomEnumValueFunction implements Function { public String execute(List<String> params, TestContext context) { if (values == null) { return randomValue(params); } else { if (!params.isEmpty()) { throw new InvalidFunctionUsageException("The enumeration values have already been set"); } return randomValue(values); } }  String execute(List<String> params, TestContext context); List<String> getValues(); void setValues(List<String> values);  }
@Test public void testWithParameters() { RandomEnumValueFunction testee = new RandomEnumValueFunction(); final List<String> values = generateRandomValues(); for (int i=0; i<100; i++) { final String value = testee.execute(values, context); assertNotNull(value); assertTrue(values.contains(value)); } }
@Test(expectedExceptions = {InvalidFunctionUsageException.class}) public void testWithNone() { RandomEnumValueFunction testee = new RandomEnumValueFunction(); final List<String> noParameters = Collections.emptyList(); testee.execute(noParameters, context); }