Java Code Examples for org.mybatis.generator.api.GeneratedJavaFile

The following examples show how to use org.mybatis.generator.api.GeneratedJavaFile. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Override
public List<GeneratedJavaFile> getGeneratedJavaFiles() {
    List<GeneratedJavaFile> answer = new ArrayList<>();

    for (AbstractJavaGenerator javaGenerator : javaGenerators) {
        List<CompilationUnit> compilationUnits = javaGenerator.getCompilationUnits();
        for (CompilationUnit compilationUnit : compilationUnits) {
            GeneratedJavaFile gjf = new GeneratedJavaFile(compilationUnit,
                            javaGenerator.getProject(),
                            context.getProperty(PropertyRegistry.CONTEXT_JAVA_FILE_ENCODING),
                            context.getJavaFormatter());
            answer.add(gjf);
        }
    }

    return answer;
}
 
Example 2
/**
 * 测试默认配置
 */
@Test
public void testDefault() throws Exception{
    MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/MapperAnnotationPlugin/mybatis-generator.xml");
    MyBatisGenerator myBatisGenerator = tool.generate();

    for (GeneratedJavaFile file : myBatisGenerator.getGeneratedJavaFiles()) {
        CompilationUnit compilationUnit = file.getCompilationUnit();
        if (compilationUnit instanceof Interface && compilationUnit.getType().getShortName().endsWith("Mapper")) {
            Interface interfaze = (Interface) compilationUnit;

            Assert.assertEquals(interfaze.getAnnotations().size(), 1);
            Assert.assertEquals(interfaze.getAnnotations().get(0), "@Mapper");
            Assert.assertTrue(interfaze.getImportedTypes().contains(new FullyQualifiedJavaType("org.apache.ibatis.annotations.Mapper")));
        }
    }
}
 
Example 3
/**
 * 测试配置Repository
 * @throws Exception
 */
@Test
public void testWithRepository() throws Exception{
    MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/MapperAnnotationPlugin/mybatis-generator-with-repository.xml");
    MyBatisGenerator myBatisGenerator = tool.generate();

    for (GeneratedJavaFile file : myBatisGenerator.getGeneratedJavaFiles()) {
        CompilationUnit compilationUnit = file.getCompilationUnit();
        if (compilationUnit instanceof Interface && compilationUnit.getType().getShortName().endsWith("Mapper")) {
            Interface interfaze = (Interface) compilationUnit;

            Assert.assertEquals(interfaze.getAnnotations().size(), 2);
            Assert.assertEquals(interfaze.getAnnotations().get(0), "@Mapper");
            Assert.assertEquals(interfaze.getAnnotations().get(1), "@Repository");
            Assert.assertTrue(interfaze.getImportedTypes().contains(new FullyQualifiedJavaType("org.apache.ibatis.annotations.Mapper")));
            Assert.assertTrue(interfaze.getImportedTypes().contains(new FullyQualifiedJavaType("org.springframework.stereotype.Repository")));
        }
    }
}
 
Example 4
Source Project: mybatis-generator-plugin   Source File: LombokPluginTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 测试具体生成(只有keys的特殊情况,尽量使用Builder)
 */
@Test
public void testGenerateWithOnlyKeys() throws Exception {
    MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/LombokPlugin/mybatis-generator-with-only-keys.xml");
    MyBatisGenerator myBatisGenerator = tool.generate();

    for (GeneratedJavaFile file : myBatisGenerator.getGeneratedJavaFiles()) {
        CompilationUnit compilationUnit = file.getCompilationUnit();
        if (compilationUnit instanceof TopLevelClass) {
            TopLevelClass topLevelClass = (TopLevelClass) compilationUnit;
            String name = topLevelClass.getType().getShortName();
            if (name.equals("TbOnlyKeysKey")){
                Assert.assertTrue(topLevelClass.getAnnotations().contains("@Builder"));
            }
        }
    }
}
 
Example 5
/**
 * 测试配置了模板参数转换
 */
@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);
        }
    }
}
 
