Search in sources :

Example 1 with RootClass

use of com.devonfw.cobigen.javaplugin.unittest.inputreader.testdata.RootClass in project cobigen by devonfw.

the class ParsedJavaModelBuilderTest method testCorrectExtractionOfInheritedFields_input_packageFolder.

/**
 * Tests the correct extraction of 'methodAccessibleFields' for {@link PackageFolder} as input.
 */
@Test
@Ignore("see com.devonfw.cobigen.javaplugin.inputreader.ParsedJavaModelBuilder.extractMethodAccessibleFields#L115")
public void testCorrectExtractionOfInheritedFields_input_packageFolder() {
    File packageFolderFile = new File(testFileRootPath + "packageFolder");
    PackageFolder packageFolder = new PackageFolder(packageFolderFile.toURI(), RootClass.class.getPackage().getName());
    JavaInputReader javaInputReader = new JavaInputReader();
    List<Object> objects = javaInputReader.getInputObjects(packageFolder, Charsets.UTF_8);
    assertThat(objects).as("The package folder does not contain any java sources!").isNotNull();
    assertThat(objects).hasSize(2);
    boolean found = false;
    for (Object o : objects) {
        Map<String, Object> model = javaInputReader.createModel(o);
        assertThat(model).as("No model has been created!").isNotNull();
        if (RootClass.class.getSimpleName().equals(JavaModelUtil.getName(model))) {
            List<Map<String, Object>> methodAccessibleFields = JavaModelUtil.getMethodAccessibleFields(model);
            assertThat(methodAccessibleFields).isNotNull();
            assertThat(methodAccessibleFields).hasSize(3);
            Map<String, Object> field = JavaModelUtil.getMethodAccessibleField(model, "value");
            assertThat(field).as("Field 'value' not found!").isNotNull();
            assertThat(field.get(ModelConstant.NAME)).isEqualTo("value");
            assertThat(field.get(ModelConstant.TYPE)).isEqualTo("String");
            assertThat(field.get(ModelConstant.CANONICAL_TYPE)).isEqualTo("java.lang.String");
            field = JavaModelUtil.getMethodAccessibleField(model, "setterVisibleByte");
            assertThat(field).as("Field 'setterVisibleByte' not found!").isNotNull();
            assertThat(field.get(ModelConstant.NAME)).isEqualTo("setterVisibleByte");
            assertThat(field.get(ModelConstant.TYPE)).isEqualTo("byte");
            assertThat(field.get(ModelConstant.CANONICAL_TYPE)).isEqualTo("byte");
            field = JavaModelUtil.getMethodAccessibleField(model, "genericAccessible");
            assertThat(field).as("Field 'genericAccessible' not found!").isNotNull();
            assertThat(field.get(ModelConstant.NAME)).isEqualTo("genericAccessible");
            // TODO: Known Issue, this is not possible as the SuperClass2 is not in the same folder and
            // thus not parsed. Thus, due to type erasure the parametric type will be lost.
            // assertThat(field.get(ModelConstant.TYPE)).isEqualTo("List<RootClass>");
            // assertThat(field.get(ModelConstant.CANONICAL_TYPE)).isEqualTo("java.util.List<RootClass>");
            assertThat(field.get(ModelConstant.TYPE)).isEqualTo("List");
            assertThat(field.get(ModelConstant.CANONICAL_TYPE)).isEqualTo("java.util.List");
            found = true;
        }
    }
    assertTrue("Class " + RootClass.class.getName() + "could not be found as child of the package folder.", found);
}
Also used : RootClass(com.devonfw.cobigen.javaplugin.unittest.inputreader.testdata.RootClass) PackageFolder(com.devonfw.cobigen.javaplugin.inputreader.to.PackageFolder) JavaInputReader(com.devonfw.cobigen.javaplugin.inputreader.JavaInputReader) File(java.io.File) Map(java.util.Map) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

JavaInputReader (com.devonfw.cobigen.javaplugin.inputreader.JavaInputReader)1 PackageFolder (com.devonfw.cobigen.javaplugin.inputreader.to.PackageFolder)1 RootClass (com.devonfw.cobigen.javaplugin.unittest.inputreader.testdata.RootClass)1 File (java.io.File)1 Map (java.util.Map)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1