View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.plugins.dependency.utils.filters;
20  
21  /**
22   *
23   */
24  import java.io.File;
25  import java.io.IOException;
26  import java.util.HashSet;
27  import java.util.Set;
28  
29  import junit.framework.TestCase;
30  import org.apache.commons.io.FileUtils;
31  import org.apache.maven.artifact.Artifact;
32  import org.apache.maven.plugin.MojoExecutionException;
33  import org.apache.maven.plugin.logging.Log;
34  import org.apache.maven.plugin.testing.SilentLog;
35  import org.apache.maven.plugins.dependency.testUtils.DependencyArtifactStubFactory;
36  import org.apache.maven.plugins.dependency.utils.markers.SourcesFileMarkerHandler;
37  import org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException;
38  
39  /**
40   * @author brianf
41   */
42  public class TestResolveMarkerFileFilter extends TestCase {
43      Set<Artifact> artifacts = new HashSet<>();
44  
45      Log log = new SilentLog();
46  
47      File outputFolder;
48  
49      DependencyArtifactStubFactory fact;
50  
51      protected void setUp() throws Exception {
52          super.setUp();
53  
54          outputFolder = new File("target/markers/");
55          FileUtils.deleteDirectory(outputFolder);
56          assertFalse(outputFolder.exists());
57  
58          this.fact = new DependencyArtifactStubFactory(outputFolder, false);
59          artifacts = fact.getReleaseAndSnapshotArtifacts();
60      }
61  
62      protected void tearDown() throws IOException {
63          FileUtils.deleteDirectory(outputFolder);
64      }
65  
66      public void testResolveFile() throws IOException, ArtifactFilterException, MojoExecutionException {
67          SourcesFileMarkerHandler handler = new SourcesFileMarkerHandler(outputFolder);
68  
69          Artifact artifact = fact.getReleaseArtifact();
70          handler.setArtifact(artifact);
71  
72          ResolveFileFilter filter = new ResolveFileFilter(handler);
73  
74          assertTrue(filter.isArtifactIncluded(artifact));
75          handler.setMarker();
76          assertFalse(filter.isArtifactIncluded(artifact));
77      }
78  }