ScmPomVersionsMergeClient implements MergeClient { @Override public void merge(InputStream local, InputStream remote, InputStream base, OutputStream result) throws ScmException { Optional<Model> localModel = loadModel(local); if (!localModel.isPresent()) { throw new ScmException(ScmOperation.MERGE, "Unable to merge non-POM changes."); } byte[] remoteData = null; try { remoteData = ByteStreams.toByteArray(remote); } catch (IOException e) { throw new ScmException(ScmOperation.MERGE, "Unable to read remote content!", e); } finally { Closeables.closeQuietly(remote); } Optional<Model> remoteModel = loadModel(new ByteArrayInputStream(remoteData)); Optional<Model> baseModel = loadModel(base); Model resultModel = loadModel(new ByteArrayInputStream(remoteData)).get(); mergeVersions(localModel.get(), remoteModel.get(), baseModel.get(), resultModel); mergeParentVersions(localModel.get(), remoteModel.get(), baseModel.get(), resultModel); try { Document document = PomUtil.parsePOM(new ByteArrayInputStream(remoteData)); PomUtil.setProjectVersion(resultModel, document, resultModel.getVersion()); if (resultModel.getParent() != null) { PomUtil.setParentVersion(resultModel, document, resultModel.getParent().getVersion()); } PomUtil.writePOM(document, result, false); } catch (Throwable t) { throw new ScmException(ScmOperation.MERGE, "Could not serialize merged POM!", t); } }  @Override void merge(InputStream local, InputStream remote, InputStream base, OutputStream result);  }
@Test @UseDataProvider("merge") public void testMerge(InputStream local, InputStream remote, InputStream base, InputStream expected) throws IOException { MergeClient mergeClient = new ScmPomVersionsMergeClient(); ByteArrayOutputStream os = new ByteArrayOutputStream(); try { mergeClient.merge(local, remote, base, os); String resultPOM = os.toString(StandardCharsets.UTF_8.name()); String expectedPOM = new String(ByteStreams.toByteArray(expected), StandardCharsets.UTF_8); Assert.assertEquals(expectedPOM.replaceAll("\\s+", ""), resultPOM.replaceAll("\\s+", "")); } finally { Closeables.closeQuietly(local); Closeables.closeQuietly(remote); Closeables.closeQuietly(base); Closeables.close(os, true); } }