use of com.devonfw.cobigen.javaplugin.merger.JavaMerger in project cobigen by devonfw.
the class JavaPluginActivator method bindMerger.
@Override
public List<Merger> bindMerger() {
List<Merger> merger = Lists.newLinkedList();
merger.add(new JavaMerger(JAVAMERGE, false));
merger.add(new JavaMerger(JAVAMERGE_OVERRIDE, true));
return merger;
}
use of com.devonfw.cobigen.javaplugin.merger.JavaMerger in project cobigen by devonfw.
the class JavaMergerTest method testBaseLineEndings.
/**
* Tests whether the output file contains line endings of base file (linux line endings)
*
* @throws IOException test fails
* @throws MergeException test fails
*/
@Test
public void testBaseLineEndings() throws IOException, MergeException {
File baseFile = new File(testFileRootPath + "BaseFile_Eol.java");
File patchFile = new File(testFileRootPath + "PatchFile_Eol.java");
File mergedFile = new File(testFileRootPath + "MergedFile_Eol.java");
String expectedContent = FileUtils.readFileToString(mergedFile, StandardCharsets.UTF_8);
String mergedContents = new JavaMerger("", false).merge(baseFile, FileUtils.readFileToString(patchFile, StandardCharsets.UTF_8), "UTF-8");
assertThat(mergedContents).isEqualTo(expectedContent);
}
use of com.devonfw.cobigen.javaplugin.merger.JavaMerger in project cobigen by devonfw.
the class JavaMergerTest method testMergeMethodsWithoutExtendingMethodBodyWithWhitespaces.
/**
* Tests merging java without adding new lines to method bodies (was a bug)
*
* @throws IOException test fails
* @throws MergeException test fails
*/
@Test
public void testMergeMethodsWithoutExtendingMethodBodyWithWhitespaces() throws IOException, MergeException {
File file = new File(testFileRootPath + "PatchFile_method.java");
ClassLibraryBuilder classLibraryBuilder = new ModifyableClassLibraryBuilder();
try (FileInputStream fileInputStream = new FileInputStream(file)) {
JavaSource source = classLibraryBuilder.addSource(fileInputStream);
JavaClass origClazz = source.getClasses().get(0);
String mergedContents = new JavaMerger("", true).merge(file, FileUtils.readFileToString(file, Charset.forName("UTF-8")), "UTF-8");
classLibraryBuilder = new ModifyableClassLibraryBuilder();
try (StringReader stringReader = new StringReader(mergedContents)) {
source = classLibraryBuilder.addSource(stringReader);
JavaClass resultClazz = source.getClasses().get(0);
for (JavaMethod method : resultClazz.getMethods()) {
JavaMethod origMethod = origClazz.getMethodBySignature(method.getName(), method.getParameterTypes());
assertThat(method.getCodeBlock()).isEqualTo(origMethod.getCodeBlock());
}
}
}
}
use of com.devonfw.cobigen.javaplugin.merger.JavaMerger in project cobigen by devonfw.
the class JavaMergerTest method testMergeWithGenerics.
/**
* Tests whether all generics of the original file will be existent after merging
*
* @throws IOException test fails
* @throws MergeException test fails
* @author mbrunnli (17.06.2013)
*/
@Test
public void testMergeWithGenerics() throws IOException, MergeException {
File baseFile = new File(testFileRootPath + "BaseFile_generics.java");
File patchFile = new File(testFileRootPath + "PatchFile_generics.java");
String mergedContents = new JavaMerger("", false).merge(baseFile, FileUtils.readFileToString(patchFile, StandardCharsets.UTF_8), "UTF-8");
assertThat(mergedContents).contains("class Clazz<T extends Object>");
assertThat(mergedContents).contains("Map<String,T>");
assertThat(mergedContents).contains("private T t;");
assertThat(mergedContents).contains("public T get()");
assertThat(mergedContents).contains("public <U extends Number> void inspect(U u)");
}
use of com.devonfw.cobigen.javaplugin.merger.JavaMerger in project cobigen by devonfw.
the class JavaMergerTest method testMergeInterfacesWithoutSuperClass.
/**
* Tests whether two interfaces without a super class are getting merged
* https://github.com/devonfw/cobigen/issues/1439
*
* @throws IOException shouldn't happen
* @throws MergeException shouldn't happen either
*/
@Test
public void testMergeInterfacesWithoutSuperClass() throws IOException, MergeException {
File baseFile = new File(testFileRootPath + "BaseFile_InterfaceWOSuperClass.java");
File patchFile = new File(testFileRootPath + "PatchFile_InterfaceWOSuperClass.java");
String mergedContents = new JavaMerger("", true).merge(baseFile, FileUtils.readFileToString(patchFile, StandardCharsets.UTF_8), "UTF-8");
assertThat(mergedContents).contains("public void testMethod();");
assertThat(mergedContents).contains("public void anotherTestMethod();");
}
Aggregations