### Question:
ConstructorExpression extends FactoryExpressionBase<T> { @Override @SuppressWarnings("unchecked") public T newInstance(Object... args) { try { for (Function<Object[], Object[]> transformer : transformers) { args = transformer.apply(args); } return (T) constructor.newInstance(args); } catch (SecurityException e) { throw new ExpressionException(e.getMessage(), e); } catch (InstantiationException e) { throw new ExpressionException(e.getMessage(), e); } catch (IllegalAccessException e) { throw new ExpressionException(e.getMessage(), e); } catch (InvocationTargetException e) { throw new ExpressionException(e.getMessage(), e); } } protected  ConstructorExpression(Class<? extends T> type, Expression<?>... args); protected  ConstructorExpression(Class<? extends T> type, Class<?>[] paramTypes, Expression<?>... args); protected  ConstructorExpression(Class<? extends T> type, Class<?>[] paramTypes, ImmutableList<Expression<?>> args); @SuppressWarnings("unchecked") Expression<T> as(Path<T> alias); Expression<T> as(String alias); @Override R accept(Visitor<R, C> v, C context); @Override boolean equals(Object obj); @Override final List<Expression<?>> getArgs(); @Override @SuppressWarnings("unchecked") T newInstance(Object... args);  }### Answer:
@Test public void constructor() { Expression<Long> longVal = ConstantImpl.create(1L); Expression<String> stringVal = ConstantImpl.create(""); ProjectionExample instance = new ConstructorExpression<ProjectionExample>(ProjectionExample.class, new Class<?>[]{long.class, String.class}, longVal, stringVal).newInstance(0L, ""); assertNotNull(instance); assertEquals((Long) 0L, instance.id); assertTrue(instance.text.isEmpty()); }
@Test public void create() { Expression<Long> longVal = ConstantImpl.create(1L); Expression<String> stringVal = ConstantImpl.create(""); assertNotNull(Projections.constructor(ProjectionExample.class, longVal, stringVal).newInstance(0L, "")); }
@Test public void create2() { Expression<Long> longVal = ConstantImpl.create(1L); assertNotNull(Projections.constructor(ProjectionExample.class, longVal).newInstance(0L)); }
@Test public void create3() { assertNotNull(Projections.constructor(ProjectionExample.class).newInstance()); }
@Test public void create4() { Expression<String> stringVal = ConstantImpl.create(""); assertNotNull(Projections.constructor(ProjectionExample.class, stringVal).newInstance("")); }
@Test public void createNullPrimitive() { Expression<Boolean> booleanVal = ConstantImpl.create(false); Expression<Byte> byteVal = ConstantImpl.create((byte) 0); Expression<Character> charVal = ConstantImpl.create('\0'); Expression<Short> shortVal = ConstantImpl.create((short) 0); Expression<Integer> intVal = ConstantImpl.create(0); Expression<Long> longVal = ConstantImpl.create(0L); Expression<Float> floatVal = ConstantImpl.create(0.0F); Expression<Double> doubleVal = ConstantImpl.create(0.0); ProjectionExample instance = Projections.constructor(ProjectionExample.class, booleanVal, byteVal, charVal, shortVal, intVal, longVal, floatVal, doubleVal) .newInstance(null, null, null, null, null, null, null, null); assertNotNull(instance); }
@Test public void factoryExpression_newInstance() { FactoryExpression<ProjectionExample> constructor = Projections.constructor(ProjectionExample.class, concat); constructor = FactoryExpressionUtils.wrap(constructor); ProjectionExample projection = constructor.newInstance("12", "34"); assertEquals("1234", projection.text); }
@Test public void serializability() { ConstructorExpression<String> expr = Serialization.serialize(Projections.constructor(String.class)); assertEquals("", expr.newInstance()); }
@Test public void threadSafety() { final ConstructorExpression<String> expr = Projections.constructor(String.class); Runnable invoker = new Runnable() { @Override public void run() { expr.newInstance(); } }; ThreadSafety.check(invoker, invoker); }