From 5c5c7765b86cd757729a9449a00a252986865847 Mon Sep 17 00:00:00 2001 From: hewei Date: Thu, 10 Jan 2019 10:40:27 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0CommentPlugin=E7=9A=84?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../generator/plugins/CommentPluginTest.java | 33 ++++++++++- .../{ComentPlugin => CommentPlugin}/init.sql | 0 .../mybatis-generator-without-comment.xml | 57 +++++++++++++++++++ .../mybatis-generator-without-template.xml | 0 .../mybatis-generator.xml | 2 +- .../test-comment.ftl | 0 6 files changed, 88 insertions(+), 4 deletions(-) rename src/test/resources/scripts/{ComentPlugin => CommentPlugin}/init.sql (100%) create mode 100644 src/test/resources/scripts/CommentPlugin/mybatis-generator-without-comment.xml rename src/test/resources/scripts/{ComentPlugin => CommentPlugin}/mybatis-generator-without-template.xml (100%) rename src/test/resources/scripts/{ComentPlugin => CommentPlugin}/mybatis-generator.xml (98%) rename src/test/resources/scripts/{ComentPlugin => CommentPlugin}/test-comment.ftl (100%) diff --git a/src/test/java/com/itfsw/mybatis/generator/plugins/CommentPluginTest.java b/src/test/java/com/itfsw/mybatis/generator/plugins/CommentPluginTest.java index 2630ef4..f971192 100644 --- a/src/test/java/com/itfsw/mybatis/generator/plugins/CommentPluginTest.java +++ b/src/test/java/com/itfsw/mybatis/generator/plugins/CommentPluginTest.java @@ -51,7 +51,7 @@ public class CommentPluginTest { */ @BeforeClass public static void init() throws Exception { - DBHelper.createDB("scripts/ComentPlugin/init.sql"); + DBHelper.createDB("scripts/CommentPlugin/init.sql"); } /** @@ -59,7 +59,7 @@ public class CommentPluginTest { */ @Test public void testGenerateWithoutTemplate() throws Exception { - MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/ComentPlugin/mybatis-generator-without-template.xml"); + MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/CommentPlugin/mybatis-generator-without-template.xml"); MyBatisGenerator myBatisGenerator = tool.generate(); // 是否在使用系统默认模板 int count = 0; @@ -76,7 +76,7 @@ public class CommentPluginTest { */ @Test public void testGenerateWithTemplate() throws Exception { - MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/ComentPlugin/mybatis-generator.xml"); + MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/CommentPlugin/mybatis-generator.xml"); MyBatisGenerator myBatisGenerator = tool.generate(); // java中的注释 @@ -105,4 +105,31 @@ public class CommentPluginTest { String comment = ((TextElement) els.get(0)).getContent(); Assert.assertEquals(comment, "addComment:BaseResultMap"); } + + /** + * 测试配置了模板参数转换 + */ + @Test + public void testGenerateWithOutComment() throws Exception { + MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/CommentPlugin/mybatis-generator-without-comment.xml"); + MyBatisGenerator myBatisGenerator = tool.generate(); + + // java中的注释 + for (GeneratedJavaFile file : myBatisGenerator.getGeneratedJavaFiles()) { + if (file.getFileName().equals("Tb.java")) { + TopLevelClass topLevelClass = (TopLevelClass) file.getCompilationUnit(); + // addJavaFileComment + Assert.assertEquals(topLevelClass.getFileCommentLines().size(), 0); + // addFieldComment + Field id = topLevelClass.getFields().get(0); + Assert.assertEquals(id.getJavaDocLines().size(), 0); + // addGeneralMethodComment + Method cons = topLevelClass.getMethods().get(0); + Assert.assertEquals(cons.getJavaDocLines().size(), 0); + // addSetterComment + Method setter = topLevelClass.getMethods().get(5); + Assert.assertEquals(setter.getJavaDocLines().size(), 0); + } + } + } } diff --git a/src/test/resources/scripts/ComentPlugin/init.sql b/src/test/resources/scripts/CommentPlugin/init.sql similarity index 100% rename from src/test/resources/scripts/ComentPlugin/init.sql rename to src/test/resources/scripts/CommentPlugin/init.sql diff --git a/src/test/resources/scripts/CommentPlugin/mybatis-generator-without-comment.xml b/src/test/resources/scripts/CommentPlugin/mybatis-generator-without-comment.xml new file mode 100644 index 0000000..e1a92b9 --- /dev/null +++ b/src/test/resources/scripts/CommentPlugin/mybatis-generator-without-comment.xml @@ -0,0 +1,57 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
\ No newline at end of file diff --git a/src/test/resources/scripts/ComentPlugin/mybatis-generator-without-template.xml b/src/test/resources/scripts/CommentPlugin/mybatis-generator-without-template.xml similarity index 100% rename from src/test/resources/scripts/ComentPlugin/mybatis-generator-without-template.xml rename to src/test/resources/scripts/CommentPlugin/mybatis-generator-without-template.xml diff --git a/src/test/resources/scripts/ComentPlugin/mybatis-generator.xml b/src/test/resources/scripts/CommentPlugin/mybatis-generator.xml similarity index 98% rename from src/test/resources/scripts/ComentPlugin/mybatis-generator.xml rename to src/test/resources/scripts/CommentPlugin/mybatis-generator.xml index ff8dc38..ebfd248 100644 --- a/src/test/resources/scripts/ComentPlugin/mybatis-generator.xml +++ b/src/test/resources/scripts/CommentPlugin/mybatis-generator.xml @@ -26,7 +26,7 @@ - + diff --git a/src/test/resources/scripts/ComentPlugin/test-comment.ftl b/src/test/resources/scripts/CommentPlugin/test-comment.ftl similarity index 100% rename from src/test/resources/scripts/ComentPlugin/test-comment.ftl rename to src/test/resources/scripts/CommentPlugin/test-comment.ftl