public void testFieldInitializationAndTypeNames() {
PersistentClass classMapping = getCfg().getClassMapping("org.hibernate.tool.hbm2x.Article");
Cfg2JavaTool cfg2java = new Cfg2JavaTool();
POJOClass clazz = cfg2java.getPOJOClass(classMapping);
Property p = classMapping.getProperty("AMap");
assertEquals("all types should be fully qualified when no importcontext","java.util.Map<java.lang.String,org.hibernate.tool.hbm2x.Article>",cfg2java.getJavaTypeName(p, true));
assertEquals("Map<String,Article>",cfg2java.getJavaTypeName(p, true, clazz));
assertEquals("new HashMap<String,Article>(0)", clazz.getFieldInitialization(p, true));
assertEquals("new HashMap(0)", clazz.getFieldInitialization(p, false));
p = classMapping.getProperty("aList");
assertEquals("lists should not have the index visible in the declaration", "List<Article>",cfg2java.getJavaTypeName(p, true, clazz));
assertEquals("all types should be fully qualified when no importcontext","java.util.List<org.hibernate.tool.hbm2x.Article>",cfg2java.getJavaTypeName(p, true));
assertEquals("new ArrayList<Article>(0)", clazz.getFieldInitialization(p, true));
assertEquals("new ArrayList(0)", clazz.getFieldInitialization(p, false));
p = classMapping.getProperty("content");
assertEquals("\"what can I say\"",clazz.getFieldInitialization(p, false));
p = classMapping.getProperty("bagarticles");
assertEquals("Should be a list via property-type", "java.util.List", cfg2java.getJavaTypeName( p, false ));
assertEquals("Should be a a generic'd list when generics=true", "java.util.List<org.hibernate.tool.hbm2x.Article>", cfg2java.getJavaTypeName( p, true ));
assertEquals("List<Article>",cfg2java.getJavaTypeName(p, true, clazz));
assertEquals("new ArrayList<Article>(0)", clazz.getFieldInitialization(p, true));
assertEquals("new ArrayList(0)", clazz.getFieldInitialization(p, false));
p = classMapping.getProperty("bagstrings");
assertEquals("Bag's are just a collection", "java.util.Collection", cfg2java.getJavaTypeName( p, false ));
assertEquals("Should be a a generic'd collection when generics=true", "java.util.Collection<java.lang.String>", cfg2java.getJavaTypeName( p, true ));
assertEquals("Collection<String>",cfg2java.getJavaTypeName(p, true, clazz));
assertEquals("new ArrayList<String>(0)", clazz.getFieldInitialization(p, true));
assertEquals("new ArrayList(0)", clazz.getFieldInitialization(p, false));
p = classMapping.getProperty("bagstrings");
assertEquals("new ArrayList(0)", clazz.getFieldInitialization(p, false));
p = classMapping.getProperty("naturalSortedArticlesMap");
assertEquals("java.util.SortedMap", cfg2java.getJavaTypeName( p, false));
assertEquals("SortedMap<String,Article>", cfg2java.getJavaTypeName( p, true, new ImportContextImpl("") ));
assertEquals("new TreeMap<String,Article>()", clazz.getFieldInitialization(p, true));
assertEquals("new TreeMap()", clazz.getFieldInitialization(p, false));
p = classMapping.getProperty("sortedArticlesMap");
assertEquals("java.util.SortedMap", cfg2java.getJavaTypeName( p, false));
assertEquals("SortedMap<String,Article>", cfg2java.getJavaTypeName( p, true, new ImportContextImpl("") ));
assertFalse(clazz.generateImports().contains("import comparator.NoopComparator;"));
assertEquals("new TreeMap(new NoopComparator())", clazz.getFieldInitialization(p, false));
assertTrue(clazz.generateImports().contains("import comparator.NoopComparator;"));
assertEquals("new TreeMap<String,Article>(new NoopComparator())", clazz.getFieldInitialization(p, true));
p = classMapping.getProperty("sortedArticlesSet");
assertEquals("java.util.SortedSet", cfg2java.getJavaTypeName( p, false));
assertEquals("SortedSet<Article>", cfg2java.getJavaTypeName( p, true, new ImportContextImpl("") ));
assertEquals("new TreeSet<Article>(new NoopComparator())", clazz.getFieldInitialization(p, true));
}