1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.reporting;
20
21 import java.lang.reflect.InvocationTargetException;
22 import java.lang.reflect.Method;
23 import java.util.Iterator;
24 import java.util.List;
25
26 import org.junit.jupiter.api.Test;
27
28 import static org.junit.jupiter.api.Assertions.assertEquals;
29 import static org.junit.jupiter.api.Assertions.fail;
30
31
32
33
34 public class AbstractMavenReportRendererTest {
35 private static List<String> applyPattern(String pattern) throws Throwable {
36 try {
37 Method method = AbstractMavenReportRenderer.class.getDeclaredMethod("applyPattern", String.class);
38 method.setAccessible(true);
39 return (List<String>) method.invoke(null, pattern);
40 } catch (InvocationTargetException ite) {
41 throw ite.getTargetException();
42 }
43 }
44
45 private static void checkPattern(String pattern, String[] expectedResult) throws Throwable {
46 List<String> result = applyPattern(pattern);
47 assertEquals(expectedResult.length, result.size(), "result size");
48 int i = 0;
49 for (Iterator<String> it = result.iterator(); it.hasNext(); ) {
50 String name = it.next();
51 String href = it.next();
52 assertEquals(expectedResult[i], name);
53 assertEquals(expectedResult[i + 1], href);
54 i += 2;
55 }
56 }
57
58 private static void checkPatternIllegalArgument(String cause, String pattern) throws Throwable {
59 try {
60 applyPattern(pattern);
61 fail(cause + " should throw an IllegalArgumentException");
62 } catch (IllegalArgumentException iae) {
63
64 }
65 }
66
67
68
69
70 @Test
71 public void testApplyPattern() throws Throwable {
72
73 checkPattern("test {text,url}", new String[] {"test ", null, "text", "url"});
74
75
76 checkPattern("test{ text , url }test", new String[] {"test", null, "text", "url", "test", null});
77
78
79 checkPattern("test{ {text} , url }", new String[] {"test", null, "{text}", "url"});
80
81
82 checkPatternIllegalArgument("unmatched brace", "{");
83 checkPattern("'{'", new String[] {"'{'", null});
84 checkPattern(" ' { '.", new String[] {" ' { '.", null});
85
86
87 checkPattern(" '", new String[] {" '", null});
88
89
90
91
92
93
94 checkPattern(" ''", new String[] {" '", null});
95 checkPattern(" '' ", new String[] {" '", null});
96 checkPattern(" '' ", new String[] {" '", null});
97
98
99 checkPattern("project''s info", new String[] {"project'", null, "s info", null});
100 checkPattern(
101 "it''s a question of {chance, http://en.wikipedia.org/wiki/Chance}",
102 new String[] {"it'", null, "s a question of ", null, "chance", "http://en.wikipedia.org/wiki/Chance"});
103 checkPattern("{s'inscrire,mail@mail.com}", new String[] {"s'inscrire", "mail@mail.com"});
104
105
106 checkPattern(
107 "it's a question of {chance, http://en.wikipedia.org/wiki/Chance}",
108 new String[] {"it's a question of {chance, http://en.wikipedia.org/wiki/Chance}", null});
109
110 checkPattern("{}test,", new String[] {"", null, "test,", null});
111 checkPattern("Hi ${name}. How is it going, sir?", new String[] {"Hi ${name}. How is it going, sir?", null});
112
113
114 checkPattern(
115 "{Indiana University Extreme! Lab Software License, vesion 1.1.1,"
116 + "http://www.extreme.indiana.edu/viewcvs/~checkout~/XPP3/java/LICENSE.txt}"
117 + "{Public Domain,http://creativecommons.org/licenses/publicdomain}"
118 + "{Apache Software License, version 1.1,http://www.apache.org/licenses/LICENSE-1.1}",
119 new String[] {
120 "Indiana University Extreme! Lab Software License, vesion 1.1.1",
121 "http://www.extreme.indiana.edu/viewcvs/~checkout~/XPP3/java/LICENSE.txt",
122 "Public Domain",
123 "http://creativecommons.org/licenses/publicdomain",
124 "Apache Software License, version 1.1",
125 "http://www.apache.org/licenses/LICENSE-1.1"
126 });
127 }
128 }