### Question:
TypeUtils { public static boolean shouldCreateNewClass(TypeDeclaration extending, TypeDeclaration... extended) { if (ScalarTypes.extendsScalarRamlType(extending)) { return false; } if (extending instanceof StringTypeDeclaration && extending.type() != null && extending.type().equals("string") && ((StringTypeDeclaration) extending).enumValues().size() > 0 && extended.length == 1 && extended[0] instanceof StringTypeDeclaration) { return true; } if (extending.parentTypes().size() > 1) { return true; } if (extending.type() != null && extending.type().equals("object")) { return true; } if (extended != null && extended.length > 0 && extended[0] instanceof JSONTypeDeclaration && extending instanceof JSONTypeDeclaration) { return false; } if (extended != null && extended.length > 0 && extended[0] instanceof XMLTypeDeclaration && extending instanceof XMLTypeDeclaration) { return false; } if (extending instanceof ObjectTypeDeclaration && extended.length > 0 && extended[0] instanceof ObjectTypeDeclaration) { ObjectTypeDeclaration extendingObject = (ObjectTypeDeclaration) extending; ObjectTypeDeclaration extendedObject = (ObjectTypeDeclaration) extended[0]; return extendedObject.properties().size() < extendingObject.properties().size(); } return false; }  static boolean shouldCreateNewClass(TypeDeclaration extending, TypeDeclaration... extended);  }### Answer:
@Test public void shouldExtendingString() throws Exception { ObjectTypeDeclaration typeDeclaration = (ObjectTypeDeclaration) finder("extendString.raml").get("ObjectOne").implementation(); TypeDeclaration property = findProperty(typeDeclaration, "name"); assertFalse(TypeUtils.shouldCreateNewClass(property, null)); }
@Test public void shouldExtendingObject() throws Exception { ObjectTypeDeclaration typeDeclaration = (ObjectTypeDeclaration) finder("extendObject.raml").get("ObjectOne").implementation(); TypeDeclaration property = findProperty(typeDeclaration, "name"); assertTrue(TypeUtils.shouldCreateNewClass(property, null)); }
@Test public void shouldExtendingObjectWithProperties() throws Exception { ObjectTypeDeclaration typeDeclaration = (ObjectTypeDeclaration) finder("extendObjectWithProperties.raml").get("ObjectOne") .implementation(); TypeDeclaration property = findProperty(typeDeclaration, "name"); assertTrue(TypeUtils.shouldCreateNewClass(property, null)); }
@Test public void shouldExtendingAnother() throws Exception { Map<String, GType> finder = finder("extendingAnother.raml"); ObjectTypeDeclaration object = (ObjectTypeDeclaration) finder.get("ObjectOne").implementation(); TypeDeclaration extending = findProperty(object, "name"); ObjectTypeDeclaration extended = (ObjectTypeDeclaration) finder.get(extending.type()).implementation(); assertFalse(TypeUtils.shouldCreateNewClass(extending, extended)); }
@Test public void shouldExtendingAnotherWithProperties() throws Exception { Map<String, GType> finder = finder("extendingAnotherWithProperties.raml"); ObjectTypeDeclaration object = (ObjectTypeDeclaration) finder.get("ObjectOne").implementation(); TypeDeclaration extending = findProperty(object, "name"); ObjectTypeDeclaration extended = (ObjectTypeDeclaration) finder.get(extending.type()).implementation(); assertTrue(TypeUtils.shouldCreateNewClass(extending, extended)); }
@Test public void shouldExtendingAnotherMultipleInheritance() throws Exception { Map<String, GType> finder = finder("extendObjectMultipleIneritance.raml"); ObjectTypeDeclaration object = (ObjectTypeDeclaration) finder.get("ObjectOne").implementation(); TypeDeclaration extending = findProperty(object, "name"); ObjectTypeDeclaration extended = (ObjectTypeDeclaration) finder.get(extending.type()); assertTrue(TypeUtils.shouldCreateNewClass(extending, extended)); }
@Test public void bigRaml() throws Exception { Map<String, GType> finder = finder("big.raml"); ObjectTypeDeclaration object = (ObjectTypeDeclaration) finder.get("RamlDataType").implementation(); TypeDeclaration extending = findProperty(object, "NilValue"); ObjectTypeDeclaration extended = (ObjectTypeDeclaration) finder.get(extending.type()); assertTrue(TypeUtils.shouldCreateNewClass(extending, extended)); }