Example 6
Source Project: mybatis-generator-plugin   Source File: BugFixedTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 测试domainObjectRenamingRule和
 */
@Test
public void bug0004() throws Exception {
    DBHelper.createDB("scripts/BugFixedTest/bug-0004.sql");
    // 规则 ^T 替换成空,也就是去掉前缀
    MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/BugFixedTest/bug-0004.xml");
    MyBatisGenerator myBatisGenerator = tool.generate();
    for (GeneratedJavaFile file : myBatisGenerator.getGeneratedJavaFiles()) {
        String name = file.getCompilationUnit().getType().getShortName();
        if (!name.matches("B.*")) {
            Assert.assertTrue(false);
        }
        if (name.endsWith("Example")) {
            Assert.assertEquals(file.getCompilationUnit().getType().getPackageName(), "com.itfsw.dao.example");
        }
    }
}
 
Example 7
Source Project: mapper-generator-javafx   Source File: PluginAggregator.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public List<GeneratedJavaFile> contextGenerateAdditionalJavaFiles(
        IntrospectedTable introspectedTable) {
    List<GeneratedJavaFile> answer = new ArrayList<>();
    for (Plugin plugin : plugins) {
        List<GeneratedJavaFile> temp = plugin
                .contextGenerateAdditionalJavaFiles(introspectedTable);
        if (temp != null) {
            answer.addAll(temp);
        }
    }
    return answer;
}
 
Example 8
Source Project: mapper-generator-javafx   Source File: PluginAggregator.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public List<GeneratedJavaFile> contextGenerateAdditionalJavaFiles() {
    List<GeneratedJavaFile> answer = new ArrayList<>();
    for (Plugin plugin : plugins) {
        List<GeneratedJavaFile> temp = plugin.contextGenerateAdditionalJavaFiles();
        if (temp != null) {
            answer.addAll(temp);
        }
    }
    return answer;
}
 
Example 9
Source Project: mapper-generator-javafx   Source File: Context.java    License: Apache License 2.0 5 votes vote down vote up
public void generateFiles(ProgressCallback callback,
        List<GeneratedJavaFile> generatedJavaFiles,
        List<GeneratedXmlFile> generatedXmlFiles, List<String> warnings)
        throws InterruptedException {

    pluginAggregator = new PluginAggregator();
    for (PluginConfiguration pluginConfiguration : pluginConfigurations) {
        Plugin plugin = ObjectFactory.createPlugin(this, pluginConfiguration);
        if (plugin.validate(warnings)) {
            pluginAggregator.addPlugin(plugin);
        } else {
            warnings.add(getString("Warning.24",
                    pluginConfiguration.getConfigurationType(), id));
        }
    }

    if (introspectedTables != null) {
        for (IntrospectedTable introspectedTable : introspectedTables) {
            callback.checkCancel();

            introspectedTable.initialize();
            introspectedTable.calculateGenerators(warnings, callback);
            generatedJavaFiles.addAll(introspectedTable.getGeneratedJavaFiles());
            generatedXmlFiles.addAll(introspectedTable.getGeneratedXmlFiles());

            generatedJavaFiles.addAll(pluginAggregator.contextGenerateAdditionalJavaFiles(introspectedTable));
            generatedXmlFiles.addAll(pluginAggregator.contextGenerateAdditionalXmlFiles(introspectedTable));
        }
    }

    generatedJavaFiles.addAll(pluginAggregator.contextGenerateAdditionalJavaFiles());
    generatedXmlFiles.addAll(pluginAggregator.contextGenerateAdditionalXmlFiles());
}
 
Example 10
Source Project: mybatis-generator-plugin   Source File: LombokPluginTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 测试具体生成
 */
