package de.unistuttgart.iste.rss.bugminer.build.maven;

import junit.framework.TestCase;
import org.apache.commons.io.IOUtils;
import org.hamcrest.Matchers;

import static com.jcabi.matchers.RegexMatchers.*;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertThat;

public class PomPatcherTest extends TestCase {

	public void testAddCoveragePerTestProfile() throws Exception {
		String source = IOUtils.toString(PomPatcherTest.class.getResourceAsStream("pom.xml"));
		PomPatcher patcher = new PomPatcher();
		String result = patcher.addCoveragePerTestProfile(source);
		assertThat(result, containsPattern("<profiles>\\s*<profile>\\s*<id>coverage-per-test</id>"));
	}

	public void testAddCoveragePerTestProfileWhenProfilesAlreadyExists() throws Exception {
		String source = IOUtils.toString(PomPatcherTest.class.getResourceAsStream("pom-with-profile.xml"));
		PomPatcher patcher = new PomPatcher();
		String result = patcher.addCoveragePerTestProfile(source);
		assertThat(result, containsPattern(".*</profile>\\s*<profile>\\s*<id>coverage-per-test</id>.*"));
	}
}

@@ -648,32 +648,41 @@
 profile%3E%5C%5Cs*%3Cid%3E
+bugminer-
 coverage-per-tes
@@ -671,31 +671,30 @@
 r-coverage-p
-er-test
+rofile
 %3C/id%3E%22));%0A%09%7D
@@ -1059,16 +1059,25 @@
 %5C%5Cs*%3Cid%3E
+bugminer-
 coverage
@@ -1082,15 +1082,14 @@
 ge-p
-er-test
+rofile
 %3C/id

Fix PomPatcherTest