1 package org.apache.torque.generator.outlet.java;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import static org.junit.Assert.assertEquals;
23 import static org.junit.Assert.assertTrue;
24
25 import java.util.ArrayList;
26 import java.util.List;
27
28 import org.apache.torque.generator.configuration.mergepoint.MergepointMapping;
29 import org.apache.torque.generator.control.ControllerState;
30 import org.apache.torque.generator.control.action.MergepointAction;
31 import org.apache.torque.generator.control.action.OutputAction;
32 import org.apache.torque.generator.outlet.OutletResult;
33 import org.apache.torque.generator.qname.QualifiedName;
34 import org.junit.Before;
35 import org.junit.Test;
36
37 public class JavadocOutletTest
38 {
39 private JavadocOutlet javadocOutlet;
40
41 @Before
42 public void setUp()
43 {
44 javadocOutlet = new JavadocOutlet(new QualifiedName("jacadocOutlet"));
45 javadocOutlet.setMaxLineLength(20);
46 }
47
48
49
50
51
52 @Test
53 public void testCompleteJavadoc() throws Exception
54 {
55 List<MergepointAction> mergepointActions
56 = new ArrayList<MergepointAction>();
57 mergepointActions.add(new OutputAction("Test-body for.a,javadoc"));
58 javadocOutlet.setMergepointMapping(
59 new MergepointMapping(
60 "body",
61 mergepointActions));
62 mergepointActions = new ArrayList<MergepointAction>();
63 mergepointActions.add(
64 new OutputAction("@param param1 description,of param1"));
65 javadocOutlet.setMergepointMapping(
66 new MergepointMapping(
67 "attributes",
68 mergepointActions));
69 OutletResult result = javadocOutlet.execute(new ControllerState());
70 assertTrue(result.isStringResult());
71 assertEquals(
72 " /**\n"
73 + " * Test-body\n"
74 + " * for.a,javadoc\n"
75 + " *\n"
76 + " * @param param1\n"
77 + " * description,\n"
78 + " * of\n"
79 + " * param1\n"
80 + " */\n",
81 result.getStringResult());
82 }
83
84
85
86
87
88
89 @Test
90 public void testWrapAfterNotRemovedCharacters()
91 {
92 String result = javadocOutlet.wrapLinesAndIndent(
93 "Test-body111-breaking.at1. 111111 not; removed1111,characters");
94 assertEquals(
95 " * Test-body111-\n"
96 + " * breaking.at1.\n"
97 + " * 111111 not; \n"
98 + " * removed1111,\n"
99 + " * characters\n",
100 result);
101 }
102
103
104
105
106
107
108 @Test
109 public void testSpaceAtEndRemoved()
110 {
111 String result = javadocOutlet.wrapLinesAndIndent(
112 "Test body1111 breaking at1 space");
113 assertEquals(
114 " * Test body1111\n"
115 + " * breaking at1\n"
116 + " * space\n",
117 result);
118 }
119
120
121
122
123 @Test
124 public void testDoubleWrapAtNewAttribute()
125 {
126 String result = javadocOutlet.wrapLinesAndIndent(
127 "body @since 1 2 3 4 5");
128 assertEquals(
129 " * body\n"
130 + " *\n"
131 + " * @since 1 2 3\n"
132 + " * 4 5\n",
133 result);
134 }
135
136
137
138
139
140 @Test
141 public void testDoubleWrapAtDifferentAttributes()
142 {
143 String result = javadocOutlet.wrapLinesAndIndent(
144 "@since 1 @see y");
145 assertEquals(
146 " * @since 1\n"
147 + " *\n"
148 + " * @see y\n",
149 result);
150 }
151
152
153
154
155
156
157 @Test
158 public void testDoubleWrapAtDifferentAttributesWithLineBreak()
159 {
160 String result = javadocOutlet.wrapLinesAndIndent(
161 "@since 1\n@see y");
162 assertEquals(
163 " * @since 1\n"
164 + " *\n"
165 + " * @see y\n",
166 result);
167 }
168
169
170
171
172
173 @Test
174 public void testSingleWrapAtAttribute()
175 {
176 String result = javadocOutlet.wrapLinesAndIndent(
177 "body\n@since 11 2 3 4 5 @since x");
178 assertEquals(
179 " * body\n"
180 + " *\n"
181 + " * @since 11 2 3\n"
182 + " * 4 5\n"
183 + " * @since x\n",
184 result);
185 }
186
187
188
189
190
191 @Test
192 public void testSingleWrapAtAttributeWithLineBreak()
193 {
194 String result = javadocOutlet.wrapLinesAndIndent(
195 "@since x\n@since y");
196 assertEquals(
197 " * @since x\n"
198 + " * @since y\n",
199 result);
200 }
201
202
203
204
205 @Test
206 public void testSetWrapAfterCharacters()
207 {
208 javadocOutlet.setWrapAfterCharacters(".");
209 String result = javadocOutlet.wrapLinesAndIndent(
210 "123-456,789;012.345");
211 assertEquals(
212 " * 123-456,789;012.\n"
213 + " * 345\n",
214 result);
215 }
216
217
218
219
220 @Test
221 public void testSetIndent()
222 {
223 javadocOutlet.setIndent(" ");
224 String result = javadocOutlet.wrapLinesAndIndent(
225 "123-456,789;012");
226 assertEquals(
227 " * 123-456,\n"
228 + " * 789;012\n",
229 result);
230 }
231
232
233
234
235 @Test
236 public void testSetLineBreak()
237 {
238 javadocOutlet.setLineBreak("\r\n");
239 String result = javadocOutlet.wrapLinesAndIndent(
240 "xxx123-456,789\n012.345");
241 assertEquals(
242 " * xxx123-456,\r\n"
243 + " * 789\r\n"
244 + " * 012.345\r\n",
245 result);
246 }
247
248
249
250
251 @Test(expected = IllegalArgumentException.class)
252 public void testSetLineBreakIllegalInput()
253 {
254 javadocOutlet.setLineBreak("\n\r");
255 }
256
257
258
259
260 @Test
261 public void testRemoveEndEmptyString()
262 {
263 StringBuilder builder = new StringBuilder();
264 JavadocOutlet.removeEnd(builder, " \r\n");
265 assertEquals("", builder.toString());
266 }
267
268
269
270
271 @Test
272 public void testRemoveEndEverythingRemoved()
273 {
274 StringBuilder builder = new StringBuilder().append(" \r\r\n \n");
275 JavadocOutlet.removeEnd(builder, " \r\n");
276 assertEquals("", builder.toString());
277 }
278
279
280
281
282 @Test
283 public void testRemoveEndNothingRemoved()
284 {
285 StringBuilder builder = new StringBuilder().append(" \r\r\n \na");
286 JavadocOutlet.removeEnd(builder, " \r\n");
287 assertEquals(" \r\r\n \na", builder.toString());
288 }
289
290
291
292
293 @Test
294 public void testRemoveEndPartRemoved()
295 {
296 StringBuilder builder = new StringBuilder().append(" \r\r\n x \r \n");
297 JavadocOutlet.removeEnd(builder, " \r\n");
298 assertEquals(" \r\r\n x", builder.toString());
299 }
300
301
302
303
304
305 @Test
306 public void testRemoveEndAllButFirstCharacterRemoved()
307 {
308 StringBuilder builder = new StringBuilder().append("x\r\r\n \r \n");
309 JavadocOutlet.removeEnd(builder, " \r\n");
310 assertEquals("x", builder.toString());
311 }
312
313
314
315
316 @Test
317 public void testRemoveEndOnlyLastCharacterRemoved()
318 {
319 StringBuilder builder = new StringBuilder().append("\r\r\n \rx ");
320 JavadocOutlet.removeEnd(builder, " \r\n");
321 assertEquals("\r\r\n \rx", builder.toString());
322 }
323 }