View Javadoc
1   /*
2    * Licensed under the Apache License, Version 2.0 (the "License");
3    * you may not use this file except in compliance with the License.
4    * You may obtain a copy of the License at
5    *
6    * http://www.apache.org/licenses/LICENSE-2.0
7    *
8    * Unless required by applicable law or agreed to in writing, software
9    * distributed under the License is distributed on an "AS IS" BASIS,
10   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11   * See the License for the specific language governing permissions and
12   * limitations under the License.
13   */
14  package org.basepom.mojo.duplicatefinder.artifact;
15  
16  import org.apache.maven.artifact.Artifact;
17  import org.apache.maven.artifact.DefaultArtifact;
18  import org.apache.maven.artifact.handler.ArtifactHandler;
19  import org.apache.maven.artifact.handler.DefaultArtifactHandler;
20  import org.junit.Test;
21  
22  import static org.junit.Assert.assertEquals;
23  
24  public class TestArtifactFileResolver {
25  
26      private final ArtifactHandler handler = new DefaultArtifactHandler();
27  
28      @Test
29      public void testCanonicalization() {
30          final Artifact jarArtifact = new DefaultArtifact("foo.group", "foo-id", "1.0", "compile", "jar", null, handler);
31  
32          assertEquals(jarArtifact, ArtifactFileResolver.canonicalizeArtifact(jarArtifact));
33  
34          final Artifact testJarArtifact = new DefaultArtifact("foo.group", "foo-id", "1.0", "compile", "jar", "tests", handler);
35          assertEquals(testJarArtifact, ArtifactFileResolver.canonicalizeArtifact(testJarArtifact));
36          assertEquals(testJarArtifact,
37                  ArtifactFileResolver.canonicalizeArtifact(new DefaultArtifact("foo.group", "foo-id", "1.0", "compile", "test-jar", null, handler)));
38          assertEquals(testJarArtifact,
39                  ArtifactFileResolver.canonicalizeArtifact(new DefaultArtifact("foo.group", "foo-id", "1.0", "compile", "test-jar", "tests", handler)));
40  
41          final Artifact testArtifact = new DefaultArtifact("foo.group", "foo-id", "1.0", "compile", "zip", "tests", handler);
42          assertEquals(testArtifact, ArtifactFileResolver.canonicalizeArtifact(testArtifact));
43  
44          final Artifact testClassifiedJarArtifact = new DefaultArtifact("foo.group", "foo-id", "1.0", "compile", "test-jar", "special", handler);
45          assertEquals(testClassifiedJarArtifact, ArtifactFileResolver.canonicalizeArtifact(testClassifiedJarArtifact));
46      }
47  }