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
41 class ExtensionDescriptorBuilderTest {
42
43 private ExtensionDescriptorBuilder builder;
44
45 @BeforeEach
46 void setUp() throws Exception {
47 builder = new ExtensionDescriptorBuilder();
48 }
49
50 @AfterEach
51 void tearDown() throws Exception {
52 builder = null;
53 }
54
55 private InputStream toStream(String xml) {
56 return new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8));
57 }
58
59 @Test
60 void testEmptyDescriptor() throws Exception {
61 String xml = "<extension></extension>";
62
63 ExtensionDescriptor ed = builder.build(toStream(xml));
64
65 assertNotNull(ed);
66 assertNotNull(ed.getExportedPackages());
67 assertThat(ed.getExportedPackages(), is(empty()));
68 assertNotNull(ed.getExportedArtifacts());
69 assertThat(ed.getExportedArtifacts(), is(empty()));
70 }
71
72 @Test
73 void testCompleteDescriptor() throws Exception {
74 String xml = "<?xml version='1.0' encoding='UTF-8'?>" + "<extension>" + "<exportedPackages>"
75 + "<exportedPackage>a</exportedPackage>" + "<exportedPackage>b</exportedPackage>"
76 + "<exportedPackage>c</exportedPackage>" + "</exportedPackages>" + "<exportedArtifacts>"
77 + "<exportedArtifact>x</exportedArtifact>" + "<exportedArtifact>y</exportedArtifact>"
78 + "<exportedArtifact> z </exportedArtifact>" + "</exportedArtifacts>" + "</extension>";
79
80 ExtensionDescriptor ed = builder.build(toStream(xml));
81
82 assertNotNull(ed);
83 assertEquals(Arrays.asList("a", "b", "c"), ed.getExportedPackages());
84 assertEquals(Arrays.asList("x", "y", "z"), ed.getExportedArtifacts());
85 }
86 }