@Test
public void testGenerateDefault() throws Exception {
    MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/LombokPlugin/mybatis-generator-default.xml");
    MyBatisGenerator myBatisGenerator = tool.generate();

    List<String> comm = Arrays.asList("@Data");
    List<String> child = new ArrayList<>(Arrays.asList("@EqualsAndHashCode(callSuper = true)", "@ToString(callSuper = true)"));
    child.addAll(comm);

    for (GeneratedJavaFile file : myBatisGenerator.getGeneratedJavaFiles()) {
        CompilationUnit compilationUnit = file.getCompilationUnit();
        if (compilationUnit instanceof TopLevelClass) {
            TopLevelClass topLevelClass = (TopLevelClass) compilationUnit;
            String name = topLevelClass.getType().getShortName();
            if ("TbKeyBlobKey".equals(name)) {
                Assert.assertEquals(comm.size(), topLevelClass.getAnnotations().size());
                Assert.assertTrue(comm.containsAll(topLevelClass.getAnnotations()));
            } else if ("TbKeyBlobWithBLOBs".equals(name)) {
                Assert.assertEquals(child.size(), topLevelClass.getAnnotations().size());
                Assert.assertTrue(child.containsAll(topLevelClass.getAnnotations()));
            }

            // tb 没有继承
            if ("Tb".equals(name)) {
                Assert.assertEquals(comm.size(), topLevelClass.getAnnotations().size());
                Assert.assertTrue(comm.containsAll(topLevelClass.getAnnotations()));
            }
        }
    }
}
 
Example 11
/**
 * 测试具体生成
 */
@Test
public void testGenerate() throws IOException, XMLParserException, InvalidConfigurationException, InterruptedException, SQLException {
    // 全局规则增加 DB, tb2 单独规则增加Tt
    MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/TablePrefixPlugin/mybatis-generator.xml");
    MyBatisGenerator myBatisGenerator = tool.generate();
    for (GeneratedJavaFile file : myBatisGenerator.getGeneratedJavaFiles()){
        String name = file.getCompilationUnit().getType().getShortName();
        if (name.matches(".*1.*")){
            Assert.assertTrue(name.matches("DB.*"));
        } else {
            Assert.assertTrue(name.matches("Tt.*"));
        }
    }
}
 
Example 12
/**
 * 测试配置了模板参数转换
 */
@Test
public void testGenerateWithTemplate() throws Exception {
    MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/CommentPlugin/mybatis-generator.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().get(0), "TestAddJavaFileComment:Tb:" + new SimpleDateFormat("yyyy-MM").format(new Date()));
            // addFieldComment 同时测试 if 判断和 mbg
            Field id = topLevelClass.getFields().get(0);
            Assert.assertEquals(id.getJavaDocLines().get(0), "注释1");
            Assert.assertEquals(id.getJavaDocLines().get(1), MergeConstants.NEW_ELEMENT_TAG);
            // addGeneralMethodComment
            Method cons = topLevelClass.getMethods().get(0);
            Assert.assertEquals(cons.getJavaDocLines().get(0), "addGeneralMethodComment:Tb:tb");
            // addSetterComment
            Method setter = topLevelClass.getMethods().get(5);
            Assert.assertEquals(setter.getJavaDocLines().get(0), "addSetterComment:field1:field1");
        }
    }

    // xml注释
    ObjectUtil xml = new ObjectUtil(myBatisGenerator.getGeneratedXmlFiles().get(0));
    Document doc = (Document) xml.get("document");
    List<Element> els = ((XmlElement) (doc.getRootElement().getElements().get(0))).getElements();
    String comment = ((TextElement) els.get(0)).getContent();
    Assert.assertEquals(comment, "addComment:BaseResultMap");
}
 
Example 13
@Test
public void testNormalPath() throws Exception {
    MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/ExampleTargetPlugin/mybatis-generator-without-plugin.xml");
    MyBatisGenerator myBatisGenerator = tool.generate();

    List<GeneratedJavaFile> list = myBatisGenerator.getGeneratedJavaFiles();
    for (GeneratedJavaFile file : list){
        if (file.getFileName().equals("TbExample.java")){
            Assert.assertEquals(file.getTargetPackage(), tool.getTargetPackage());
        }
    }
}
 
