Search in sources :

Example 1 with CompilationUnitSummary

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);
}
Also used : InputStream(java.io.InputStream) CompilationUnitSummary(org.mybatis.generator.eclipse.tests.harness.summary.CompilationUnitSummary) ClassSummary(org.mybatis.generator.eclipse.tests.harness.summary.ClassSummary) Test(org.junit.Test)

Example 2 with CompilationUnitSummary

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);
}
Also used : InputStream(java.io.InputStream) CompilationUnitSummary(org.mybatis.generator.eclipse.tests.harness.summary.CompilationUnitSummary) AnnotationSummary(org.mybatis.generator.eclipse.tests.harness.summary.AnnotationSummary) Test(org.junit.Test)

Example 3 with CompilationUnitSummary

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)")));
}
Also used : InputStream(java.io.InputStream) CompilationUnitSummary(org.mybatis.generator.eclipse.tests.harness.summary.CompilationUnitSummary) Test(org.junit.Test)

Example 4 with CompilationUnitSummary

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)));
}
Also used : CompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit) InputStream(java.io.InputStream) TextEdit(org.eclipse.text.edits.TextEdit) CompilationUnitSummary(org.mybatis.generator.eclipse.tests.harness.summary.CompilationUnitSummary) Utilities.getResourceAsString(org.mybatis.generator.eclipse.tests.harness.Utilities.getResourceAsString) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) ExistingJavaFileVisitor(org.mybatis.generator.eclipse.core.merge.ExistingJavaFileVisitor) IDocument(org.eclipse.jface.text.IDocument) Test(org.junit.Test)

Example 5 with CompilationUnitSummary

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")));
}
Also used : CompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit) InputStream(java.io.InputStream) TextEdit(org.eclipse.text.edits.TextEdit) CompilationUnitSummary(org.mybatis.generator.eclipse.tests.harness.summary.CompilationUnitSummary) Utilities.getResourceAsString(org.mybatis.generator.eclipse.tests.harness.Utilities.getResourceAsString) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) ExistingJavaFileVisitor(org.mybatis.generator.eclipse.core.merge.ExistingJavaFileVisitor) IDocument(org.eclipse.jface.text.IDocument) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)10 CompilationUnitSummary (org.mybatis.generator.eclipse.tests.harness.summary.CompilationUnitSummary)10 InputStream (java.io.InputStream)8 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)3 Document (org.eclipse.jface.text.Document)3 IDocument (org.eclipse.jface.text.IDocument)3 TextEdit (org.eclipse.text.edits.TextEdit)3 ExistingJavaFileVisitor (org.mybatis.generator.eclipse.core.merge.ExistingJavaFileVisitor)3 Utilities.getResourceAsString (org.mybatis.generator.eclipse.tests.harness.Utilities.getResourceAsString)3 JavaFileMerger (org.mybatis.generator.eclipse.core.merge.JavaFileMerger)2 AnnotationSummary (org.mybatis.generator.eclipse.tests.harness.summary.AnnotationSummary)1 ClassSummary (org.mybatis.generator.eclipse.tests.harness.summary.ClassSummary)1 EnumSummary (org.mybatis.generator.eclipse.tests.harness.summary.EnumSummary)1 InterfaceSummary (org.mybatis.generator.eclipse.tests.harness.summary.InterfaceSummary)1