### Question:
QBean extends FactoryExpressionBase<T> { @Override public T newInstance(Object... a) { try { T rv = create(getType()); if (fieldAccess) { for (int i = 0; i < a.length; i++) { Object value = a[i]; if (value != null) { Field field = fields.get(i); if (field != null) { field.set(rv, value); } } } } else { for (int i = 0; i < a.length; i++) { Object value = a[i]; if (value != null) { Method setter = setters.get(i); if (setter != null) { setter.invoke(rv, value); } } } } return rv; } 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  QBean(Class<? extends T> type, Map<String, ? extends Expression<?>> bindings); protected  QBean(Class<? extends T> type, Expression<?>... args); protected  QBean(Class<? extends T> type, boolean fieldAccess, Expression<?>... args); protected  QBean(Class<? extends T> type, boolean fieldAccess, Map<String, ? extends Expression<?>> bindings); @Override T newInstance(Object... a); @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 List<Expression<?>> getArgs();  }### Answer:
@Test public void with_class_and_exprs() { QBean<Entity> beanProjection = new QBean<Entity>(Entity.class, name, age, married); Entity bean = beanProjection.newInstance("Fritz", 30, true); assertEquals("Fritz", bean.getName()); assertEquals(30, bean.getAge()); assertEquals(true, bean.isMarried()); }
@Test public void with_path_and_exprs() { QBean<Entity> beanProjection = Projections.bean(entity, name, age, married); Entity bean = beanProjection.newInstance("Fritz", 30, true); assertEquals("Fritz", bean.getName()); assertEquals(30, bean.getAge()); assertEquals(true, bean.isMarried()); }
@Test public void with_unknown_properties() { QBean<Entity> beanProjection = Projections.bean(entity, name, age, Expressions.booleanPath("unknown")); Entity bean = beanProjection.newInstance("Fritz", 30, true); assertEquals("Fritz", bean.getName()); assertEquals(30, bean.getAge()); }
@Test public void with_class_and_map() { Map<String,Expression<?>> bindings = new LinkedHashMap<String,Expression<?>>(); bindings.put("name", name); bindings.put("age", age); bindings.put("married", married); QBean<Entity> beanProjection = new QBean<Entity>(Entity.class, bindings); Entity bean = beanProjection.newInstance("Fritz", 30, true); assertEquals("Fritz", bean.getName()); assertEquals(30, bean.getAge()); assertEquals(true, bean.isMarried()); }
@Test public void with_nested_factoryExpression() { Map<String,Expression<?>> bindings = new LinkedHashMap<String,Expression<?>>(); bindings.put("age", age); bindings.put("name", new Concatenation(name, name2)); QBean<Entity> beanProjection = new QBean<Entity>(Entity.class, bindings); FactoryExpression<Entity> wrappedProjection = FactoryExpressionUtils.wrap(beanProjection); Entity bean = wrappedProjection.newInstance(30, "Fri","tz"); assertEquals("Fritz", bean.getName()); }
@Test public void supertype_population() { QBean<SubEntity> beanProjection = new QBean<SubEntity>(SubEntity.class, true, name, age, married); SubEntity bean = beanProjection.newInstance("Fritz", 30, true); assertEquals("Fritz", bean.getName()); assertEquals(30, bean.getAge()); assertEquals(true, bean.isMarried()); }