// Path: maven-spy/src/main/java/org/jenkinsci/plugins/pipeline/maven/eventspy/reporter/OutputStreamEventReporter.java
// public class OutputStreamEventReporter implements MavenEventReporter {
// 
//     final PrintWriter out;
//     final XMLWriter xmlWriter;
// 
//     public OutputStreamEventReporter(OutputStream out) {
//         this(new OutputStreamWriter(out, Charset.forName("UTF-8")));
//     }
// 
//     public OutputStreamEventReporter(Writer out) {
//         if (out instanceof PrintWriter) {
//             this.out = (PrintWriter) out;
//         } else {
//             this.out = new PrintWriter(out, true);
//         }
//         this.xmlWriter = new PrettyPrintXMLWriter(out);
//         xmlWriter.startElement("mavenExecution");
// 
//     }
// 
//     @Override
//     public synchronized void print(Object message) {
//         String comment = new Timestamp(System.currentTimeMillis()) + " - " + message;
//         XmlWriterUtil.writeComment(xmlWriter, comment);
//         XmlWriterUtil.writeLineBreak(xmlWriter);
// 
//         out.flush();
//     }
// 
//     @Override
//     public synchronized void print(Xpp3Dom element) {
//         Xpp3DomWriter.write(xmlWriter, element);
//         XmlWriterUtil.writeLineBreak(xmlWriter);
// 
//         out.flush();
//     }
// 
//     @Override
//     public synchronized void close() {
//         xmlWriter.endElement();
//         out.flush();
//     }
// }


import org.apache.maven.model.Model;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import org.hamcrest.Matchers;
import org.jenkinsci.plugins.pipeline.maven.eventspy.reporter.OutputStreamEventReporter;
import org.junit.Test;
import java.io.IOException;
import java.io.InputStream;
import static org.hamcrest.MatcherAssert.assertThat;
package org.jenkinsci.plugins.pipeline.maven.eventspy.handler;




/**
 * @author <a href="mailto:cleclerc@cloudbees.com">Cyrille Le Clerc</a>
 */
public class AbstractMavenEventHandlerTest {

    @Test
    public void test_getMavenFlattenPluginFlattenedPomFilename_nameDefinedAtTheExecutionLevel() throws Exception {
        test_getMavenFlattenPluginFlattenedPomFilename(
                "org/jenkinsci/plugins/pipeline/maven/eventspy/pom-flatten-plugin-flattenedPomFilename.xml",
                "${project.artifactId}-${project.version}.pom");
    }

    @Test
    public void test_getMavenFlattenPluginFlattenedPomFilename_nameDefinedAtThePluginLevel() throws Exception {
        test_getMavenFlattenPluginFlattenedPomFilename(
                "org/jenkinsci/plugins/pipeline/maven/eventspy/pom-flatten-plugin-flattenedPomFilename2.xml",
                "${project.artifactId}-${project.version}.flatten-pom");
    }

    @Test
    public void test_getMavenFlattenPluginFlattenedPomFilename_nameNotDefined() throws Exception {
        test_getMavenFlattenPluginFlattenedPomFilename(
                "org/jenkinsci/plugins/pipeline/maven/eventspy/pom.xml",
                null);
    }

    protected void test_getMavenFlattenPluginFlattenedPomFilename(String pomFile, String expected) throws IOException, XmlPullParserException {
        InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(pomFile);
        Model mavenProjectModel = new MavenXpp3Reader().read(in);

        MavenProject mavenProject = new MavenProject(mavenProjectModel);
// Path: maven-spy/src/main/java/org/jenkinsci/plugins/pipeline/maven/eventspy/reporter/OutputStreamEventReporter.java
// public class OutputStreamEventReporter implements MavenEventReporter {
// 
//     final PrintWriter out;
//     final XMLWriter xmlWriter;
// 
//     public OutputStreamEventReporter(OutputStream out) {
//         this(new OutputStreamWriter(out, Charset.forName("UTF-8")));
//     }
// 
//     public OutputStreamEventReporter(Writer out) {
//         if (out instanceof PrintWriter) {
//             this.out = (PrintWriter) out;
//         } else {
//             this.out = new PrintWriter(out, true);
//         }
//         this.xmlWriter = new PrettyPrintXMLWriter(out);
//         xmlWriter.startElement("mavenExecution");
// 
//     }
// 
//     @Override
//     public synchronized void print(Object message) {
//         String comment = new Timestamp(System.currentTimeMillis()) + " - " + message;
//         XmlWriterUtil.writeComment(xmlWriter, comment);
//         XmlWriterUtil.writeLineBreak(xmlWriter);
// 
//         out.flush();
//     }
// 
//     @Override
//     public synchronized void print(Xpp3Dom element) {
//         Xpp3DomWriter.write(xmlWriter, element);
//         XmlWriterUtil.writeLineBreak(xmlWriter);
// 
//         out.flush();
//     }
// 
//     @Override
//     public synchronized void close() {
//         xmlWriter.endElement();
//         out.flush();
//     }
// }


// Path: maven-spy/src/test/java/org/jenkinsci/plugins/pipeline/maven/eventspy/handler/AbstractMavenEventHandlerTest.java
import org.apache.maven.model.Model;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import org.hamcrest.Matchers;
import org.jenkinsci.plugins.pipeline.maven.eventspy.reporter.OutputStreamEventReporter;
import org.junit.Test;
import java.io.IOException;
import java.io.InputStream;
import static org.hamcrest.MatcherAssert.assertThat;

package org.jenkinsci.plugins.pipeline.maven.eventspy.handler;




/**
 * @author <a href="mailto:cleclerc@cloudbees.com">Cyrille Le Clerc</a>
 */
public class AbstractMavenEventHandlerTest {

    @Test
    public void test_getMavenFlattenPluginFlattenedPomFilename_nameDefinedAtTheExecutionLevel() throws Exception {
        test_getMavenFlattenPluginFlattenedPomFilename(
                "org/jenkinsci/plugins/pipeline/maven/eventspy/pom-flatten-plugin-flattenedPomFilename.xml",
                "${project.artifactId}-${project.version}.pom");
    }

    @Test
    public void test_getMavenFlattenPluginFlattenedPomFilename_nameDefinedAtThePluginLevel() throws Exception {
        test_getMavenFlattenPluginFlattenedPomFilename(
                "org/jenkinsci/plugins/pipeline/maven/eventspy/pom-flatten-plugin-flattenedPomFilename2.xml",
                "${project.artifactId}-${project.version}.flatten-pom");
    }

    @Test
    public void test_getMavenFlattenPluginFlattenedPomFilename_nameNotDefined() throws Exception {
        test_getMavenFlattenPluginFlattenedPomFilename(
                "org/jenkinsci/plugins/pipeline/maven/eventspy/pom.xml",
                null);
    }

    protected void test_getMavenFlattenPluginFlattenedPomFilename(String pomFile, String expected) throws IOException, XmlPullParserException {
        InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(pomFile);
        Model mavenProjectModel = new MavenXpp3Reader().read(in);

        MavenProject mavenProject = new MavenProject(mavenProjectModel);
        AbstractMavenEventHandler mavenEventHandler = new AbstractMavenEventHandler(new OutputStreamEventReporter(System.err)) {