1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 package com.jcabi.aether;
31
32 import java.io.File;
33 import java.util.ArrayList;
34 import java.util.Arrays;
35 import java.util.List;
36 import org.apache.maven.model.Exclusion;
37 import org.apache.maven.project.MavenProject;
38 import org.hamcrest.MatcherAssert;
39 import org.hamcrest.Matchers;
40 import org.junit.Rule;
41 import org.junit.Test;
42 import org.junit.rules.TemporaryFolder;
43 import org.mockito.Mockito;
44 import org.sonatype.aether.artifact.Artifact;
45 import org.sonatype.aether.repository.RemoteRepository;
46 import org.sonatype.aether.util.artifact.DefaultArtifact;
47
48
49
50
51
52
53 public final class RootArtifactTest {
54
55
56
57
58
59 @Rule
60 public final transient TemporaryFolder temp = new TemporaryFolder();
61
62
63
64
65
66 @Test
67 @SuppressWarnings("unchecked")
68 public void resolvesRootArtifact() throws Exception {
69 final RootArtifact root = new RootArtifact(
70 this.aether(),
71
72 new DefaultArtifact("junit", "junit", "", "jar", "4.10"),
73 new ArrayList<Exclusion>(0)
74 );
75 MatcherAssert.assertThat(
76 root,
77 Matchers.hasToString(Matchers.containsString("junit:junit:4.10"))
78 );
79 MatcherAssert.assertThat(
80 root.children(),
81 Matchers.<Artifact>hasItems(
82 Matchers.hasToString("junit:junit:jar:4.10"),
83 Matchers.hasToString("org.hamcrest:hamcrest-core:jar:1.1")
84 )
85 );
86 }
87
88
89
90
91
92 @Test
93 public void gracefullyResolvesBrokenRootArtifact() throws Exception {
94 final RootArtifact root = new RootArtifact(
95 this.aether(),
96 new DefaultArtifact("junit-broken", "junit-absent", "", "", "1.0"),
97 new ArrayList<Exclusion>(0)
98 );
99 MatcherAssert.assertThat(
100 root,
101 Matchers.hasToString(
102 Matchers.containsString("failed to load 'junit-broken:")
103 )
104 );
105 }
106
107
108
109
110
111
112 private Aether aether() throws Exception {
113 final File local = this.temp.newFolder();
114 final MavenProject project = Mockito.mock(MavenProject.class);
115 final List<RemoteRepository> repos = Arrays.asList(
116 new RemoteRepository(
117 "maven-central",
118 "default",
119 "http://repo1.maven.org/maven2/"
120 )
121 );
122 Mockito.doReturn(repos).when(project).getRemoteProjectRepositories();
123 return new Aether(project, local);
124 }
125
126 }