1 /**
2 * Copyright (c) 2012-2014, jcabi.com
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met: 1) Redistributions of source code must retain the above
8 * copyright notice, this list of conditions and the following
9 * disclaimer. 2) Redistributions in binary form must reproduce the above
10 * copyright notice, this list of conditions and the following
11 * disclaimer in the documentation and/or other materials provided
12 * with the distribution. 3) Neither the name of the jcabi.com nor
13 * the names of its contributors may be used to endorse or promote
14 * products derived from this software without specific prior written
15 * permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
19 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
21 * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
22 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
28 * OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30 package com.jcabi.aether;
31
32 import java.util.ArrayList;
33 import java.util.Collections;
34 import org.apache.maven.artifact.Artifact;
35 import org.apache.maven.artifact.DefaultArtifact;
36 import org.apache.maven.artifact.handler.DefaultArtifactHandler;
37 import org.apache.maven.model.Exclusion;
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
44 /**
45 * Test case for {@link com.jcabi.aether.MavenRootArtifact}.
46 * @author Krzysztof Krason (Krzysztof.Krason@gmail.com)
47 * @version $Id$
48 */
49 public final class MavenRootArtifactTest {
50
51 /**
52 * Temp dir.
53 * @checkstyle VisibilityModifier (3 lines)
54 */
55 @Rule
56 public final transient TemporaryFolder temp = new TemporaryFolder();
57
58 /**
59 * MavenRootArtifact can resolve a root artifact.
60 * @throws Exception If there is some problem inside
61 */
62 @Test
63 @SuppressWarnings("unchecked")
64 public void resolvesMavenRootArtifact() throws Exception {
65 final DefaultArtifact artifact = new DefaultArtifact(
66 // @checkstyle MultipleStringLiteralsCheck (1 line)
67 "junit", "junit", "4.10", "", "jar", "",
68 new DefaultArtifactHandler()
69 );
70 final MavenRootArtifact root = new MavenRootArtifact(
71 artifact,
72 new ArrayList<Exclusion>(0),
73 Collections.<Artifact>singleton(artifact)
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 )
84 );
85 }
86
87 /**
88 * MavenRootArtifact can gracefully resolve a root artifact.
89 * @throws Exception If there is some problem inside
90 */
91 @Test
92 public void gracefullyResolvesBrokenMavenRootArtifact() throws Exception {
93 final MavenRootArtifact root = new MavenRootArtifact(
94 new DefaultArtifact(
95 "junit-broken", "junit-absent", "1.0", "", "", "",
96 new DefaultArtifactHandler()
97 ),
98 new ArrayList<Exclusion>(0),
99 new ArrayList<Artifact>(0)
100 );
101 MatcherAssert.assertThat(
102 root,
103 Matchers.hasToString(
104 Matchers.containsString("junit-broken:junit-absent:1.0:0")
105 )
106 );
107 }
108 }