Example 14
@Test
public void testConfigPath() throws Exception {
    MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/ExampleTargetPlugin/mybatis-generator.xml");
    MyBatisGenerator myBatisGenerator = tool.generate();

    List<GeneratedJavaFile> list = myBatisGenerator.getGeneratedJavaFiles();
    for (GeneratedJavaFile file : list){
        if (file.getFileName().equals("TbExample.java")){
            Assert.assertEquals(file.getTargetPackage(), "com.itfsw.mybatis.generator.plugins.dao.example");
        }
    }
}
 
Example 15
/**
 * 测试具体生成
 */
@Test
public void testGenerate() throws IOException, XMLParserException, InvalidConfigurationException, InterruptedException, SQLException {
    // 规则1 ^T 替换成 Test, 同时tb2 使用了tableOverride 替换成 TestOverride
    MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/TableRenamePlugin/mybatis-generator-rule1.xml");
    MyBatisGenerator myBatisGenerator = tool.generate();
    for (GeneratedJavaFile file : myBatisGenerator.getGeneratedJavaFiles()){
        String name = file.getCompilationUnit().getType().getShortName();
        if (name.matches(".*1.*")){
            Assert.assertTrue(name.matches("Testb1.*"));
        } else {
            Assert.assertTrue(name.matches("TestOverride.*"));
        }
    }
}
 
Example 16
/**
 * 测试替代 TablePrefixPlugin 插件
 */
@Test
public void testGenerateLikeTablePrefixPlugin() throws IOException, XMLParserException, InvalidConfigurationException, InterruptedException, SQLException {
    MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/TableRenamePlugin/mybatis-generator-like-TablePrefixPlugin.xml");
    MyBatisGenerator myBatisGenerator = tool.generate();
    for (GeneratedJavaFile file : myBatisGenerator.getGeneratedJavaFiles()){
        String name = file.getCompilationUnit().getType().getShortName();
        Assert.assertTrue(name.matches("DB1.*"));
    }
}
 
Example 17
/**
 * 测试exampleSuffix
 */
@Test
public void testExampleSuffix() throws Exception {
    MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/TableRenameConfigurationPlugin/mybatis-generator-with-exampleSuffix.xml");
    MyBatisGenerator myBatisGenerator = tool.generate();

    boolean find = false;
    for (GeneratedJavaFile file : myBatisGenerator.getGeneratedJavaFiles()) {
        String name = file.getCompilationUnit().getType().getShortName();
        if (name.equals("TbQuery")){
            find = true;
        }
    }
    Assert.assertTrue(find);
    // 执行一条语句确认其可用
    tool.generate(() -> DBHelper.resetDB("scripts/TableRenameConfigurationPlugin/init.sql"), new AbstractShellCallback() {
        @Override
        public void reloadProject(SqlSession sqlSession, ClassLoader loader, String packagz) throws Exception {
            ObjectUtil tbMapper = new ObjectUtil(sqlSession.getMapper(loader.loadClass(packagz + ".TbMapper")));

            ObjectUtil tbQuery = new ObjectUtil(loader, packagz + ".TbQuery");
            ObjectUtil criteria = new ObjectUtil(tbQuery.invoke("createCriteria"));
            criteria.invoke("andIdLessThan", 4L);

            // sql
            String sql = SqlHelper.getFormatMapperSql(tbMapper.getObject(), "selectByExample", tbQuery.getObject());
            Assert.assertEquals(sql, "select id, field1, inc_f1, inc_f2, inc_f3 from tb WHERE ( id < '4' )");
            // 执行
            List list = (List) tbMapper.invoke("selectByExample", tbQuery.getObject());
            Assert.assertEquals(list.size(), 3);
        }
    });
}
 
Example 18
Source Project: mybatis-generator-plugin   Source File: BugFixedTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 表重命名配置插件生成的大小写错误
 * @throws Exception
 */
