use of com.devonfw.cobigen.javaplugin.inputreader.JavaInputReader in project cobigen by devonfw.
the class ReflectedJavaModelBuilderTest method testCorrectlyInterpretingInterfaceInheritance.
/**
* Tests whether no {@link NullPointerException} will be thrown if an interface taken as an input extends another
* interface. Test for issue #250.
*
* @throws Exception test fails
*/
@Test
public void testCorrectlyInterpretingInterfaceInheritance() throws Exception {
JavaInputReader javaModelBuilder = new JavaInputReader();
javaModelBuilder.createModel(TestInterfaceInheritance.class);
}
use of com.devonfw.cobigen.javaplugin.inputreader.JavaInputReader in project cobigen by devonfw.
the class ReflectedJavaModelBuilderTest method testExtractionOfMethodAccessibleFields_inherited.
/**
* Tests whether the input type's extracted fields are complete (including annotations and javaDoc)
*/
@Test
public void testExtractionOfMethodAccessibleFields_inherited() {
JavaInputReader javaInputReader = new JavaInputReader();
Map<String, Object> model = javaInputReader.createModel(TestClass.class);
// test inherited field
Map<String, Object> inheritedField = JavaModelUtil.getMethodAccessibleField(model, "id");
assertThat(inheritedField).isNotNull();
assertThat(inheritedField.get(ModelConstant.NAME)).isEqualTo("id");
assertThat(inheritedField.get(ModelConstant.TYPE)).isEqualTo("Long");
assertThat(inheritedField.get(ModelConstant.CANONICAL_TYPE)).isEqualTo("java.lang.Long");
// is deprecated, so its not necessary to test here
// assertThat(inheritedField.get("isId")).isEqualTo("false");
// currently no javadoc provided
// assertThat(inheritedField.get(ModelConstant.JAVADOC)).isNotNull();
// assertThat(JavaModelUtil.getJavaDocModel(inheritedField).get("comment")).isEqualTo("Example
// JavaDoc");
// test annotations for attribute, getter, setter, is-method
assertThat(inheritedField.get(ModelConstant.ANNOTATIONS)).isNotNull();
// getter
assertThat(JavaModelUtil.getAnnotations(inheritedField)).containsKey("com_devonfw_cobigen_javaplugin_unittest_inputreader_testdata_MySuperTypeGetterAnnotation");
// Setter
assertThat(JavaModelUtil.getAnnotations(inheritedField)).containsKey("com_devonfw_cobigen_javaplugin_unittest_inputreader_testdata_MySuperTypeSetterAnnotation");
// is-method
assertThat(JavaModelUtil.getAnnotations(inheritedField)).containsKey("com_devonfw_cobigen_javaplugin_unittest_inputreader_testdata_MySuperTypeIsAnnotation");
// attribute
assertThat(JavaModelUtil.getAnnotations(inheritedField)).containsKey("com_devonfw_cobigen_javaplugin_unittest_inputreader_testdata_MySuperTypeFieldAnnotation");
}
use of com.devonfw.cobigen.javaplugin.inputreader.JavaInputReader in project cobigen by devonfw.
the class ParsedJavaModelBuilderTest method testCorrectlyExtractedImplementedTypes.
/**
* Tests whether super types (extended Type and implemented Types) will be extracted correctly to the model
*
* @throws Exception test fails
*/
@Test
public void testCorrectlyExtractedImplementedTypes() throws Exception {
File classFile = new File(testFileRootPath + "TestClass.java");
JavaInputReader javaModelBuilder = new JavaInputReader();
try (FileReader fileReader = new FileReader(classFile)) {
Map<String, Object> model = javaModelBuilder.createModel(JavaParserUtil.getFirstJavaClass(fileReader));
// check whether implemented Types (interfaces) meet expectations
List<Map<String, Object>> interfaces = JavaModelUtil.getImplementedTypes(model);
// interface1
assertThat(interfaces.get(0).get(ModelConstant.NAME)).isEqualTo("TestInterface1");
assertThat(interfaces.get(0).get(ModelConstant.CANONICAL_NAME)).isEqualTo("com.devonfw.cobigen.javaplugin.unittest.inputreader.testdata.TestInterface1");
assertThat(interfaces.get(0).get(ModelConstant.PACKAGE)).isEqualTo("com.devonfw.cobigen.javaplugin.unittest.inputreader.testdata");
// interface2
assertThat(interfaces.get(1).get(ModelConstant.NAME)).isEqualTo("TestInterface2");
assertThat(interfaces.get(1).get(ModelConstant.CANONICAL_NAME)).isEqualTo("com.devonfw.cobigen.javaplugin.unittest.inputreader.testdata.TestInterface2");
assertThat(interfaces.get(1).get(ModelConstant.PACKAGE)).isEqualTo("com.devonfw.cobigen.javaplugin.unittest.inputreader.testdata");
}
}
use of com.devonfw.cobigen.javaplugin.inputreader.JavaInputReader in project cobigen by devonfw.
the class ParsedJavaModelBuilderTest method testExtractionOfMethodAccessibleFields_inherited.
/**
* Tests whether the input type's extracted fields are complete (including annotations and javaDoc)
*
* @throws Exception test fails
*/
@Test
@Ignore("see com.devonfw.cobigen.javaplugin.inputreader.ParsedJavaModelBuilder.extractMethodAccessibleFields#L115")
public void testExtractionOfMethodAccessibleFields_inherited() throws Exception {
File file = new File(testFileRootPath + "TestClass.java");
JavaInputReader javaModelBuilder = new JavaInputReader();
try (FileReader fileReader = new FileReader(file)) {
Map<String, Object> model = javaModelBuilder.createModel(JavaParserUtil.getFirstJavaClass(fileReader));
// test inherited field of direct superclass named "id"
Map<String, Object> inheritedField = JavaModelUtil.getMethodAccessibleField(model, "id");
assertThat(inheritedField).isNotNull();
assertThat(inheritedField.get(ModelConstant.NAME)).isEqualTo("id");
assertThat(inheritedField.get(ModelConstant.TYPE)).isEqualTo("Long");
assertThat(inheritedField.get(ModelConstant.CANONICAL_TYPE)).isEqualTo("java.lang.Long");
}
// is deprecated, so its not necessary to test here
// assertThat(inheritedField.get("isId")).isEqualTo("false");
// currently no javadoc provided
// assertThat(inheritedField.get(ModelConstant.JAVADOC)).isNotNull();
// assertThat(JavaModelUtil.getJavaDocModel(inheritedField).get("comment")).isEqualTo("Example
// JavaDoc");
// TODO Currently qDox library does not return the superclass' annotations
/*
* // test annotations for attribute, getter, setter, is-method
* assertThat(inheritedField.get(ModelConstant.ANNOTATIONS)).isNotNull(); // getter
* assertTrue(JavaModelUtil.getAnnotations (inheritedField).containsKey("MySuperTypeGetterAnnotation")); // Setter
* assertTrue(JavaModelUtil.getAnnotations (inheritedField).containsKey("MySuperTypeSetterAnnotation")); //
* is-method assertThat(JavaModelUtil.getAnnotations(inheritedField).containsKey("MySuperTypeIsAnnotation")).
* isTrue(); // attribute
* assertThat(JavaModelUtil.getAnnotations(inheritedField).containsKey("MySuperTypeFieldAnnotation")). isTrue();
*/
}
use of com.devonfw.cobigen.javaplugin.inputreader.JavaInputReader in project cobigen by devonfw.
the class ParsedJavaModelBuilderTest method testCorrectlyExtractedInheritedType.
/**
* Tests whether the inherited type will be correctly extracted and put into the model
*
* @throws Exception test fails
*/
@Test
public void testCorrectlyExtractedInheritedType() throws Exception {
File classFile = new File(testFileRootPath + "TestClass.java");
JavaInputReader javaModelBuilder = new JavaInputReader();
try (FileReader fileReader = new FileReader(classFile)) {
Map<String, Object> model = javaModelBuilder.createModel(JavaParserUtil.getFirstJavaClass(fileReader));
Assert.assertEquals("AbstractTestClass", JavaModelUtil.getExtendedType(model).get(ModelConstant.NAME));
assertThat(JavaModelUtil.getExtendedType(model).get(ModelConstant.CANONICAL_NAME)).isEqualTo("com.devonfw.cobigen.javaplugin.unittest.inputreader.testdata.AbstractTestClass");
assertThat(JavaModelUtil.getExtendedType(model).get(ModelConstant.PACKAGE)).isEqualTo("com.devonfw.cobigen.javaplugin.unittest.inputreader.testdata");
}
}
Aggregations