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.project.artifact;
20  
21  import java.util.Arrays;
22  import java.util.Collections;
23  
24  import junit.framework.TestCase;
25  import org.apache.maven.artifact.Artifact;
26  import org.apache.maven.artifact.repository.ArtifactRepository;
27  import org.apache.maven.artifact.resolver.filter.ExcludesArtifactFilter;
28  import org.apache.maven.project.artifact.DefaultMavenMetadataCache.CacheKey;
29  import org.apache.maven.repository.DelegatingLocalArtifactRepository;
30  import org.apache.maven.repository.RepositorySystem;
31  import org.apache.maven.repository.TestRepositorySystem;
32  
33  /**
34   * @author Igor Fedorenko
35   */
36  public class DefaultMavenMetadataCacheTest extends TestCase {
37      private RepositorySystem repositorySystem;
38  
39      protected void setUp() throws Exception {
40          super.setUp();
41          repositorySystem = new TestRepositorySystem();
42      }
43  
44      @Override
45      protected void tearDown() throws Exception {
46          repositorySystem = null;
47          super.tearDown();
48      }
49  
50      public void testCacheKey() throws Exception {
51          Artifact a1 = repositorySystem.createArtifact("testGroup", "testArtifact", "1.2.3", "jar");
52          @SuppressWarnings("deprecation")
53          ArtifactRepository lr1 = new DelegatingLocalArtifactRepository(repositorySystem.createDefaultLocalRepository());
54          ArtifactRepository rr1 = repositorySystem.createDefaultRemoteRepository();
55          a1.setDependencyFilter(new ExcludesArtifactFilter(Arrays.asList("foo")));
56  
57          Artifact a2 = repositorySystem.createArtifact("testGroup", "testArtifact", "1.2.3", "jar");
58          @SuppressWarnings("deprecation")
59          ArtifactRepository lr2 = new DelegatingLocalArtifactRepository(repositorySystem.createDefaultLocalRepository());
60          ArtifactRepository rr2 = repositorySystem.createDefaultRemoteRepository();
61          a2.setDependencyFilter(new ExcludesArtifactFilter(Arrays.asList("foo")));
62  
63          // sanity checks
64          assertNotSame(a1, a2);
65          assertNotSame(lr1, lr2);
66          assertNotSame(rr1, rr2);
67  
68          CacheKey k1 = new CacheKey(a1, false, lr1, Collections.singletonList(rr1));
69          CacheKey k2 = new CacheKey(a2, false, lr2, Collections.singletonList(rr2));
70  
71          assertEquals(k1.hashCode(), k2.hashCode());
72      }
73  }