1 package org.apache.maven.artifact;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 import org.apache.maven.artifact.handler.ArtifactHandlerMock;
24 import org.apache.maven.artifact.versioning.VersionRange;
25
26 import junit.framework.TestCase;
27
28 public class DefaultArtifactTest
29 extends TestCase
30 {
31
32 private DefaultArtifact artifact;
33
34 private DefaultArtifact snapshotArtifact;
35
36 private String groupId = "groupid", artifactId = "artifactId", version = "1.0", scope = "scope", type = "type",
37 classifier = "classifier";
38
39 private String snapshotSpecVersion = "1.0-SNAPSHOT";
40 private String snapshotResolvedVersion = "1.0-20070606.010101-1";
41
42 private VersionRange versionRange;
43 private VersionRange snapshotVersionRange;
44
45 private ArtifactHandlerMock artifactHandler;
46
47 protected void setUp()
48 throws Exception
49 {
50 super.setUp();
51 artifactHandler = new ArtifactHandlerMock();
52 versionRange = VersionRange.createFromVersion( version );
53 artifact = new DefaultArtifact( groupId, artifactId, versionRange, scope, type, classifier, artifactHandler );
54
55 snapshotVersionRange = VersionRange.createFromVersion( snapshotResolvedVersion );
56 snapshotArtifact = new DefaultArtifact( groupId, artifactId, snapshotVersionRange, scope, type, classifier, artifactHandler );
57 }
58
59 public void testGetVersionReturnsResolvedVersionOnSnapshot()
60 {
61 assertEquals( snapshotResolvedVersion, snapshotArtifact.getVersion() );
62
63
64
65
66 assertEquals( snapshotSpecVersion, snapshotArtifact.getBaseVersion() );
67 }
68
69 public void testGetDependencyConflictId()
70 {
71 assertEquals( groupId + ":" + artifactId + ":" + type + ":" + classifier, artifact.getDependencyConflictId() );
72 }
73
74 public void testGetDependencyConflictIdNullGroupId()
75 {
76 artifact.setGroupId( null );
77 assertEquals( null + ":" + artifactId + ":" + type + ":" + classifier, artifact.getDependencyConflictId() );
78 }
79
80 public void testGetDependencyConflictIdNullClassifier()
81 {
82 artifact = new DefaultArtifact( groupId, artifactId, versionRange, scope, type, null, artifactHandler );
83 assertEquals( groupId + ":" + artifactId + ":" + type, artifact.getDependencyConflictId() );
84 }
85
86 public void testGetDependencyConflictIdNullScope()
87 {
88 artifact.setScope( null );
89 assertEquals( groupId + ":" + artifactId + ":" + type + ":" + classifier, artifact.getDependencyConflictId() );
90 }
91
92 public void testToString()
93 {
94 assertEquals( groupId + ":" + artifactId + ":" + type + ":" + classifier + ":" + version + ":" + scope,
95 artifact.toString() );
96 }
97
98 public void testToStringNullGroupId()
99 {
100 artifact.setGroupId( null );
101 assertEquals( artifactId + ":" + type + ":" + classifier + ":" + version + ":" + scope, artifact.toString() );
102 }
103
104 public void testToStringNullClassifier()
105 {
106 artifact = new DefaultArtifact( groupId, artifactId, versionRange, scope, type, null, artifactHandler );
107 assertEquals( groupId + ":" + artifactId + ":" + type + ":" + version + ":" + scope, artifact.toString() );
108 }
109
110 public void testToStringNullScope()
111 {
112 artifact.setScope( null );
113 assertEquals( groupId + ":" + artifactId + ":" + type + ":" + classifier + ":" + version, artifact.toString() );
114 }
115
116 }