This is an automated email from the ASF dual-hosted git repository.

rfscholte pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-dependency-plugin.git

commit b489c8a4ba121ecc72a78eec9afcbfea6c0ba882
Author: Maarten Mulders <maart...@infosupport.com>
AuthorDate: Mon Sep 2 21:26:38 2019 +0200

    Add unit test for the ExcludeReactorProjectsArtifactFilter
---
 .../maven/plugins/dependency/CapturingLog.java     | 179 +++++++++++++++++++++
 .../apache/maven/plugins/dependency/TestSkip.java  | 156 ------------------
 .../ExcludeReactorProjectsArtifactFilterTest.java  |  88 ++++++++++
 3 files changed, 267 insertions(+), 156 deletions(-)

diff --git 
a/src/test/java/org/apache/maven/plugins/dependency/CapturingLog.java 
b/src/test/java/org/apache/maven/plugins/dependency/CapturingLog.java
new file mode 100644
index 0000000..089fa69
--- /dev/null
+++ b/src/test/java/org/apache/maven/plugins/dependency/CapturingLog.java
@@ -0,0 +1,179 @@
+package org.apache.maven.plugins.dependency;
+
+import org.apache.maven.plugin.logging.Log;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/** Helper to do assertions on what is being logged. */
+public class CapturingLog
+    implements Log
+{
+    StringBuilder sb = new StringBuilder();
+
+    /** {@inheritDoc} */
+    public void debug( CharSequence content )
+    {
+        print( "debug", content );
+    }
+
+    /** {@inheritDoc} */
+    public void debug( CharSequence content, Throwable error )
+    {
+        print( "debug", content, error );
+    }
+
+    /** {@inheritDoc} */
+    public void debug( Throwable error )
+    {
+        print( "debug", error );
+    }
+
+    /** {@inheritDoc} */
+    public void info( CharSequence content )
+    {
+        print( "info", content );
+    }
+
+    /** {@inheritDoc} */
+    public void info( CharSequence content, Throwable error )
+    {
+        print( "info", content, error );
+    }
+
+    /** {@inheritDoc} */
+    public void info( Throwable error )
+    {
+        print( "info", error );
+    }
+
+    /** {@inheritDoc} */
+    public void warn( CharSequence content )
+    {
+        print( "warn", content );
+    }
+
+    /** {@inheritDoc} */
+    public void warn( CharSequence content, Throwable error )
+    {
+        print( "warn", content, error );
+    }
+
+    /** {@inheritDoc} */
+    public void warn( Throwable error )
+    {
+        print( "warn", error );
+    }
+
+    /** {@inheritDoc} */
+    public void error( CharSequence content )
+    {
+        System.err.println( "[error] " + content.toString() );
+    }
+
+    /** {@inheritDoc} */
+    public void error( CharSequence content, Throwable error )
+    {
+        StringWriter sWriter = new StringWriter();
+        PrintWriter pWriter = new PrintWriter( sWriter );
+
+        error.printStackTrace( pWriter );
+
+        System.err.println( "[error] " + content.toString() + 
System.lineSeparator() + System.lineSeparator() + sWriter.toString() );
+    }
+
+    /**
+     * @see Log#error(Throwable)
+     */
+    public void error( Throwable error )
+    {
+        StringWriter sWriter = new StringWriter();
+        PrintWriter pWriter = new PrintWriter( sWriter );
+
+        error.printStackTrace( pWriter );
+
+        System.err.println( "[error] " + sWriter.toString() );
+    }
+
+    /**
+     * @see Log#isDebugEnabled()
+     */
+    public boolean isDebugEnabled()
+    {
+        // TODO: Not sure how best to set these for this implementation...
+        return true;
+    }
+
+    /**
+     * @see Log#isInfoEnabled()
+     */
+    public boolean isInfoEnabled()
+    {
+        return true;
+    }
+
+    /**
+     * @see Log#isWarnEnabled()
+     */
+    public boolean isWarnEnabled()
+    {
+        return true;
+    }
+
+    /**
+     * @see Log#isErrorEnabled()
+     */
+    public boolean isErrorEnabled()
+    {
+        return true;
+    }
+
+    private void print( String prefix, CharSequence content )
+    {
+        sb.append( "[" ).append( prefix ).append( "] " ).append( 
content.toString() ).append( System.lineSeparator() );
+    }
+
+    private void print( String prefix, Throwable error )
+    {
+        StringWriter sWriter = new StringWriter();
+        PrintWriter pWriter = new PrintWriter( sWriter );
+
+        error.printStackTrace( pWriter );
+
+        sb.append( "[" ).append( prefix ).append( "] " ).append( 
sWriter.toString() ).append( System.lineSeparator() );
+    }
+
+    private void print( String prefix, CharSequence content, Throwable error )
+    {
+        StringWriter sWriter = new StringWriter();
+        PrintWriter pWriter = new PrintWriter( sWriter );
+
+        error.printStackTrace( pWriter );
+
+        sb.append( "[" ).append( prefix ).append( "] " ).append( 
content.toString() ).append( System.lineSeparator() ).append( 
System.lineSeparator() ).append( sWriter.toString() ).append( 
System.lineSeparator() );
+    }
+
+    public String getContent()
+    {
+        return sb.toString();
+    }
+}
diff --git a/src/test/java/org/apache/maven/plugins/dependency/TestSkip.java 
b/src/test/java/org/apache/maven/plugins/dependency/TestSkip.java
index 932c9da..54e3d3d 100644
--- a/src/test/java/org/apache/maven/plugins/dependency/TestSkip.java
+++ b/src/test/java/org/apache/maven/plugins/dependency/TestSkip.java
@@ -1,11 +1,8 @@
 package org.apache.maven.plugins.dependency;
 
 import org.apache.maven.plugin.Mojo;
