1 package org.apache.maven.reporting;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.Iterator;
23 import java.util.List;
24
25 import junit.framework.Assert;
26 import junit.framework.TestCase;
27 import junitx.util.PrivateAccessor;
28
29
30
31
32 public class AbstractMavenReportRendererTest
33 extends TestCase
34 {
35 private static List<String> applyPattern( String pattern )
36 throws Throwable
37 {
38 return (List<String>) PrivateAccessor.invoke( AbstractMavenReportRenderer.class, "applyPattern",
39 new Class[] { String.class }, new Object[] { pattern } );
40 }
41
42 private static void checkPattern( String pattern, String[] expectedResult ) throws Throwable
43 {
44 List<String> result = applyPattern( pattern );
45 Assert.assertEquals( "result size", expectedResult.length, result.size() );
46 int i = 0;
47 for ( Iterator<String> it = result.iterator(); it.hasNext(); )
48 {
49 String name = it.next();
50 String href = it.next();
51 Assert.assertEquals( expectedResult[i], name );
52 Assert.assertEquals( expectedResult[i + 1], href );
53 i += 2;
54 }
55 }
56
57 private static void checkPatternIllegalArgument( String cause, String pattern ) throws Throwable
58 {
59 try
60 {
61 applyPattern( pattern );
62 Assert.fail( cause + " should throw an IllegalArgumentException" );
63 }
64 catch ( IllegalArgumentException iae )
65 {
66
67 }
68 }
69
70
71
72
73 public void testApplyPattern() throws Throwable
74 {
75
76 checkPattern( "test {text,url}", new String[] { "test ", null, "text", "url" } );
77
78
79 checkPattern( "test{ text , url }test", new String[] { "test", null, "text", "url", "test", null } );
80
81
82 checkPattern( "test{ {text} , url }", new String[] { "test", null, "{text}", "url" } );
83
84
85 checkPatternIllegalArgument( "unmatched brace", "{" );
86 checkPattern( "'{'", new String[] { "'{'", null } );
87 checkPattern( " ' { '.", new String[] { " ' { '.", null } );
88
89
90 checkPattern( " '", new String[] { " '", null } );
91
92
93
94
95
96
97 checkPattern( " ''", new String[] { " '", null } );
98 checkPattern( " '' ", new String[] { " '", null } );
99 checkPattern( " '' ", new String[] { " '", null } );
100
101
102 checkPattern( "project''s info", new String[] { "project'", null, "s info", null } );
103 checkPattern( "it''s a question of {chance, http://en.wikipedia.org/wiki/Chance}",
104 new String[] { "it'", null, "s a question of ", null,
105 "chance", "http://en.wikipedia.org/wiki/Chance" } );
106 checkPattern( "{s'inscrire,mail@mail.com}", new String[] { "s'inscrire", "mail@mail.com" } );
107
108
109 checkPattern( "it's a question of {chance, http://en.wikipedia.org/wiki/Chance}",
110 new String[] { "it's a question of {chance, http://en.wikipedia.org/wiki/Chance}", null } );
111
112 checkPattern( "{}test,", new String[] { "", null, "test,", null } );
113 checkPattern( "Hi ${name}. How is it going, sir?", new String[] { "Hi ${name}. How is it going, sir?", null } );
114 }
115 }