Search in sources :

Example 11 with JavaMerger

use of com.devonfw.cobigen.javaplugin.merger.JavaMerger in project cobigen by devonfw.

the class JavaMergerTest method testMergeClassAnnotation.

/**
 * Tests merging the class annotation into the baseFile
 *
 * @throws IOException shouldn't happen
 * @throws MergeException shouldn't happen either
 */
@Test
public void testMergeClassAnnotation() throws IOException, MergeException {
    File baseFile = new File(testFileRootPath + "BaseFile_ClassAnnotation.java");
    File patchFile = new File(testFileRootPath + "PatchFile_ClassAnnotation.java");
    // with override
    String mergedContents = new JavaMerger("", true).merge(baseFile, FileUtils.readFileToString(patchFile, StandardCharsets.UTF_8), "UTF-8");
    assertThat(mergedContents).contains("@Entity");
    assertThat(mergedContents).contains("@javax.persistence.Table(name=\"Visitor\")");
    // without override
    mergedContents = new JavaMerger("", false).merge(baseFile, FileUtils.readFileToString(patchFile, StandardCharsets.UTF_8), "UTF-8");
    assertThat(mergedContents).contains("@Entity");
    assertThat(mergedContents).contains("@javax.persistence.Table(name=\"Visits\")");
}
Also used : JavaMerger(com.devonfw.cobigen.javaplugin.merger.JavaMerger) File(java.io.File) Test(org.junit.Test)

Aggregations

JavaMerger (com.devonfw.cobigen.javaplugin.merger.JavaMerger)11 File (java.io.File)10 Test (org.junit.Test)10 StringReader (java.io.StringReader)3 JavaParserUtil.getFirstJavaClass (com.devonfw.cobigen.javaplugin.inputreader.JavaParserUtil.getFirstJavaClass)2 JavaClass (com.thoughtworks.qdox.model.JavaClass)2 JavaSource (com.thoughtworks.qdox.model.JavaSource)2 Merger (com.devonfw.cobigen.api.extension.Merger)1 ModifyableClassLibraryBuilder (com.devonfw.cobigen.javaplugin.merger.libextension.ModifyableClassLibraryBuilder)1 ClassLibraryBuilder (com.thoughtworks.qdox.library.ClassLibraryBuilder)1 JavaMethod (com.thoughtworks.qdox.model.JavaMethod)1 FileInputStream (java.io.FileInputStream)1 FileReader (java.io.FileReader)1