@Test
public void issues63() throws Exception {
    MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/BugFixedTest/issues-63.xml");
    MyBatisGenerator generator = tool.generate(() -> DBHelper.createDB("scripts/BugFixedTest/issues-63.sql"));
    for (GeneratedJavaFile file : generator.getGeneratedJavaFiles()) {
        String fileName = file.getFileName();
        if (fileName.startsWith("Repaydetail")) {
            Assert.assertTrue("官方自己的问题", true);
        }
    }
}
 
Example 19
Source Project: mybatis-generator-plugin   Source File: BugFixedTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 测试批量batchUpsert存在主键的情况
 * https://github.com/itfsw/mybatis-generator-plugin/issues/77
 * @throws Exception
 */
@Test
public void issues81() throws Exception {
    MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/BugFixedTest/issues-81.xml");
    MyBatisGenerator myBatisGenerator = tool.generate(() -> DBHelper.createDB("scripts/BugFixedTest/issues-81.sql"));

    // 是否在使用系统默认模板
    int count = 0;
    for (GeneratedJavaFile file : myBatisGenerator.getGeneratedJavaFiles()) {
        if (file.getFormattedContent().indexOf(MergeConstants.NEW_ELEMENT_TAG) != -1) {
            count++;
        }
    }
    Assert.assertTrue(count == 0);
}
 
Example 20
public List<GeneratedJavaFile> contextGenerateAdditionalJavaFiles(
        IntrospectedTable introspectedTable) {
    List<GeneratedJavaFile> answer = new ArrayList<GeneratedJavaFile>();
    for (Plugin plugin : plugins) {
        List<GeneratedJavaFile> temp = plugin
                .contextGenerateAdditionalJavaFiles(introspectedTable);
        if (temp != null) {
            answer.addAll(temp);
        }
    }
    return answer;
}
 
Example 21
public List<GeneratedJavaFile> contextGenerateAdditionalJavaFiles() {
    List<GeneratedJavaFile> answer = new ArrayList<GeneratedJavaFile>();
    for (Plugin plugin : plugins) {
        List<GeneratedJavaFile> temp = plugin
                .contextGenerateAdditionalJavaFiles();
        if (temp != null) {
            answer.addAll(temp);
        }
    }
    return answer;
}
 
Example 22
Source Project: mybatis-generator-plus   Source File: PluginAggregator.java    License: Apache License 2.0 5 votes vote down vote up
public List<GeneratedJavaFile> contextGenerateAdditionalJavaFiles(IntrospectedTable introspectedTable) {
	List<GeneratedJavaFile> answer = new ArrayList<GeneratedJavaFile>();
	for (Plugin plugin : plugins) {
		List<GeneratedJavaFile> temp = plugin.contextGenerateAdditionalJavaFiles(introspectedTable);
		if (temp != null) {
			answer.addAll(temp);
		}
	}
	return answer;
}
 
Example 23
Source Project: mybatis-generator-plus   Source File: PluginAggregator.java    License: Apache License 2.0 5 votes vote down vote up
public List<GeneratedJavaFile> contextGenerateAdditionalJavaFiles() {
	List<GeneratedJavaFile> answer = new ArrayList<GeneratedJavaFile>();
	for (Plugin plugin : plugins) {
		List<GeneratedJavaFile> temp = plugin.contextGenerateAdditionalJavaFiles();
		if (temp != null) {
			answer.addAll(temp);
		}
	}
	return answer;
}
 
