### Question:
NumberConversions extends FactoryExpressionBase<T> { @Override @SuppressWarnings("unchecked") public T newInstance(Object... args) { for (int i = 0; i < args.length; i++) { Class<?> type = expr.getArgs().get(i).getType(); if (Enum.class.isAssignableFrom(type) && !type.isInstance(args[i])) { if (args[i] instanceof String) { args[i] = Enum.valueOf((Class) type, (String) args[i]); } else if (args[i] instanceof Number) { args[i] = getValues((Class) type)[((Number) args[i]).intValue()]; } } else if (args[i] instanceof Number && !type.isInstance(args[i])) { if (type.equals(Boolean.class)) { args[i] = ((Number) args[i]).intValue() > 0; } else if (Number.class.isAssignableFrom(type)) { args[i] = MathUtils.cast((Number) args[i], (Class) type); } } } return expr.newInstance(args); } NumberConversions(FactoryExpression<T> expr); @Override R accept(Visitor<R, C> v, C context); @Override List<Expression<?>> getArgs(); @Override @SuppressWarnings("unchecked") T newInstance(Object... args);  }### Answer:
@Test public void name() { EnumPath<Color> color = Expressions.enumPath(Color.class, "path"); QTuple qTuple = Projections.tuple(color); NumberConversions<Tuple> conversions = new NumberConversions<Tuple>(qTuple); assertEquals(Color.BLUE, conversions.newInstance("BLUE").get(color)); }
@Test public void ordinal() { EnumPath<Color> color = Expressions.enumPath(Color.class, "path"); QTuple qTuple = Projections.tuple(color); NumberConversions<Tuple> conversions = new NumberConversions<Tuple>(qTuple); assertEquals(Color.RED, conversions.newInstance(2).get(color)); }
@Test public void safe_number_conversion() { StringPath strPath = Expressions.stringPath("strPath"); NumberPath<Integer> intPath = Expressions.numberPath(Integer.class, "intPath"); QTuple qTuple = Projections.tuple(strPath, intPath); NumberConversions<Tuple> conversions = new NumberConversions<Tuple>(qTuple); assertNotNull(conversions.newInstance(1, 2)); }
@Test public void number_conversion() { StringPath strPath = Expressions.stringPath("strPath"); NumberPath<Integer> intPath = Expressions.numberPath(Integer.class, "intPath"); QTuple qTuple = Projections.tuple(strPath, intPath); NumberConversions<Tuple> conversions = new NumberConversions<Tuple>(qTuple); Tuple tuple = conversions.newInstance("a", Long.valueOf(3)); assertEquals("a", tuple.get(strPath)); assertEquals(Integer.valueOf(3), tuple.get(intPath)); }