1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.project;
20
21 import java.io.ByteArrayInputStream;
22 import java.io.InputStream;
23 import java.nio.charset.StandardCharsets;
24 import java.util.Arrays;
25
26 import org.junit.jupiter.api.AfterEach;
27 import org.junit.jupiter.api.BeforeEach;
28 import org.junit.jupiter.api.Test;
29
30 import static org.hamcrest.MatcherAssert.assertThat;
31 import static org.hamcrest.Matchers.empty;
32 import static org.hamcrest.Matchers.is;
33 import static org.junit.jupiter.api.Assertions.assertEquals;
34 import static org.junit.jupiter.api.Assertions.assertNotNull;
35
36
37
38
39
40 class ExtensionDescriptorBuilderTest {
41
42 private ExtensionDescriptorBuilder builder;
43
44 @BeforeEach
45 void setUp() throws Exception {
46 builder = new ExtensionDescriptorBuilder();
47 }
48
49 @AfterEach
50 void tearDown() throws Exception {
51 builder = null;
52 }
53
54 private InputStream toStream(String xml) {
55 return new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8));
56 }
57
58 @Test
59 void testEmptyDescriptor() throws Exception {
60 String xml = "<extension></extension>";
61
62 ExtensionDescriptor ed = builder.build(toStream(xml));
63
64 assertNotNull(ed);
65 assertNotNull(ed.getExportedPackages());
66 assertThat(ed.getExportedPackages(), is(empty()));
67 assertNotNull(ed.getExportedArtifacts());
68 assertThat(ed.getExportedArtifacts(), is(empty()));
69 }
70
71 @Test
72 void testCompleteDescriptor() throws Exception {
73 String xml = "<?xml version='1.0' encoding='UTF-8'?>" + "<extension>" + "<exportedPackages>"
74 + "<exportedPackage>a</exportedPackage>" + "<exportedPackage>b</exportedPackage>"
75 + "<exportedPackage>c</exportedPackage>" + "</exportedPackages>" + "<exportedArtifacts>"
76 + "<exportedArtifact>x</exportedArtifact>" + "<exportedArtifact>y</exportedArtifact>"
77 + "<exportedArtifact> z </exportedArtifact>" + "</exportedArtifacts>" + "</extension>";
78
79 ExtensionDescriptor ed = builder.build(toStream(xml));
80
81 assertNotNull(ed);
82 assertEquals(Arrays.asList("a", "b", "c"), ed.getExportedPackages());
83 assertEquals(Arrays.asList("x", "y", "z"), ed.getExportedArtifacts());
84 }
85 }