AttributeBytecodeGenerator { @SuppressWarnings("unchecked") public static <O, A> Class<? extends MultiValueAttribute<O, A>> generateMultiValueAttributeForField(Class<O> pojoClass, Class<A> attributeValueType, String fieldName, String attributeName) { ensureFieldExists(pojoClass, attributeValueType, fieldName, attributeName); return generateMultiValueAttribute(MultiValueAttribute.class, pojoClass, attributeValueType, attributeName, "object." + fieldName); }  static Map<String, ? extends Attribute<O, ?>> createAttributes(Class<O> pojoClass); @SuppressWarnings("unchecked") static Map<String, ? extends Attribute<O, ?>> createAttributes(Class<O> pojoClass, MemberFilter memberFilter); @SuppressWarnings("unchecked") static Map<String, ? extends Attribute<O, ?>> createAttributes(Class<O> pojoClass, MemberFilter memberFilter, Function<Member, String> attributeNameProducer); @SuppressWarnings("unchecked") static Class<? extends SimpleAttribute<O, A>> generateSimpleAttributeForField(Class<O> pojoClass, Class<A> attributeValueType, String fieldName, String attributeName); @SuppressWarnings("unchecked") static Class<? extends SimpleAttribute<O, A>> generateSimpleAttributeForGetter(Class<O> pojoClass, Class<A> attributeValueType, String getterMethodName, String attributeName); @SuppressWarnings("unchecked") static Class<? extends SimpleAttribute<O, A>> generateSimpleAttributeForParameterizedGetter(Class<O> pojoClass, Class<A> attributeValueType, String getterMethodName, String getterParameter, String attributeName); @SuppressWarnings("unchecked") static Class<? extends SimpleNullableAttribute<O, A>> generateSimpleNullableAttributeForField(Class<O> pojoClass, Class<A> attributeValueType, String fieldName, String attributeName); @SuppressWarnings("unchecked") static Class<? extends SimpleNullableAttribute<O, A>> generateSimpleNullableAttributeForGetter(Class<O> pojoClass, Class<A> attributeValueType, String getterMethodName, String attributeName); @SuppressWarnings("unchecked") static Class<? extends SimpleNullableAttribute<O, A>> generateSimpleNullableAttributeForParameterizedGetter(Class<O> pojoClass, Class<A> attributeValueType, String getterMethodName, String getterParameter, String attributeName); @SuppressWarnings("unchecked") static Class<? extends MultiValueAttribute<O, A>> generateMultiValueAttributeForField(Class<O> pojoClass, Class<A> attributeValueType, String fieldName, String attributeName); @SuppressWarnings("unchecked") static Class<? extends MultiValueAttribute<O, A>> generateMultiValueAttributeForGetter(Class<O> pojoClass, Class<A> attributeValueType, String getterMethodName, String attributeName); @SuppressWarnings("unchecked") static Class<? extends MultiValueAttribute<O, A>> generateMultiValueAttributeForParameterizedGetter(Class<O> pojoClass, Class<A> attributeValueType, String getterMethodName, String getterParameter, String attributeName); @SuppressWarnings("unchecked") static Class<? extends MultiValueNullableAttribute<O, A>> generateMultiValueNullableAttributeForField(Class<O> pojoClass, Class<A> attributeValueType, String fieldName, boolean componentValuesNullable, String attributeName); @SuppressWarnings("unchecked") static Class<? extends MultiValueNullableAttribute<O, A>> generateMultiValueNullableAttributeForGetter(Class<O> pojoClass, Class<A> attributeValueType, String getterMethodName, boolean componentValuesNullable, String attributeName); @SuppressWarnings("unchecked") static Class<? extends MultiValueNullableAttribute<O, A>> generateMultiValueNullableAttributeForParameterizedGetter(Class<O> pojoClass, Class<A> attributeValueType, String getterMethodName, String getterParameter, boolean componentValuesNullable, String attributeName);  }
@Test public void testGenerateMultiValueAttributeForField_ListField() throws Exception { Class<? extends MultiValueAttribute<PojoWithMultiValueField, String>> attributeClass = generateMultiValueAttributeForField(PojoWithMultiValueField.class, String.class, "foo", "foo"); MultiValueAttribute<PojoWithMultiValueField, String> attribute = attributeClass.newInstance(); validateAttribute(attribute, PojoWithMultiValueField.class, String.class, "foo", new PojoWithMultiValueField(), asList("bar1", "bar2")); }
@Test public void testGenerateMultiValueAttributeForField_PrimitiveArrayField() throws Exception { Class<? extends MultiValueAttribute<PojoWithMultiValuePrimitiveArrayField, Integer>> attributeClass = generateMultiValueAttributeForField(PojoWithMultiValuePrimitiveArrayField.class, Integer.class, "foo", "foo"); MultiValueAttribute<PojoWithMultiValuePrimitiveArrayField, Integer> attribute = attributeClass.newInstance(); validateAttribute(attribute, PojoWithMultiValuePrimitiveArrayField.class, Integer.class, "foo", new PojoWithMultiValuePrimitiveArrayField(), asList(5, 6)); }
@Test public void testGenerateMultiValueAttributeForField_ObjectArrayField() throws Exception { Class<? extends MultiValueAttribute<PojoWithMultiValueObjectArrayField, String>> attributeClass = generateMultiValueAttributeForField(PojoWithMultiValueObjectArrayField.class, String.class, "foo", "foo"); MultiValueAttribute<PojoWithMultiValueObjectArrayField, String> attribute = attributeClass.newInstance(); validateAttribute(attribute, PojoWithMultiValueObjectArrayField.class, String.class, "foo", new PojoWithMultiValueObjectArrayField(), asList("bar1", "bar2")); }
@Test(expected = IllegalStateException.class) public void testGenerateMultiValueAttributeForField_ExceptionHandling1() throws Exception { generateMultiValueAttributeForField(null, String.class, "foo", "object.foo"); }
@Test(expected = IllegalStateException.class) public void testGenerateMultiValueAttributeForField_ExceptionHandling2() throws Exception { generateMultiValueAttributeForField(PojoWithMultiValueField.class, null, "foo", "foo"); }