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  import java.io.File;
22  import java.io.IOException;
23  import java.util.HashSet;
24  import java.util.Set;
25  
26  import junit.framework.TestCase;
27  import org.apache.commons.io.FileUtils;
28  import org.apache.maven.artifact.Artifact;
29  import org.apache.maven.plugin.MojoExecutionException;
30  import org.apache.maven.plugin.logging.Log;
31  import org.apache.maven.plugin.testing.SilentLog;
32  import org.apache.maven.plugins.dependency.testUtils.DependencyArtifactStubFactory;
33  import org.apache.maven.plugins.dependency.utils.markers.SourcesFileMarkerHandler;
34  import org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException;
35  
36  /**
37   * @author brianf
38   */
39  public class TestResolveMarkerFileFilter extends TestCase {
40      Set<Artifact> artifacts = new HashSet<>();
41  
42      Log log = new SilentLog();
43  
44      File outputFolder;
45  
46      DependencyArtifactStubFactory fact;
47  
48      protected void setUp() throws Exception {
49          super.setUp();
50  
51          outputFolder = new File("target/markers/");
52          FileUtils.deleteDirectory(outputFolder);
53          assertFalse(outputFolder.exists());
54  
55          this.fact = new DependencyArtifactStubFactory(outputFolder, false);
56          artifacts = fact.getReleaseAndSnapshotArtifacts();
57      }
58  
59      protected void tearDown() throws IOException {
60          FileUtils.deleteDirectory(outputFolder);
61      }
62  
63      public void testResolveFile() throws IOException, ArtifactFilterException, MojoExecutionException {
64          SourcesFileMarkerHandler handler = new SourcesFileMarkerHandler(outputFolder);
65  
66          Artifact artifact = fact.getReleaseArtifact();
67          handler.setArtifact(artifact);
68  
69          ResolveFileFilter filter = new ResolveFileFilter(handler);
70  
71          assertTrue(filter.isArtifactIncluded(artifact));
72          handler.setMarker();
73          assertFalse(filter.isArtifactIncluded(artifact));
74      }
75  }