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