### Question:
EnumConversion extends FactoryExpressionBase<T> { @Override public T newInstance(Object... args) { if (args[0] != null) { if (args[0] instanceof String || args[0] instanceof Character) { @SuppressWarnings("unchecked") T rv = (T) Enum.valueOf(getType().asSubclass(Enum.class), (String) args[0].toString()); return rv; } else if (args[0] instanceof Number) { return values[((Number) args[0]).intValue()]; } else { @SuppressWarnings("unchecked") T rv = (T) args[0]; return rv; } } else { return null; } } EnumConversion(Expression<T> expr); @Override R accept(Visitor<R, C> v, C context); @Override List<Expression<?>> getArgs(); @Override T newInstance(Object... args);  }### Answer:
@Test public void nameForCharacter() { EnumPath<Color> color = Expressions.enumPath(Color.class, "path"); EnumConversion<Color> conv = new EnumConversion<Color>(color); assertEquals(Color.W, conv.newInstance('W')); }
@Test public void name() { EnumPath<Color> color = Expressions.enumPath(Color.class, "path"); EnumConversion<Color> conv = new EnumConversion<Color>(color); assertEquals(Color.BLUE, conv.newInstance("BLUE")); }
@Test public void ordinal() { EnumPath<Color> color = Expressions.enumPath(Color.class, "path"); EnumConversion<Color> conv = new EnumConversion<Color>(color); assertEquals(Color.RED, conv.newInstance(2)); }
@Test(expected = IllegalArgumentException.class) public void illegal() { StringPath string = Expressions.stringPath("path"); EnumConversion<String> conv = new EnumConversion<String>(string); fail("EnumConversion successfully created for a non-enum type"); conv.newInstance(0); }