ModelImporter { public Map<String, DataType> getTypes() { return resolvedTypes; } ModelImporter(ModelInfo modelInfo, Iterable<DataType> systemTypes); Map<String, DataType> getTypes(); Iterable<Conversion> getConversions(); Iterable<ModelContext> getContexts(); String getDefaultContextName(); void validateFreeAndBoundParameters(ClassType type, ClassInfo definition); boolean isParentGeneric(ClassType type);  }
@Test public void handleModelInfoGenerics() { try { ModelManager modelManager = new ModelManager(); GentestModelInfoProvider gentestModelInfoProvider = new GentestModelInfoProvider(); ModelImporter systemImporter = new ModelImporter(ModelInfoLoader.getModelInfoProvider(new VersionedIdentifier().withId("System").withVersion("1")).load(), null); ModelInfo gentestModel = gentestModelInfoProvider.load(); ModelImporter gentestImporter = new ModelImporter(gentestModel, systemImporter.getTypes().values()); assertThat(gentestModel.getName(), is("GENTEST")); assertThat(gentestModel.getTypeInfo().size(), is(8)); Map<String, DataType> dataTypeMap = gentestImporter.getTypes(); Map<String, DataType> systemTypeMap = systemImporter.getTypes(); ClassInfo myGeneric = (ClassInfo)gentestModel.getTypeInfo().get(0); assertThat(myGeneric.getName(), is("GENTEST.MyGeneric")); assertThat(myGeneric.getParameter().size(), is(1)); assertThat(myGeneric.getParameter().get(0).getName(), is("T")); assertThat(myGeneric.getParameter().get(0).getConstraintType(), is("System.Any")); ClassType myGenericType = (ClassType)dataTypeMap.get("GENTEST.MyGeneric"); assertNotNull(myGenericType); assertThat(myGenericType.getName(), is("GENTEST.MyGeneric")); assertThat(myGenericType.getGenericParameterByIdentifier("T").getConstraint(), is(TypeParameter.TypeParameterConstraint.TYPE)); assertThat(myGenericType.getGenericParameterByIdentifier("T").getConstraintType(), is(systemTypeMap.get("System.Any"))); assertThat(myGenericType.getElements().size(), is(1)); ClassTypeElement field1 = myGenericType.getElements().get(0); assertThat(field1.getName(), is("field1")); assertThat(field1.getType().getClass().getSimpleName(), is("TypeParameter")); ClassType myQuantityType = (ClassType)dataTypeMap.get("GENTEST.MyQuantity"); assertNotNull(myQuantityType); assertThat(myQuantityType.getName(), is("GENTEST.MyQuantity")); assertThat(myQuantityType.getGenericParameters().size(), is(0)); assertThat(myQuantityType.getElements().size(), is(1)); ClassTypeElement overridenField1 = myQuantityType.getElements().get(0); assertThat(overridenField1.getName(), is("field1")); assertThat(((ClassType)overridenField1.getType()).getName(), is("System.Quantity")); ClassInfo map = (ClassInfo)gentestModel.getTypeInfo().get(2); assertThat(map.getName(), is("GENTEST.Map<S,T extends System.Integer>")); assertThat(map.getParameter().size(), is(0)); ClassType mapType = (ClassType)dataTypeMap.get("GENTEST.Map"); assertNotNull(mapType); assertThat(mapType.getName(), is("GENTEST.Map")); assertThat(mapType.getGenericParameterByIdentifier("S").getConstraint(), is(TypeParameter.TypeParameterConstraint.NONE)); assertNull(mapType.getGenericParameterByIdentifier("S").getConstraintType()); assertThat(mapType.getGenericParameterByIdentifier("T").getConstraint(), is(TypeParameter.TypeParameterConstraint.TYPE)); assertThat(mapType.getGenericParameterByIdentifier("T").getConstraintType(), is(systemTypeMap.get("System.Integer"))); ClassType myIntegerType = (ClassType)dataTypeMap.get("GENTEST.MyInteger"); assertNotNull(myIntegerType); assertThat(myIntegerType.getName(), is("GENTEST.MyInteger")); assertThat(myIntegerType.getGenericParameters().size(), is(0)); assertThat(myIntegerType.getElements().size(), is(1)); overridenField1 = myIntegerType.getElements().get(0); assertThat(overridenField1.getName(), is("field1")); assertThat(((SimpleType)overridenField1.getType()).getName(), is("System.Integer")); } catch (Exception e) { e.printStackTrace(); fail(); } }
@Test public void handleModelInfoGenericsSad1() { try { ModelManager modelManager = new ModelManager(); GentestModelInfoProviderSad1 gentestModelInfoProvider = new GentestModelInfoProviderSad1(); ModelImporter systemImporter = new ModelImporter(ModelInfoLoader.getModelInfoProvider(new VersionedIdentifier().withId("System").withVersion("1")).load(), null); ModelInfo gentestModel = gentestModelInfoProvider.load(); try { ModelImporter gentestImporter = new ModelImporter(gentestModel, systemImporter.getTypes().values()); fail(); } catch(Exception e) { assertThat(e.getMessage(), is("Unknown symbols [T]")); } } catch (Exception e) { e.printStackTrace(); fail(); } }