final SetField fieldDetails = new SetField(
SIMPLE_CLASS3_DECLARED_BY_MID, new JavaType(
SET.getFullyQualifiedTypeName(), 0, DataType.TYPE,
null, Arrays.asList(SIMPLE_CLASS3_TYPE)),
new JavaSymbolName("children"), SIMPLE_CLASS3_TYPE,
Cardinality.ONE_TO_MANY);
final FieldMetadataBuilder fieldBuilder = new FieldMetadataBuilder(
fieldDetails.getPhysicalTypeIdentifier(), Modifier.PRIVATE,
new ArrayList<AnnotationMetadataBuilder>(),
fieldDetails.getFieldName(), fieldDetails.getFieldType());
fieldBuilder.setFieldInitializer("new HashSet<SimpleClass3>()");
final ClassOrInterfaceTypeDetails newClassDetails = addField(
simpleInterfaceDetails, fieldBuilder.build());
// Invoke
final String result = typeParsingService
.getCompilationUnitContents(newClassDetails);
saveResult(file, result, "-addField");
checkSimple3Class(result);
assertTrue(result
.contains("private Set<SimpleClass3> children = new HashSet<SimpleClass3>();"));
// Add another
final ClassOrInterfaceTypeDetails simpleInterfaceDetails2 = typeParsingService
.getTypeFromString(result, SIMPLE_CLASS3_DECLARED_BY_MID,
SIMPLE_CLASS3_TYPE);
final ReferenceField fieldDetails2 = new ReferenceField(
SIMPLE_CLASS3_DECLARED_BY_MID, SIMPLE_CLASS2_TYPE,
new JavaSymbolName("referenceField"), Cardinality.MANY_TO_ONE);
final FieldMetadataBuilder fieldBuilder2 = new FieldMetadataBuilder(
fieldDetails2.getPhysicalTypeIdentifier(), Modifier.PRIVATE,
new ArrayList<AnnotationMetadataBuilder>(),
fieldDetails2.getFieldName(), fieldDetails2.getFieldType());