Example 24
Source Project: mybatis-generator-plus   Source File: Context.java    License: Apache License 2.0 5 votes vote down vote up
public void generateFiles(ProgressCallback callback, List<GeneratedJavaFile> generatedJavaFiles, List<GeneratedXmlFile> generatedXmlFiles, List<String> warnings) throws InterruptedException {

		pluginAggregator = new PluginAggregator();
		for (PluginConfiguration pluginConfiguration : pluginConfigurations) {
			Plugin plugin = ObjectFactory.createPlugin(this, pluginConfiguration);
			if (plugin.validate(warnings)) {
				pluginAggregator.addPlugin(plugin);
			}
			else {
				warnings.add(getString("Warning.24", //$NON-NLS-1$
						pluginConfiguration.getConfigurationType(), id));
			}
		}

		if (introspectedTables != null) {
			for (IntrospectedTable introspectedTable : introspectedTables) {
				callback.checkCancel();

				introspectedTable.initialize();
				introspectedTable.calculateGenerators(warnings, callback);
				generatedJavaFiles.addAll(introspectedTable.getGeneratedJavaFiles());
				generatedXmlFiles.addAll(introspectedTable.getGeneratedXmlFiles());

				generatedJavaFiles.addAll(pluginAggregator.contextGenerateAdditionalJavaFiles(introspectedTable));
				generatedXmlFiles.addAll(pluginAggregator.contextGenerateAdditionalXmlFiles(introspectedTable));
			}
		}

		generatedJavaFiles.addAll(pluginAggregator.contextGenerateAdditionalJavaFiles());
		generatedXmlFiles.addAll(pluginAggregator.contextGenerateAdditionalXmlFiles());


		//每个表自定义包路径
		setJavaFilesCustomTargetPackage(generatedJavaFiles);
		setXmlFilesCustomTargetPackage(generatedJavaFiles);
	}
 
Example 25
@Override
public List<GeneratedJavaFile> contextGenerateAdditionalJavaFiles() {
	List<GeneratedJavaFile> models = new ArrayList<>();

	GeneratedJavaFile genericInterfaceFile =
			new GeneratedJavaFile(genericInterface, context.getJavaClientGeneratorConfiguration().getTargetProject(), new DefaultJavaFormatter());

	models.add(genericInterfaceFile);

	return models;
}
 
Example 26
@Override
public List<GeneratedJavaFile> contextGenerateAdditionalJavaFiles(IntrospectedTable introspectedTable) {
	List<GeneratedJavaFile> models = new ArrayList<>();

	CompilationUnit unit = DynamicSqlSupportClassGenerator
			.of(introspectedTable, context.getCommentGenerator(), tableClassSuffix, addAliasedColumns, addTableAlias, tableAliasFieldName, properties)
			.generate();

	GeneratedJavaFile dynamicSqlModel =
			new GeneratedJavaFile(unit, context.getJavaClientGeneratorConfiguration().getTargetProject(), new DefaultJavaFormatter());

	models.add(dynamicSqlModel);

	return models;
}
 
Example 27
@Test
public void shouldGenerateAdditionalFile() throws Exception {
	// Given

	// When
	List<GeneratedJavaFile> files = plugin.contextGenerateAdditionalJavaFiles();

	// Then
	then(files).hasSize(1);
}
 
Example 28
@Test
public void shouldGenerateAdditionalFile() throws Exception {
	// Given

	// When
	List<GeneratedJavaFile> files = plugin.contextGenerateAdditionalJavaFiles(table);

	// Then
	then(files).hasSize(1);
}
 
Example 29
@Test
public void shouldGenerateAdditionalFileEvenWhenTableHasNoColumns() throws Exception {
	// Given
	given(table.getAllColumns()).willReturn(new ArrayList<IntrospectedColumn>());

	// When
	List<GeneratedJavaFile> files = plugin.contextGenerateAdditionalJavaFiles(table);

	// Then
	then(files).hasSize(1);
}
 
Example 30
Source Project: Mapper   Source File: TemplateFilePlugin.java    License: MIT License 5 votes vote down vote up
@Override
public List<GeneratedJavaFile> contextGenerateAdditionalJavaFiles(IntrospectedTable introspectedTable) {
    List<GeneratedJavaFile> list = new ArrayList<GeneratedJavaFile>();
    TableClass tableClass = TableColumnBuilder.build(introspectedTable);
    if ("TRUE".equalsIgnoreCase(singleMode)) {
        list.add(new GenerateByTemplateFile(tableClass, (TemplateFormatter) templateFormatter, properties, targetProject, targetPackage, fileName, templateContent));
    } else {
        cacheTables.add(tableClass);
    }
    return list;
}