use of org.mybatis.generator.eclipse.core.merge.ExistingJavaFileVisitor 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.core.merge.ExistingJavaFileVisitor 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")));
}
use of org.mybatis.generator.eclipse.core.merge.ExistingJavaFileVisitor in project generator by mybatis.
the class ExistingJavaFileVisitorTest method testRegularInterface.
@Test
public void testRegularInterface() throws Exception {
InputStream resource = getClass().getResourceAsStream("/org/mybatis/generator/eclipse/core/tests/merge/resources/AwfulTableMapper.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(true));
assertThat(visitor.getTypeDeclaration().getName().getFullyQualifiedName(), is("AwfulTableMapper"));
// 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(11));
assertThat(summary, hasInterface("AwfulTableMapper"));
assertThat(summary, hasInterface("AwfulTableMapper", withSuperInterfaceCount(0)));
assertThat(summary, hasInterface("AwfulTableMapper", withMethodCount(0)));
assertThat(summary, hasInterface("AwfulTableMapper", withFieldCount(0)));
}
Aggregations