use of org.mybatis.generator.eclipse.tests.harness.summary.CompilationUnitSummary in project generator by mybatis.
the class SummarizerTest method testClassSummarizer.
@Test
public void testClassSummarizer() throws IOException {
InputStream resource = getClass().getResourceAsStream("/org/mybatis/generator/eclipse/tests/harness/tests/resources/OuterClass.src");
CompilationUnitSummary cuSummary = getCompilationUnitSummaryFromResource(resource);
assertThat(cuSummary, hasImportCount(2));
assertThat(cuSummary, hasImport(IMPORT_JAVA_IO_SERIALIZABLE));
assertThat(cuSummary, hasImport("import java.util.ArrayList"));
assertThat(cuSummary, hasClassCount(2));
assertThat(cuSummary, hasClass("SecondOuterClass"));
assertThat(cuSummary, hasClass("OuterClass"));
assertThat(cuSummary, hasEnumCount(0));
assertThat(cuSummary, hasInterfaceCount(0));
ClassSummary classSummary = cuSummary.getClassSummary("OuterClass");
assertThat(classSummary, hasSuperClass("ArrayList<String>"));
assertThat(classSummary, hasSuperInterface(SERIALIZABLE));
assertThat(classSummary, hasSuperInterfaceCount(1));
assertThat(classSummary, hasField("serialVersionUID", withFieldType("long")));
assertThat(classSummary, hasField("unreliableCount"));
assertThat(classSummary, hasFieldCount(2));
assertThat(classSummary, hasMethod("add(String)"));
assertThat(classSummary, hasMethod("getUnreliableCount()"));
assertThat(classSummary, hasMethodCount(2));
verifyInners(classSummary);
}
use of org.mybatis.generator.eclipse.tests.harness.summary.CompilationUnitSummary in project generator by mybatis.
the class SummarizerTest method testAnnotationSummarizer.
@Test
public void testAnnotationSummarizer() throws IOException {
InputStream resource = getClass().getResourceAsStream("/org/mybatis/generator/eclipse/tests/harness/tests/resources/OuterAnnotation.src");
CompilationUnitSummary cuSummary = getCompilationUnitSummaryFromResource(resource);
assertThat(cuSummary, hasImportCount(4));
assertThat(cuSummary, hasImport("import java.lang.annotation.ElementType"));
assertThat(cuSummary, hasImport("import java.lang.annotation.Retention"));
assertThat(cuSummary, hasImport("import java.lang.annotation.RetentionPolicy"));
assertThat(cuSummary, hasImport("import java.lang.annotation.Target"));
assertThat(cuSummary, hasAnnotationCount(2));
assertThat(cuSummary, hasAnnotation("OuterAnnotation"));
assertThat(cuSummary, hasAnnotation("SecondOuterAnnotation"));
assertThat(cuSummary, hasClassCount(0));
assertThat(cuSummary, hasEnumCount(0));
assertThat(cuSummary, hasInterfaceCount(0));
AnnotationSummary annotationSummary = cuSummary.getAnnotationSummary("OuterAnnotation");
assertThat(annotationSummary, hasAnnotationMember("name"));
assertThat(annotationSummary, hasAnnotationMemberCount(1));
assertThat(annotationSummary, hasField("id", ofType("int")));
assertThat(annotationSummary, hasField("id2", ofType("int")));
assertThat(annotationSummary, hasField("name", ofType("int")));
assertThat(annotationSummary, hasFieldCount(3));
verifyInners(annotationSummary);
}
use of org.mybatis.generator.eclipse.tests.harness.summary.CompilationUnitSummary in project generator by mybatis.
the class SummarizerTortureTest method testDifficultMethodsAndFields.
@Test
public void testDifficultMethodsAndFields() throws IOException {
InputStream resource = getClass().getResourceAsStream("/org/mybatis/generator/eclipse/tests/harness/tests/resources/StringifierExercizer.java.src");
CompilationUnitSummary summary = getCompilationUnitSummaryFromResource(resource);
assertThat(summary, hasImportCount(6));
assertThat(summary, hasImport("import static org.junit.Assert.*"));
assertThat(summary, hasImport("import static org.hamcrest.core.IsNot.not"));
assertThat(summary, hasImport("import java.io.Closeable"));
assertThat(summary, hasImport("import java.io.IOException"));
assertThat(summary, hasImport("import java.util.*"));
assertThat(summary, hasImport("import java.math.BigDecimal"));
assertThat(summary, hasClass(CLASS_NAME, withFieldCount(3)));
assertThat(summary, hasClass(CLASS_NAME, withField("primitive1", ofType("int"))));
assertThat(summary, hasClass(CLASS_NAME, withField("decimalArray1", ofType("java.math.BigDecimal[]"))));
assertThat(summary, hasClass(CLASS_NAME, withField("integerArray2", ofType("java.math.BigInteger[][]"))));
assertThat(summary, hasClass(CLASS_NAME, withMethodCount(10)));
assertThat(summary, hasClass(CLASS_NAME, withMethod("emptyMethod()")));
assertThat(summary, hasClass(CLASS_NAME, withMethod("<I extends List<String> & Closeable> intersectionType(I)")));
assertThat(summary, hasClass(CLASS_NAME, withMethod("getPrimitive1()")));
assertThat(summary, hasClass(CLASS_NAME, withMethod("setPrimitive1(int)")));
assertThat(summary, hasClass(CLASS_NAME, withMethod("someMethod(List<Map<Integer,java.lang.String>>,Map<Integer,List<String>>)")));
assertThat(summary, hasClass(CLASS_NAME, withMethod("anotherMethod(String[],String[][])")));
assertThat(summary, hasClass(CLASS_NAME, withMethod("main(String[])")));
assertThat(summary, hasClass(CLASS_NAME, withMethod("method22(List<? extends BigDecimal>)")));
assertThat(summary, hasClass(CLASS_NAME, withMethod("method22(Map<Integer,? super java.math.BigDecimal>)")));
assertThat(summary, hasClass(CLASS_NAME, withMethod("method33(java.lang.String)")));
}
use of org.mybatis.generator.eclipse.tests.harness.summary.CompilationUnitSummary in project generator by mybatis.
the class ExistingJavaFileVisitorTest method testRegularClass.
@Test
public void testRegularClass() throws Exception {
InputStream resource = getClass().getResourceAsStream("/org/mybatis/generator/eclipse/core/tests/merge/resources/AwfulTable.java.src");
String source = getResourceAsString(resource);
IDocument document = new Document(source);
CompilationUnit cu = getCompilationUnitFromSource(source);
cu.recordModifications();
ExistingJavaFileVisitor visitor = new ExistingJavaFileVisitor(MergeConstants.OLD_ELEMENT_TAGS);
// delete all the old generated stuff
cu.accept(visitor);
assertThat(visitor.getTypeDeclaration(), is(notNullValue()));
assertThat(visitor.getTypeDeclaration().isInterface(), is(false));
assertThat(visitor.getTypeDeclaration().getName().getFullyQualifiedName(), is("AwfulTable"));
// generate a new compilation unit that is stripped of old stuff
TextEdit textEdit = cu.rewrite(document, null);
textEdit.apply(document);
CompilationUnitSummary summary = getCompilationUnitSummaryFromSource(document.get());
assertThat(summary, hasImportCount(1));
assertThat(summary, hasClass("AwfulTable", withSuperClass("AwfulTableKey")));
assertThat(summary, hasClass("AwfulTable", withSuperInterfaceCount(0)));
assertThat(summary, hasClass("AwfulTable", withMethodCount(0)));
assertThat(summary, hasClass("AwfulTable", withFieldCount(0)));
}
use of org.mybatis.generator.eclipse.tests.harness.summary.CompilationUnitSummary in project generator by mybatis.
the class ExistingJavaFileVisitorTest method testComplexClass.
@Test
public void testComplexClass() throws Exception {
InputStream resource = getClass().getResourceAsStream("/org/mybatis/generator/eclipse/core/tests/merge/resources/AwfulTableExample.java.src");
String source = getResourceAsString(resource);
IDocument document = new Document(source);
CompilationUnit cu = getCompilationUnitFromSource(source);
cu.recordModifications();
ExistingJavaFileVisitor visitor = new ExistingJavaFileVisitor(MergeConstants.OLD_ELEMENT_TAGS);
// delete all the old generated stuff
cu.accept(visitor);
assertThat(visitor.getTypeDeclaration(), is(notNullValue()));
assertThat(visitor.getTypeDeclaration().isInterface(), is(false));
assertThat(visitor.getTypeDeclaration().getName().getFullyQualifiedName(), is("AwfulTableExample"));
assertThat(visitor.containsInnerClass("Criteria"), is(true));
// generate a new compilation unit that is stripped of old stuff
TextEdit textEdit = cu.rewrite(document, null);
textEdit.apply(document);
CompilationUnitSummary summary = getCompilationUnitSummaryFromSource(document.get());
assertThat(summary, hasImportCount(2));
assertThat(summary, hasClass("AwfulTableExample", withSuperClass(nullValue())));
assertThat(summary, hasClass("AwfulTableExample", withSuperInterfaceCount(0)));
assertThat(summary, hasClass("AwfulTableExample", withMethodCount(0)));
assertThat(summary, hasClass("AwfulTableExample", withFieldCount(0)));
assertThat(summary, hasClass("AwfulTableExample", withClass("Criteria")));
}
Aggregations