-import org.apache.maven.plugin.logging.Log;
 
 import java.io.File;
-import java.io.PrintWriter;
-import java.io.StringWriter;
 
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
@@ -168,157 +165,4 @@ public class TestSkip
         assertTrue( log.getContent().contains( "Skipping plugin execution" ) );
     }
 
-    class CapturingLog
-        implements Log
-    {
-        StringBuilder sb = new StringBuilder();
-
-        /** {@inheritDoc} */
-        public void debug( CharSequence content )
-        {
-            print( "debug", content );
-        }
-
-        /** {@inheritDoc} */
-        public void debug( CharSequence content, Throwable error )
-        {
-            print( "debug", content, error );
-        }
-
-        /** {@inheritDoc} */
-        public void debug( Throwable error )
-        {
-            print( "debug", error );
-        }
-
-        /** {@inheritDoc} */
-        public void info( CharSequence content )
-        {
-            print( "info", content );
-        }
-
-        /** {@inheritDoc} */
-        public void info( CharSequence content, Throwable error )
-        {
-            print( "info", content, error );
-        }
-
-        /** {@inheritDoc} */
-        public void info( Throwable error )
-        {
-            print( "info", error );
-        }
-
-        /** {@inheritDoc} */
-        public void warn( CharSequence content )
-        {
-            print( "warn", content );
-        }
-
-        /** {@inheritDoc} */
-        public void warn( CharSequence content, Throwable error )
-        {
-            print( "warn", content, error );
-        }
-
-        /** {@inheritDoc} */
-        public void warn( Throwable error )
-        {
-            print( "warn", error );
-        }
-
-        /** {@inheritDoc} */
-        public void error( CharSequence content )
-        {
-            System.err.println( "[error] " + content.toString() );
-        }
-
-        /** {@inheritDoc} */
-        public void error( CharSequence content, Throwable error )
-        {
-            StringWriter sWriter = new StringWriter();
-            PrintWriter pWriter = new PrintWriter( sWriter );
-
-            error.printStackTrace( pWriter );
-
-            System.err.println( "[error] " + content.toString() + 
System.lineSeparator() + System.lineSeparator() + sWriter.toString() );
-        }
-
-        /**
-         * @see org.apache.maven.plugin.logging.Log#error(java.lang.Throwable)
-         */
-        public void error( Throwable error )
-        {
-            StringWriter sWriter = new StringWriter();
-            PrintWriter pWriter = new PrintWriter( sWriter );
-
-            error.printStackTrace( pWriter );
-
-            System.err.println( "[error] " + sWriter.toString() );
-        }
-
-        /**
-         * @see org.apache.maven.plugin.logging.Log#isDebugEnabled()
-         */
-        public boolean isDebugEnabled()
-        {
-            // TODO: Not sure how best to set these for this implementation...
-            return false;
-        }
-
-        /**
-         * @see org.apache.maven.plugin.logging.Log#isInfoEnabled()
-         */
-        public boolean isInfoEnabled()
-        {
-            return true;
-        }
-
-        /**
-         * @see org.apache.maven.plugin.logging.Log#isWarnEnabled()
-         */
-        public boolean isWarnEnabled()
-        {
-            return true;
-        }
-
-        /**
-         * @see org.apache.maven.plugin.logging.Log#isErrorEnabled()
-         */
-        public boolean isErrorEnabled()
-        {
-            return true;
-        }
-
-        private void print( String prefix, CharSequence content )
-        {
-            sb.append( "[" ).append( prefix ).append( "] " ).append( 
content.toString() ).append( System.lineSeparator() );
-        }
-
-        private void print( String prefix, Throwable error )
-        {
-            StringWriter sWriter = new StringWriter();
-            PrintWriter pWriter = new PrintWriter( sWriter );
-
-            error.printStackTrace( pWriter );
-
-            sb.append( "[" ).append( prefix ).append( "] " ).append( 
sWriter.toString() ).append( System.lineSeparator() );
-        }
-
-        private void print( String prefix, CharSequence content, Throwable 
error )
-        {
-            StringWriter sWriter = new StringWriter();
-            PrintWriter pWriter = new PrintWriter( sWriter );
-
-            error.printStackTrace( pWriter );
-
-            sb.append( "[" ).append( prefix ).append( "] " ).append( 
content.toString() ).append( System.lineSeparator() ).append( 
System.lineSeparator() ).append( sWriter.toString() ).append( 
System.lineSeparator() );
-        }
-
-        protected String getContent()
-        {
-            return sb.toString();
-        }
-    }
-
 }
