1 package org.apache.maven.project.artifact;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.Arrays;
23 import java.util.Collections;
24
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.codehaus.plexus.PlexusTestCase;
32
33
34
35
36 public class DefaultMavenMetadataCacheTest
37 extends PlexusTestCase
38 {
39 private RepositorySystem repositorySystem;
40
41 protected void setUp()
42 throws Exception
43 {
44 super.setUp();
45 repositorySystem = lookup( RepositorySystem.class );
46 }
47
48 @Override
49 protected void tearDown()
50 throws Exception
51 {
52 repositorySystem = null;
53 super.tearDown();
54 }
55
56 public void testCacheKey()
57 throws Exception
58 {
59 Artifact a1 = repositorySystem.createArtifact( "testGroup", "testArtifact", "1.2.3", "jar" );
60 @SuppressWarnings( "deprecation" )
61 ArtifactRepository lr1 = new DelegatingLocalArtifactRepository( repositorySystem.createDefaultLocalRepository() );
62 ArtifactRepository rr1 = repositorySystem.createDefaultRemoteRepository();
63 a1.setDependencyFilter( new ExcludesArtifactFilter( Arrays.asList( "foo" ) ) );
64
65 Artifact a2 = repositorySystem.createArtifact( "testGroup", "testArtifact", "1.2.3", "jar" );
66 @SuppressWarnings( "deprecation" )
67 ArtifactRepository lr2 = new DelegatingLocalArtifactRepository( repositorySystem.createDefaultLocalRepository() );
68 ArtifactRepository rr2 = repositorySystem.createDefaultRemoteRepository();
69 a2.setDependencyFilter( new ExcludesArtifactFilter( Arrays.asList( "foo" ) ) );
70
71
72 assertNotSame( a1, a2 );
73 assertNotSame( lr1, lr2 );
74 assertNotSame( rr1, rr2 );
75
76 CacheKey k1 = new CacheKey( a1, false, lr1, Collections.singletonList( rr1 ) );
77 CacheKey k2 = new CacheKey( a2, false, lr2, Collections.singletonList( rr2 ) );
78
79 assertEquals(k1.hashCode(), k2.hashCode());
80 }
81 }