use of com.devonfw.cobigen.javaplugin.merger.JavaMerger in project cobigen by devonfw.
the class JavaMergerTest method testConsistentLineEndings.
/**
* Tests whether the output file does not contain different line endings
*
* @throws IOException test fails
* @throws MergeException test fails
* @author mbrunnli (04.06.2013)
*/
@Test
public void testConsistentLineEndings() throws IOException, MergeException {
File baseFile = new File(testFileRootPath + "BaseFile_innerClass.java");
File patchFile = new File(testFileRootPath + "PatchFile_innerClass.java");
String mergedContents = new JavaMerger("", false).merge(baseFile, FileUtils.readFileToString(patchFile, StandardCharsets.UTF_8), "UTF-8");
boolean eol1 = mergedContents.contains("\r\n");
mergedContents = mergedContents.replaceAll("\r\n", "");
boolean eol2 = mergedContents.contains("\n");
boolean eol3 = mergedContents.contains("\r");
assertThat(eol1 ^ eol2 ^ eol3).isTrue();
}
use of com.devonfw.cobigen.javaplugin.merger.JavaMerger in project cobigen by devonfw.
the class JavaMergerTest method testMergeInheritanceRelation.
/**
* Tests issue <a href=https://github.com/devonfw/cobigen/issues/39>#39</a>: inheritance relation should be merged
* also if the base class (natively) extends java.lang.Object
*
* @throws IOException test fails
* @throws MergeException test fails
* @author mbrunnli (29.09.2014)
*/
@Test
public void testMergeInheritanceRelation() throws IOException, MergeException {
File baseFile = new File(testFileRootPath + "BaseFile_inheritance.java");
File patchFile = new File(testFileRootPath + "PatchFile_inheritance.java");
try (FileReader fileReader = new FileReader(baseFile)) {
JavaClass origClazz = getFirstJavaClass(fileReader);
assertThat(origClazz.getSuperClass().getCanonicalName()).isEqualTo("java.lang.Object");
}
String mergedContents = new JavaMerger("", false).merge(baseFile, FileUtils.readFileToString(patchFile, Charset.forName("UTF-8")), "UTF-8");
try (StringReader stringReader = new StringReader(mergedContents)) {
JavaClass resultClazz = getFirstJavaClass(stringReader);
assertThat(resultClazz.getSuperClass().getCanonicalName()).as("The merged result does not contain the expected inheritance relation 'extends HashMap<String,Long>'").isEqualTo("java.util.HashMap");
assertThat(resultClazz.getSuperClass().getGenericValue()).as("The merged result does not contain the original inheritance declaration'extends HashMap<String,Long>'").isEqualTo("HashMap<String,Long>");
}
}
use of com.devonfw.cobigen.javaplugin.merger.JavaMerger in project cobigen by devonfw.
the class JavaMergerTest method testReadingEncoding.
/**
* Tests whether the contents will be rewritten after parsing and printing with QDox with the right encoding
*
* @throws IOException test fails
* @throws MergeException test fails
* @author mbrunnli (12.04.2013)
*/
@Test
public void testReadingEncoding() throws IOException, MergeException {
File baseFile = new File(testFileRootPath + "BaseFile_encoding_UTF-8.java");
File patchFile = new File(testFileRootPath + "PatchFile_encoding.java");
String mergedContents = new JavaMerger("", false).merge(baseFile, FileUtils.readFileToString(patchFile, StandardCharsets.UTF_8), "UTF-8");
JavaSource mergedSource;
try (StringReader stringReader = new StringReader(mergedContents)) {
mergedSource = getFirstJavaClass(stringReader).getSource();
assertThat(mergedSource.toString().contains("enthält")).isTrue();
}
baseFile = new File(testFileRootPath + "BaseFile_encoding_ISO-8859-1.java");
mergedContents = new JavaMerger("", false).merge(baseFile, FileUtils.readFileToString(patchFile, StandardCharsets.ISO_8859_1), "ISO-8859-1");
try (StringReader stringReader = new StringReader(mergedContents)) {
mergedSource = getFirstJavaClass(stringReader).getSource();
assertThat(mergedSource.toString()).contains("enthält");
}
}
use of com.devonfw.cobigen.javaplugin.merger.JavaMerger in project cobigen by devonfw.
the class JavaMergerTest method testMergePropertyAnnotation.
/**
* Tests merging a property annotation into the baseFile
*
* @throws IOException shouldn't happen
* @throws MergeException shouldn't happen either
*/
@Test
public void testMergePropertyAnnotation() throws IOException, MergeException {
File baseFile = new File(testFileRootPath + "BaseFile_PropertyAnnotation.java");
File patchFile = new File(testFileRootPath + "PatchFile_PropertyAnnotation.java");
// with override
String mergedContents = new JavaMerger("", false).merge(baseFile, FileUtils.readFileToString(patchFile, StandardCharsets.UTF_8), "UTF-8");
assertThat(mergedContents).contains("@Column(name=\"USER\")");
assertThat(mergedContents).contains("@Column(name=\"NAME\")");
// without override
mergedContents = new JavaMerger("", true).merge(baseFile, FileUtils.readFileToString(patchFile, StandardCharsets.UTF_8), "UTF-8");
assertThat(mergedContents).contains("@Column(name= \"USERNAME\")");
assertThat(mergedContents).contains("@Column(name=\"NAME\")");
}
use of com.devonfw.cobigen.javaplugin.merger.JavaMerger in project cobigen by devonfw.
the class JavaMergerTest method testMergeMethodAnnotation.
/**
* Tests merging a Method annotation into the baseFile
*
* @throws IOException shouldn't happen
* @throws MergeException shouldn't happen either
*/
@Test
public void testMergeMethodAnnotation() throws IOException, MergeException {
File baseFile = new File(testFileRootPath + "BaseFile_MethodAnnotation.java");
File patchFile = new File(testFileRootPath + "PatchFile_MethodAnnotation.java");
// with override
String mergedContents = new JavaMerger("", true).merge(baseFile, FileUtils.readFileToString(patchFile, StandardCharsets.UTF_8), "UTF-8");
assertThat(mergedContents).contains("@Column(name=\"USERNAME\")");
assertThat(mergedContents).contains("@Column(name=\"USER\")");
// without override
mergedContents = new JavaMerger("", false).merge(baseFile, FileUtils.readFileToString(patchFile, StandardCharsets.UTF_8), "UTF-8");
assertThat(mergedContents).contains("@Column(name=\"NAME\")");
assertThat(mergedContents).contains("@Column(name=\"USER\")");
}
Aggregations