diff --git 
a/src/test/java/org/apache/maven/plugins/dependency/resolvers/ExcludeReactorProjectsArtifactFilterTest.java
 
b/src/test/java/org/apache/maven/plugins/dependency/resolvers/ExcludeReactorProjectsArtifactFilterTest.java
new file mode 100644
index 0000000..65b35f6
--- /dev/null
+++ 
b/src/test/java/org/apache/maven/plugins/dependency/resolvers/ExcludeReactorProjectsArtifactFilterTest.java
@@ -0,0 +1,88 @@
+package org.apache.maven.plugins.dependency.resolvers;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.plugin.testing.stubs.ArtifactStub;
+import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
+import org.apache.maven.plugins.dependency.AbstractDependencyMojoTestCase;
+import org.apache.maven.plugins.dependency.CapturingLog;
+import org.apache.maven.project.MavenProject;
+import 
org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import static java.util.Collections.singleton;
+import static java.util.Collections.singletonList;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+public class ExcludeReactorProjectsArtifactFilterTest
+        extends AbstractDependencyMojoTestCase
+{
+
+    public void testFilter()
+            throws ArtifactFilterException
+    {
+        Artifact artifact1 = new ArtifactStub();
+        artifact1.setGroupId("org.apache.maven.plugins");
+        artifact1.setArtifactId("maven-dependency-plugin-dummy");
+        artifact1.setVersion("1.0");
+
+        Artifact artifact2 = new ArtifactStub();
+        artifact2.setGroupId("org.apache.maven.plugins");
+        artifact2.setArtifactId("maven-dependency-plugin-other-dummy");
+        artifact2.setVersion("1.0");
+
+        Set<Artifact> artifacts = new HashSet<>();
+        artifacts.add( artifact1 );
+        artifacts.add( artifact2 );
+
+        CapturingLog log = new CapturingLog();
+        MavenProject project = new MavenProjectStub();
+        project.setArtifact(artifact1);
+
+        ExcludeReactorProjectsArtifactFilter filter = new 
ExcludeReactorProjectsArtifactFilter(
+                singletonList( project ), log );
+
+        Set<Artifact> result = filter.filter( artifacts );
+
+        assertEquals( 1, result.size() );
+    }
+
+    public void testFilterWithLogging()
+            throws ArtifactFilterException
+    {
+        Artifact artifact = new ArtifactStub();
+        artifact.setGroupId("org.apache.maven.plugins");
+        artifact.setArtifactId("maven-dependency-plugin-dummy");
+        artifact.setVersion("1.0");
+
+        CapturingLog log = new CapturingLog();
+        MavenProject project = new MavenProjectStub();
+        project.setArtifact(artifact);
+
+        ExcludeReactorProjectsArtifactFilter filter = new 
ExcludeReactorProjectsArtifactFilter(
+                singletonList( project ), log );
+
+        filter.filter( singleton( artifact ) );
+
+        assertTrue( log.getContent().contains( "Skipped artifact" ) );
+    }
+}

Reply via email to