DisplayableEnum implements Displayable, Expression<String> { @Override public List<Constraint> createConstraint(String value) { if (value.equals(VALUE_UNDEFINED) || value.isEmpty()) return null; if (!range.contains(value)){ throw new IllegalArgumentException("Value not in domain: " + value); } BooleanExpression expression = new RelationalOperation<>(this, RelationalOperator.EQ, new StringConstant(new StringSetExpression(range), value)); Constraint constraint = new Constraint("userDefined", String.format("%s = %s", this.getInfo().get(0).getLabelCaption(), value), expression); return Collections.singletonList(constraint); } DisplayableEnum(String name, Set<String> range); @Override List<Constraint> createConstraint(String value); @Override List<InfoGUI> getInfo(); @Override String getName(); @Override String use(); @Override Expression<String> substitute(String name, Object value); @Override String value();  }
@Test public void createConstraint_setUndefined_returnsNull() { assertNull(defaultEnum.createConstraint(Displayable.VALUE_UNDEFINED)); }
@Test(expected = IllegalArgumentException.class) public void createConstraint_setValueNotInDomain_returnsNull() { assertNull(defaultEnum.createConstraint("Not in domain")); }
@Test public void createConstraint_setFirst_returnsValidConstraint() { List<Constraint> constraints = defaultEnum.createConstraint("first"); assertEquals(1, constraints.size()); Constraint constraint = constraints.get(0); assertEquals("userDefined", constraint.getConstraintGroup()); assertEquals("test_enum = first", constraint.getConstraintName()); }