1 | /* |
2 | * Copyright (c) 2001-2009, Jean Tessier |
3 | * All rights reserved. |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
8 | * |
9 | * * Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. |
11 | * |
12 | * * Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. |
15 | * |
16 | * * Neither the name of Jean Tessier nor the names of his contributors |
17 | * may be used to endorse or promote products derived from this software |
18 | * without specific prior written permission. |
19 | * |
20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR |
24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
31 | */ |
32 | |
33 | package com.jeantessier.classreader; |
34 | |
35 | import java.io.*; |
36 | import java.util.*; |
37 | import javax.xml.parsers.*; |
38 | import javax.xml.xpath.*; |
39 | |
40 | import org.apache.oro.text.perl.*; |
41 | import org.jmock.*; |
42 | import org.jmock.integration.junit3.*; |
43 | import org.w3c.dom.*; |
44 | import org.xml.sax.*; |
45 | |
46 | public class TestXMLPrinter extends MockObjectTestCase { |
47 | private static final String TEST_CLASS = "test"; |
48 | private static final String TEST_FILENAME = "classes" + File.separator + "test.class"; |
49 | private static final String TEST_DIRECTORY = "tests" + File.separator + "JarJarDiff" + File.separator + "new"; |
50 | |
51 | private static final String SPECIFIC_ENCODING = "iso-latin-1"; |
52 | private static final String SPECIFIC_DTD_PREFIX = "./etc"; |
53 | |
54 | private static final String ANNOTATION_TYPE = "foobar"; |
55 | private static final String ELEMENT_NAME = "foo"; |
56 | |
57 | private ClassfileLoader loader; |
58 | private StringWriter buffer; |
59 | private Visitor printer; |
60 | private XMLReader reader; |
61 | private ErrorHandler errorHandler; |
62 | |
63 | private Perl5Util perl; |
64 | |
65 | protected void setUp() throws Exception { |
66 | super.setUp(); |
67 | |
68 | loader = new AggregatingClassfileLoader(); |
69 | |
70 | buffer = new StringWriter(); |
71 | printer = new XMLPrinter(new PrintWriter(buffer), XMLPrinter.DEFAULT_ENCODING, SPECIFIC_DTD_PREFIX); |
72 | reader = SAXParserFactory.newInstance().newSAXParser().getXMLReader(); |
73 | |
74 | boolean validate = Boolean.getBoolean("DEPENDENCYFINDER_TESTS_VALIDATE"); |
75 | reader.setFeature("http://xml.org/sax/features/validation", validate); |
76 | reader.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", validate); |
77 | |
78 | errorHandler = mock(ErrorHandler.class); |
79 | reader.setErrorHandler(errorHandler); |
80 | |
81 | perl = new Perl5Util(); |
82 | } |
83 | |
84 | public void testDefaultDTDPrefix() throws Exception { |
85 | checking(new Expectations() {{ |
86 | one (errorHandler).fatalError(with(any(SAXParseException.class))); |
87 | }}); |
88 | |
89 | buffer = new StringWriter(); |
90 | printer = new XMLPrinter(new PrintWriter(buffer)); |
91 | |
92 | String xmlDocument = buffer.toString(); |
93 | assertTrue(xmlDocument + "Missing DTD", perl.match("/DOCTYPE \\S+ SYSTEM \"(.*)\"/", xmlDocument)); |
94 | assertTrue("DTD \"" + perl.group(1) + "\" does not have prefix \"" + XMLPrinter.DEFAULT_DTD_PREFIX + "\"", perl.group(1).startsWith(XMLPrinter.DEFAULT_DTD_PREFIX)); |
95 | |
96 | try { |
97 | reader.parse(new InputSource(new StringReader(xmlDocument))); |
98 | fail("Parsed non-existant document\n" + xmlDocument); |
99 | } catch (SAXParseException ex) { |
100 | // Expected |
101 | } |
102 | } |
103 | |
104 | public void testSpecificDTDPrefix() throws Exception { |
105 | checking(new Expectations() {{ |
106 | one (errorHandler).fatalError(with(any(SAXParseException.class))); |
107 | }}); |
108 | |
109 | buffer = new StringWriter(); |
110 | printer = new XMLPrinter(new PrintWriter(buffer), XMLPrinter.DEFAULT_ENCODING, SPECIFIC_DTD_PREFIX); |
111 | |
112 | String xmlDocument = buffer.toString(); |
113 | assertTrue(xmlDocument + "Missing DTD", perl.match("/DOCTYPE \\S+ SYSTEM \"(.*)\"/", xmlDocument)); |
114 | assertTrue("DTD \"" + perl.group(1) + "\" does not have prefix \"./etc\"", perl.group(1).startsWith(SPECIFIC_DTD_PREFIX)); |
115 | |
116 | try { |
117 | reader.parse(new InputSource(new StringReader(xmlDocument))); |
118 | fail("Parsed non-existant document\n" + xmlDocument); |
119 | } catch (SAXParseException ex) { |
120 | // Expected |
121 | } |
122 | } |
123 | |
124 | public void testDefaultEncoding() throws Exception { |
125 | checking(new Expectations() {{ |
126 | one (errorHandler).fatalError(with(any(SAXParseException.class))); |
127 | }}); |
128 | |
129 | buffer = new StringWriter(); |
130 | printer = new XMLPrinter(new PrintWriter(buffer)); |
131 | |
132 | String xmlDocument = buffer.toString(); |
133 | assertTrue(xmlDocument + "Missing encoding", perl.match("/encoding=\"([^\"]*)\"/", xmlDocument)); |
134 | assertEquals("Encoding", XMLPrinter.DEFAULT_ENCODING, perl.group(1)); |
135 | |
136 | try { |
137 | reader.parse(new InputSource(new StringReader(xmlDocument))); |
138 | fail("Parsed non-existant document\n" + xmlDocument); |
139 | } catch (SAXParseException ex) { |
140 | // Expected |
141 | } |
142 | } |
143 | |
144 | public void testSpecificEncoding() throws Exception { |
145 | checking(new Expectations() {{ |
146 | one (errorHandler).fatalError(with(any(SAXParseException.class))); |
147 | }}); |
148 | |
149 | buffer = new StringWriter(); |
150 | printer = new XMLPrinter(new PrintWriter(buffer), SPECIFIC_ENCODING, XMLPrinter.DEFAULT_DTD_PREFIX); |
151 | |
152 | String xmlDocument = buffer.toString(); |
153 | assertTrue(xmlDocument + "Missing encoding", perl.match("/encoding=\"([^\"]*)\"/", xmlDocument)); |
154 | assertEquals("Encoding", SPECIFIC_ENCODING, perl.group(1)); |
155 | |
156 | try { |
157 | reader.parse(new InputSource(new StringReader(xmlDocument))); |
158 | fail("Parsed non-existant document\n" + xmlDocument); |
159 | } catch (SAXParseException ex) { |
160 | // Expected |
161 | } |
162 | } |
163 | |
164 | public void testSingleClassfile() throws Exception { |
165 | loader.load(Collections.singleton(TEST_FILENAME)); |
166 | |
167 | loader.getClassfile(TEST_CLASS).accept(printer); |
168 | |
169 | String xmlDocument = buffer.toString(); |
170 | assertXPathCount(xmlDocument, "classfile[this-class='" + TEST_CLASS + "']", 1); |
171 | } |
172 | |
173 | public void testZeroClassfile() throws Exception { |
174 | printer.visitClassfiles(Collections.<Classfile>emptyList()); |
175 | |
176 | String xmlDocument = buffer.toString(); |
177 | assertXPathCount(xmlDocument, "*/classfile[this-class='" + TEST_CLASS + "']", 0); |
178 | } |
179 | |
180 | public void testOneClassfile() throws Exception { |
181 | loader.load(Collections.singleton(TEST_FILENAME)); |
182 | |
183 | printer.visitClassfiles(loader.getAllClassfiles()); |
184 | |
185 | String xmlDocument = buffer.toString(); |
186 | assertXPathCount(xmlDocument, "*/classfile", loader.getAllClassfiles().size()); |
187 | } |
188 | |
189 | public void testMultipleClassfiles() throws Exception { |
190 | loader.load(Collections.singleton(TEST_DIRECTORY)); |
191 | |
192 | printer.visitClassfiles(loader.getAllClassfiles()); |
193 | |
194 | String xmlDocument = buffer.toString(); |
195 | assertXPathCount(xmlDocument, "*/classfile", loader.getAllClassfiles().size()); |
196 | } |
197 | |
198 | public void testNonPublicClassfile() throws Exception { |
199 | final Classfile mockClassfile = mock(Classfile.class); |
200 | |
201 | checking(new Expectations() {{ |
202 | one (mockClassfile).isPublic(); will(returnValue(false)); |
203 | ignoring (mockClassfile); |
204 | }}); |
205 | |
206 | printer.visitClassfile(mockClassfile); |
207 | |
208 | String xmlDocument = buffer.toString(); |
209 | assertXPathCount(xmlDocument, "classfile/public", 0); |
210 | } |
211 | |
212 | public void testPublicClassfile() throws Exception { |
213 | final Classfile mockClassfile = mock(Classfile.class); |
214 | |
215 | checking(new Expectations() {{ |
216 | one (mockClassfile).isPublic(); will(returnValue(true)); |
217 | ignoring (mockClassfile); |
218 | }}); |
219 | |
220 | printer.visitClassfile(mockClassfile); |
221 | |
222 | String xmlDocument = buffer.toString(); |
223 | assertXPathCount(xmlDocument, "classfile/public", 1); |
224 | } |
225 | |
226 | public void testNonFinalClassfile() throws Exception { |
227 | final Classfile mockClassfile = mock(Classfile.class); |
228 | |
229 | checking(new Expectations() {{ |
230 | one (mockClassfile).isFinal(); will(returnValue(false)); |
231 | ignoring (mockClassfile); |
232 | }}); |
233 | |
234 | printer.visitClassfile(mockClassfile); |
235 | |
236 | String xmlDocument = buffer.toString(); |
237 | assertXPathCount(xmlDocument, "classfile/final", 0); |
238 | } |
239 | |
240 | public void testFinalClassfile() throws Exception { |
241 | final Classfile mockClassfile = mock(Classfile.class); |
242 | |
243 | checking(new Expectations() {{ |
244 | one (mockClassfile).isFinal(); will(returnValue(true)); |
245 | ignoring (mockClassfile); |
246 | }}); |
247 | |
248 | printer.visitClassfile(mockClassfile); |
249 | |
250 | String xmlDocument = buffer.toString(); |
251 | assertXPathCount(xmlDocument, "classfile/final", 1); |
252 | } |
253 | |
254 | public void testNonSuperClassfile() throws Exception { |
255 | final Classfile mockClassfile = mock(Classfile.class); |
256 | |
257 | checking(new Expectations() {{ |
258 | one (mockClassfile).isSuper(); will(returnValue(false)); |
259 | ignoring (mockClassfile); |
260 | }}); |
261 | |
262 | printer.visitClassfile(mockClassfile); |
263 | |
264 | String xmlDocument = buffer.toString(); |
265 | assertXPathCount(xmlDocument, "classfile/super", 0); |
266 | } |
267 | |
268 | public void testSuperClassfile() throws Exception { |
269 | final Classfile mockClassfile = mock(Classfile.class); |
270 | |
271 | checking(new Expectations() {{ |
272 | one (mockClassfile).isSuper(); will(returnValue(true)); |
273 | ignoring (mockClassfile); |
274 | }}); |
275 | |
276 | printer.visitClassfile(mockClassfile); |
277 | |
278 | String xmlDocument = buffer.toString(); |
279 | assertXPathCount(xmlDocument, "classfile/super", 1); |
280 | } |
281 | |
282 | public void testNonInterfaceClassfile() throws Exception { |
283 | final Classfile mockClassfile = mock(Classfile.class); |
284 | |
285 | checking(new Expectations() {{ |
286 | one (mockClassfile).isInterface(); will(returnValue(false)); |
287 | ignoring (mockClassfile); |
288 | }}); |
289 | |
290 | printer.visitClassfile(mockClassfile); |
291 | |
292 | String xmlDocument = buffer.toString(); |
293 | assertXPathCount(xmlDocument, "classfile/is-interface", 0); |
294 | } |
295 | |
296 | public void testInterfaceClassfile() throws Exception { |
297 | final Classfile mockClassfile = mock(Classfile.class); |
298 | |
299 | checking(new Expectations() {{ |
300 | one (mockClassfile).isInterface(); will(returnValue(true)); |
301 | ignoring (mockClassfile); |
302 | }}); |
303 | |
304 | printer.visitClassfile(mockClassfile); |
305 | |
306 | String xmlDocument = buffer.toString(); |
307 | assertXPathCount(xmlDocument, "classfile/is-interface", 1); |
308 | } |
309 | |
310 | public void testNonAbstractClassfile() throws Exception { |
311 | final Classfile mockClassfile = mock(Classfile.class); |
312 | |
313 | checking(new Expectations() {{ |
314 | one (mockClassfile).isAbstract(); will(returnValue(false)); |
315 | ignoring (mockClassfile); |
316 | }}); |
317 | |
318 | printer.visitClassfile(mockClassfile); |
319 | |
320 | String xmlDocument = buffer.toString(); |
321 | assertXPathCount(xmlDocument, "classfile/abstract", 0); |
322 | } |
323 | |
324 | public void testAbstractClassfile() throws Exception { |
325 | final Classfile mockClassfile = mock(Classfile.class); |
326 | |
327 | checking(new Expectations() {{ |
328 | one (mockClassfile).isAbstract(); will(returnValue(true)); |
329 | ignoring (mockClassfile); |
330 | }}); |
331 | |
332 | printer.visitClassfile(mockClassfile); |
333 | |
334 | String xmlDocument = buffer.toString(); |
335 | assertXPathCount(xmlDocument, "classfile/abstract", 1); |
336 | } |
337 | |
338 | public void testNonSyntheticClassfile() throws Exception { |
339 | final Classfile mockClassfile = mock(Classfile.class); |
340 | |
341 | checking(new Expectations() {{ |
342 | one (mockClassfile).isSynthetic(); will(returnValue(false)); |
343 | ignoring (mockClassfile); |
344 | }}); |
345 | |
346 | printer.visitClassfile(mockClassfile); |
347 | |
348 | String xmlDocument = buffer.toString(); |
349 | assertXPathCount(xmlDocument, "classfile/synthetic", 0); |
350 | } |
351 | |
352 | public void testSyntheticClassfile() throws Exception { |
353 | final Classfile mockClassfile = mock(Classfile.class); |
354 | |
355 | checking(new Expectations() {{ |
356 | one (mockClassfile).isSynthetic(); will(returnValue(true)); |
357 | ignoring (mockClassfile); |
358 | }}); |
359 | |
360 | printer.visitClassfile(mockClassfile); |
361 | |
362 | String xmlDocument = buffer.toString(); |
363 | assertXPathCount(xmlDocument, "classfile/synthetic", 1); |
364 | } |
365 | |
366 | public void testNonAnnotationClassfile() throws Exception { |
367 | final Classfile mockClassfile = mock(Classfile.class); |
368 | |
369 | checking(new Expectations() {{ |
370 | one (mockClassfile).isAnnotation(); will(returnValue(false)); |
371 | ignoring (mockClassfile); |
372 | }}); |
373 | |
374 | printer.visitClassfile(mockClassfile); |
375 | |
376 | String xmlDocument = buffer.toString(); |
377 | assertXPathCount(xmlDocument, "classfile/is-annotation", 0); |
378 | } |
379 | |
380 | public void testAnnotationClassfile() throws Exception { |
381 | final Classfile mockClassfile = mock(Classfile.class); |
382 | |
383 | checking(new Expectations() {{ |
384 | one (mockClassfile).isAnnotation(); will(returnValue(true)); |
385 | ignoring (mockClassfile); |
386 | }}); |
387 | |
388 | printer.visitClassfile(mockClassfile); |
389 | |
390 | String xmlDocument = buffer.toString(); |
391 | assertXPathCount(xmlDocument, "classfile/is-annotation", 1); |
392 | } |
393 | |
394 | public void testNonEnumClassfile() throws Exception { |
395 | final Classfile mockClassfile = mock(Classfile.class); |
396 | |
397 | checking(new Expectations() {{ |
398 | one (mockClassfile).isEnum(); will(returnValue(false)); |
399 | ignoring (mockClassfile); |
400 | }}); |
401 | |
402 | printer.visitClassfile(mockClassfile); |
403 | |
404 | String xmlDocument = buffer.toString(); |
405 | assertXPathCount(xmlDocument, "classfile/enum", 0); |
406 | } |
407 | |
408 | public void testEnumClassfile() throws Exception { |
409 | final Classfile mockClassfile = mock(Classfile.class); |
410 | |
411 | checking(new Expectations() {{ |
412 | one (mockClassfile).isEnum(); will(returnValue(true)); |
413 | ignoring (mockClassfile); |
414 | }}); |
415 | |
416 | printer.visitClassfile(mockClassfile); |
417 | |
418 | String xmlDocument = buffer.toString(); |
419 | assertXPathCount(xmlDocument, "classfile/enum", 1); |
420 | } |
421 | |
422 | public void testNonPublicField() throws Exception { |
423 | final Field_info mockField = mock(Field_info.class); |
424 | |
425 | checking(new Expectations() {{ |
426 | one (mockField).isPublic(); will(returnValue(false)); |
427 | ignoring (mockField); |
428 | }}); |
429 | |
430 | printer.visitField_info(mockField); |
431 | |
432 | String xmlDocument = buffer.toString(); |
433 | assertXPathCount(xmlDocument, "field-info/public", 0); |
434 | } |
435 | |
436 | public void testPublicField() throws Exception { |
437 | final Field_info mockField = mock(Field_info.class); |
438 | |
439 | checking(new Expectations() {{ |
440 | one (mockField).isPublic(); will(returnValue(true)); |
441 | ignoring (mockField); |
442 | }}); |
443 | |
444 | printer.visitField_info(mockField); |
445 | |
446 | String xmlDocument = buffer.toString(); |
447 | assertXPathCount(xmlDocument, "field-info/public", 1); |
448 | } |
449 | |
450 | public void testNonProtectedField() throws Exception { |
451 | final Field_info mockField = mock(Field_info.class); |
452 | |
453 | checking(new Expectations() {{ |
454 | one (mockField).isProtected(); will(returnValue(false)); |
455 | ignoring (mockField); |
456 | }}); |
457 | |
458 | printer.visitField_info(mockField); |
459 | |
460 | String xmlDocument = buffer.toString(); |
461 | assertXPathCount(xmlDocument, "field-info/protected", 0); |
462 | } |
463 | |
464 | public void testProtectedField() throws Exception { |
465 | final Field_info mockField = mock(Field_info.class); |
466 | |
467 | checking(new Expectations() {{ |
468 | one (mockField).isProtected(); will(returnValue(true)); |
469 | ignoring (mockField); |
470 | }}); |
471 | |
472 | printer.visitField_info(mockField); |
473 | |
474 | String xmlDocument = buffer.toString(); |
475 | assertXPathCount(xmlDocument, "field-info/protected", 1); |
476 | } |
477 | |
478 | public void testNonPrivateField() throws Exception { |
479 | final Field_info mockField = mock(Field_info.class); |
480 | |
481 | checking(new Expectations() {{ |
482 | one (mockField).isPrivate(); will(returnValue(false)); |
483 | ignoring (mockField); |
484 | }}); |
485 | |
486 | printer.visitField_info(mockField); |
487 | |
488 | String xmlDocument = buffer.toString(); |
489 | assertXPathCount(xmlDocument, "field-info/private", 0); |
490 | } |
491 | |
492 | public void testPrivateField() throws Exception { |
493 | final Field_info mockField = mock(Field_info.class); |
494 | |
495 | checking(new Expectations() {{ |
496 | one (mockField).isPrivate(); will(returnValue(true)); |
497 | ignoring (mockField); |
498 | }}); |
499 | |
500 | printer.visitField_info(mockField); |
501 | |
502 | String xmlDocument = buffer.toString(); |
503 | assertXPathCount(xmlDocument, "field-info/private", 1); |
504 | } |
505 | |
506 | public void testNonStaticField() throws Exception { |
507 | final Field_info mockField = mock(Field_info.class); |
508 | |
509 | checking(new Expectations() {{ |
510 | one (mockField).isStatic(); will(returnValue(false)); |
511 | ignoring (mockField); |
512 | }}); |
513 | |
514 | printer.visitField_info(mockField); |
515 | |
516 | String xmlDocument = buffer.toString(); |
517 | assertXPathCount(xmlDocument, "field-info/static", 0); |
518 | } |
519 | |
520 | public void testStaticField() throws Exception { |
521 | final Field_info mockField = mock(Field_info.class); |
522 | |
523 | checking(new Expectations() {{ |
524 | one (mockField).isStatic(); will(returnValue(true)); |
525 | ignoring (mockField); |
526 | }}); |
527 | |
528 | printer.visitField_info(mockField); |
529 | |
530 | String xmlDocument = buffer.toString(); |
531 | assertXPathCount(xmlDocument, "field-info/static", 1); |
532 | } |
533 | |
534 | public void testNonFinalField() throws Exception { |
535 | final Field_info mockField = mock(Field_info.class); |
536 | |
537 | checking(new Expectations() {{ |
538 | one (mockField).isFinal(); will(returnValue(false)); |
539 | ignoring (mockField); |
540 | }}); |
541 | |
542 | printer.visitField_info(mockField); |
543 | |
544 | String xmlDocument = buffer.toString(); |
545 | assertXPathCount(xmlDocument, "field-info/final", 0); |
546 | } |
547 | |
548 | public void testFinalField() throws Exception { |
549 | final Field_info mockField = mock(Field_info.class); |
550 | |
551 | checking(new Expectations() {{ |
552 | one (mockField).isFinal(); will(returnValue(true)); |
553 | ignoring (mockField); |
554 | }}); |
555 | |
556 | printer.visitField_info(mockField); |
557 | |
558 | String xmlDocument = buffer.toString(); |
559 | assertXPathCount(xmlDocument, "field-info/final", 1); |
560 | } |
561 | |
562 | public void testNonVolatileField() throws Exception { |
563 | final Field_info mockField = mock(Field_info.class); |
564 | |
565 | checking(new Expectations() {{ |
566 | one (mockField).isVolatile(); will(returnValue(false)); |
567 | ignoring (mockField); |
568 | }}); |
569 | |
570 | printer.visitField_info(mockField); |
571 | |
572 | String xmlDocument = buffer.toString(); |
573 | assertXPathCount(xmlDocument, "field-info/volatile", 0); |
574 | } |
575 | |
576 | public void testVolatileField() throws Exception { |
577 | final Field_info mockField = mock(Field_info.class); |
578 | |
579 | checking(new Expectations() {{ |
580 | one (mockField).isVolatile(); will(returnValue(true)); |
581 | ignoring (mockField); |
582 | }}); |
583 | |
584 | printer.visitField_info(mockField); |
585 | |
586 | String xmlDocument = buffer.toString(); |
587 | assertXPathCount(xmlDocument, "field-info/volatile", 1); |
588 | } |
589 | |
590 | public void testNonTransientField() throws Exception { |
591 | final Field_info mockField = mock(Field_info.class); |
592 | |
593 | checking(new Expectations() {{ |
594 | one (mockField).isTransient(); will(returnValue(false)); |
595 | ignoring (mockField); |
596 | }}); |
597 | |
598 | printer.visitField_info(mockField); |
599 | |
600 | String xmlDocument = buffer.toString(); |
601 | assertXPathCount(xmlDocument, "field-info/transient", 0); |
602 | } |
603 | |
604 | public void testTransientField() throws Exception { |
605 | final Field_info mockField = mock(Field_info.class); |
606 | |
607 | checking(new Expectations() {{ |
608 | one (mockField).isTransient(); will(returnValue(true)); |
609 | ignoring (mockField); |
610 | }}); |
611 | |
612 | printer.visitField_info(mockField); |
613 | |
614 | String xmlDocument = buffer.toString(); |
615 | assertXPathCount(xmlDocument, "field-info/transient", 1); |
616 | } |
617 | |
618 | public void testNonSyntheticField() throws Exception { |
619 | final Field_info mockField = mock(Field_info.class); |
620 | |
621 | checking(new Expectations() {{ |
622 | one (mockField).isSynthetic(); will(returnValue(false)); |
623 | ignoring (mockField); |
624 | }}); |
625 | |
626 | printer.visitField_info(mockField); |
627 | |
628 | String xmlDocument = buffer.toString(); |
629 | assertXPathCount(xmlDocument, "field-info/synthetic", 0); |
630 | } |
631 | |
632 | public void testSyntheticField() throws Exception { |
633 | final Field_info mockField = mock(Field_info.class); |
634 | |
635 | checking(new Expectations() {{ |
636 | one (mockField).isSynthetic(); will(returnValue(true)); |
637 | ignoring (mockField); |
638 | }}); |
639 | |
640 | printer.visitField_info(mockField); |
641 | |
642 | String xmlDocument = buffer.toString(); |
643 | assertXPathCount(xmlDocument, "field-info/synthetic", 1); |
644 | } |
645 | |
646 | public void testNonEnumField() throws Exception { |
647 | final Field_info mockField = mock(Field_info.class); |
648 | |
649 | checking(new Expectations() {{ |
650 | one (mockField).isEnum(); will(returnValue(false)); |
651 | ignoring (mockField); |
652 | }}); |
653 | |
654 | printer.visitField_info(mockField); |
655 | |
656 | String xmlDocument = buffer.toString(); |
657 | assertXPathCount(xmlDocument, "field-info/enum", 0); |
658 | } |
659 | |
660 | public void testEnumField() throws Exception { |
661 | final Field_info mockField = mock(Field_info.class); |
662 | |
663 | checking(new Expectations() {{ |
664 | one (mockField).isEnum(); will(returnValue(true)); |
665 | ignoring (mockField); |
666 | }}); |
667 | |
668 | printer.visitField_info(mockField); |
669 | |
670 | String xmlDocument = buffer.toString(); |
671 | assertXPathCount(xmlDocument, "field-info/enum", 1); |
672 | } |
673 | |
674 | public void testNonPublicMethod() throws Exception { |
675 | final Method_info mockMethod = mock(Method_info.class); |
676 | |
677 | checking(new Expectations() {{ |
678 | one (mockMethod).isPublic(); will(returnValue(false)); |
679 | ignoring (mockMethod); |
680 | }}); |
681 | |
682 | printer.visitMethod_info(mockMethod); |
683 | |
684 | String xmlDocument = buffer.toString(); |
685 | assertXPathCount(xmlDocument, "method-info/public", 0); |
686 | } |
687 | |
688 | public void testPublicMethod() throws Exception { |
689 | final Method_info mockMethod = mock(Method_info.class); |
690 | |
691 | checking(new Expectations() {{ |
692 | one (mockMethod).isPublic(); will(returnValue(true)); |
693 | ignoring (mockMethod); |
694 | }}); |
695 | |
696 | printer.visitMethod_info(mockMethod); |
697 | |
698 | String xmlDocument = buffer.toString(); |
699 | assertXPathCount(xmlDocument, "method-info/public", 1); |
700 | } |
701 | |
702 | public void testNonPrivateMethod() throws Exception { |
703 | final Method_info mockMethod = mock(Method_info.class); |
704 | |
705 | checking(new Expectations() {{ |
706 | one (mockMethod).isPrivate(); will(returnValue(false)); |
707 | ignoring (mockMethod); |
708 | }}); |
709 | |
710 | printer.visitMethod_info(mockMethod); |
711 | |
712 | String xmlDocument = buffer.toString(); |
713 | assertXPathCount(xmlDocument, "method-info/private", 0); |
714 | } |
715 | |
716 | public void testPrivateMethod() throws Exception { |
717 | final Method_info mockMethod = mock(Method_info.class); |
718 | |
719 | checking(new Expectations() {{ |
720 | one (mockMethod).isPrivate(); will(returnValue(true)); |
721 | ignoring (mockMethod); |
722 | }}); |
723 | |
724 | printer.visitMethod_info(mockMethod); |
725 | |
726 | String xmlDocument = buffer.toString(); |
727 | assertXPathCount(xmlDocument, "method-info/private", 1); |
728 | } |
729 | |
730 | public void testNonProtectedMethod() throws Exception { |
731 | final Method_info mockMethod = mock(Method_info.class); |
732 | |
733 | checking(new Expectations() {{ |
734 | one (mockMethod).isProtected(); will(returnValue(false)); |
735 | ignoring (mockMethod); |
736 | }}); |
737 | |
738 | printer.visitMethod_info(mockMethod); |
739 | |
740 | String xmlDocument = buffer.toString(); |
741 | assertXPathCount(xmlDocument, "method-info/protected", 0); |
742 | } |
743 | |
744 | public void testProtectedMethod() throws Exception { |
745 | final Method_info mockMethod = mock(Method_info.class); |
746 | |
747 | checking(new Expectations() {{ |
748 | one (mockMethod).isProtected(); will(returnValue(true)); |
749 | ignoring (mockMethod); |
750 | }}); |
751 | |
752 | printer.visitMethod_info(mockMethod); |
753 | |
754 | String xmlDocument = buffer.toString(); |
755 | assertXPathCount(xmlDocument, "method-info/protected", 1); |
756 | } |
757 | |
758 | public void testNonStaticMethod() throws Exception { |
759 | final Method_info mockMethod = mock(Method_info.class); |
760 | |
761 | checking(new Expectations() {{ |
762 | one (mockMethod).isStatic(); will(returnValue(false)); |
763 | ignoring (mockMethod); |
764 | }}); |
765 | |
766 | printer.visitMethod_info(mockMethod); |
767 | |
768 | String xmlDocument = buffer.toString(); |
769 | assertXPathCount(xmlDocument, "method-info/static", 0); |
770 | } |
771 | |
772 | public void testStaticMethod() throws Exception { |
773 | final Method_info mockMethod = mock(Method_info.class); |
774 | |
775 | checking(new Expectations() {{ |
776 | one (mockMethod).isStatic(); will(returnValue(true)); |
777 | ignoring (mockMethod); |
778 | }}); |
779 | |
780 | printer.visitMethod_info(mockMethod); |
781 | |
782 | String xmlDocument = buffer.toString(); |
783 | assertXPathCount(xmlDocument, "method-info/static", 1); |
784 | } |
785 | |
786 | public void testNonFinalMethod() throws Exception { |
787 | final Method_info mockMethod = mock(Method_info.class); |
788 | |
789 | checking(new Expectations() {{ |
790 | one (mockMethod).isFinal(); will(returnValue(false)); |
791 | ignoring (mockMethod); |
792 | }}); |
793 | |
794 | printer.visitMethod_info(mockMethod); |
795 | |
796 | String xmlDocument = buffer.toString(); |
797 | assertXPathCount(xmlDocument, "method-info/final", 0); |
798 | } |
799 | |
800 | public void testFinalMethod() throws Exception { |
801 | final Method_info mockMethod = mock(Method_info.class); |
802 | |
803 | checking(new Expectations() {{ |
804 | one (mockMethod).isFinal(); will(returnValue(true)); |
805 | ignoring (mockMethod); |
806 | }}); |
807 | |
808 | printer.visitMethod_info(mockMethod); |
809 | |
810 | String xmlDocument = buffer.toString(); |
811 | assertXPathCount(xmlDocument, "method-info/final", 1); |
812 | } |
813 | |
814 | public void testNonSynchronizedMethod() throws Exception { |
815 | final Method_info mockMethod = mock(Method_info.class); |
816 | |
817 | checking(new Expectations() {{ |
818 | one (mockMethod).isSynchronized(); will(returnValue(false)); |
819 | ignoring (mockMethod); |
820 | }}); |
821 | |
822 | printer.visitMethod_info(mockMethod); |
823 | |
824 | String xmlDocument = buffer.toString(); |
825 | assertXPathCount(xmlDocument, "method-info/synchronized", 0); |
826 | } |
827 | |
828 | public void testSynchronizedMethod() throws Exception { |
829 | final Method_info mockMethod = mock(Method_info.class); |
830 | |
831 | checking(new Expectations() {{ |
832 | one (mockMethod).isSynchronized(); will(returnValue(true)); |
833 | ignoring (mockMethod); |
834 | }}); |
835 | |
836 | printer.visitMethod_info(mockMethod); |
837 | |
838 | String xmlDocument = buffer.toString(); |
839 | assertXPathCount(xmlDocument, "method-info/synchronized", 1); |
840 | } |
841 | |
842 | public void testNonBridgeMethod() throws Exception { |
843 | final Method_info mockMethod = mock(Method_info.class); |
844 | |
845 | checking(new Expectations() {{ |
846 | one (mockMethod).isBridge(); will(returnValue(false)); |
847 | ignoring (mockMethod); |
848 | }}); |
849 | |
850 | printer.visitMethod_info(mockMethod); |
851 | |
852 | String xmlDocument = buffer.toString(); |
853 | assertXPathCount(xmlDocument, "method-info/bridge", 0); |
854 | } |
855 | |
856 | public void testBridgeMethod() throws Exception { |
857 | final Method_info mockMethod = mock(Method_info.class); |
858 | |
859 | checking(new Expectations() {{ |
860 | one (mockMethod).isBridge(); will(returnValue(true)); |
861 | ignoring (mockMethod); |
862 | }}); |
863 | |
864 | printer.visitMethod_info(mockMethod); |
865 | |
866 | String xmlDocument = buffer.toString(); |
867 | assertXPathCount(xmlDocument, "method-info/bridge", 1); |
868 | } |
869 | |
870 | public void testNonVarargsMethod() throws Exception { |
871 | final Method_info mockMethod = mock(Method_info.class); |
872 | |
873 | checking(new Expectations() {{ |
874 | one (mockMethod).isVarargs(); will(returnValue(false)); |
875 | ignoring (mockMethod); |
876 | }}); |
877 | |
878 | printer.visitMethod_info(mockMethod); |
879 | |
880 | String xmlDocument = buffer.toString(); |
881 | assertXPathCount(xmlDocument, "method-info/varargs", 0); |
882 | } |
883 | |
884 | public void testVarargsMethod() throws Exception { |
885 | final Method_info mockMethod = mock(Method_info.class); |
886 | |
887 | checking(new Expectations() {{ |
888 | one (mockMethod).isVarargs(); will(returnValue(true)); |
889 | ignoring (mockMethod); |
890 | }}); |
891 | |
892 | printer.visitMethod_info(mockMethod); |
893 | |
894 | String xmlDocument = buffer.toString(); |
895 | assertXPathCount(xmlDocument, "method-info/varargs", 1); |
896 | } |
897 | |
898 | public void testNonNativeMethod() throws Exception { |
899 | final Method_info mockMethod = mock(Method_info.class); |
900 | |
901 | checking(new Expectations() {{ |
902 | one (mockMethod).isNative(); will(returnValue(false)); |
903 | ignoring (mockMethod); |
904 | }}); |
905 | |
906 | printer.visitMethod_info(mockMethod); |
907 | |
908 | String xmlDocument = buffer.toString(); |
909 | assertXPathCount(xmlDocument, "method-info/native", 0); |
910 | } |
911 | |
912 | public void testNativeMethod() throws Exception { |
913 | final Method_info mockMethod = mock(Method_info.class); |
914 | |
915 | checking(new Expectations() {{ |
916 | one (mockMethod).isNative(); will(returnValue(true)); |
917 | ignoring (mockMethod); |
918 | }}); |
919 | |
920 | printer.visitMethod_info(mockMethod); |
921 | |
922 | String xmlDocument = buffer.toString(); |
923 | assertXPathCount(xmlDocument, "method-info/native", 1); |
924 | } |
925 | |
926 | public void testNonAbstractMethod() throws Exception { |
927 | final Method_info mockMethod = mock(Method_info.class); |
928 | |
929 | checking(new Expectations() {{ |
930 | one (mockMethod).isAbstract(); will(returnValue(false)); |
931 | ignoring (mockMethod); |
932 | }}); |
933 | |
934 | printer.visitMethod_info(mockMethod); |
935 | |
936 | String xmlDocument = buffer.toString(); |
937 | assertXPathCount(xmlDocument, "method-info/abstract", 0); |
938 | } |
939 | |
940 | public void testAbstractMethod() throws Exception { |
941 | final Method_info mockMethod = mock(Method_info.class); |
942 | |
943 | checking(new Expectations() {{ |
944 | one (mockMethod).isAbstract(); will(returnValue(true)); |
945 | ignoring (mockMethod); |
946 | }}); |
947 | |
948 | printer.visitMethod_info(mockMethod); |
949 | |
950 | String xmlDocument = buffer.toString(); |
951 | assertXPathCount(xmlDocument, "method-info/abstract", 1); |
952 | } |
953 | |
954 | public void testNonStrictMethod() throws Exception { |
955 | final Method_info mockMethod = mock(Method_info.class); |
956 | |
957 | checking(new Expectations() {{ |
958 | one (mockMethod).isStrict(); will(returnValue(false)); |
959 | ignoring (mockMethod); |
960 | }}); |
961 | |
962 | printer.visitMethod_info(mockMethod); |
963 | |
964 | String xmlDocument = buffer.toString(); |
965 | assertXPathCount(xmlDocument, "method-info/strict", 0); |
966 | } |
967 | |
968 | public void testStrictMethod() throws Exception { |
969 | final Method_info mockMethod = mock(Method_info.class); |
970 | |
971 | checking(new Expectations() {{ |
972 | one (mockMethod).isStrict(); will(returnValue(true)); |
973 | ignoring (mockMethod); |
974 | }}); |
975 | |
976 | printer.visitMethod_info(mockMethod); |
977 | |
978 | String xmlDocument = buffer.toString(); |
979 | assertXPathCount(xmlDocument, "method-info/strict", 1); |
980 | } |
981 | |
982 | public void testNonSyntheticMethod() throws Exception { |
983 | final Method_info mockMethod = mock(Method_info.class); |
984 | |
985 | checking(new Expectations() {{ |
986 | one (mockMethod).isSynthetic(); will(returnValue(false)); |
987 | ignoring (mockMethod); |
988 | }}); |
989 | |
990 | printer.visitMethod_info(mockMethod); |
991 | |
992 | String xmlDocument = buffer.toString(); |
993 | assertXPathCount(xmlDocument, "method-info/synthetic", 0); |
994 | } |
995 | |
996 | public void testSyntheticMethod() throws Exception { |
997 | final Method_info mockMethod = mock(Method_info.class); |
998 | |
999 | checking(new Expectations() {{ |
1000 | one (mockMethod).isSynthetic(); will(returnValue(true)); |
1001 | ignoring (mockMethod); |
1002 | }}); |
1003 | |
1004 | printer.visitMethod_info(mockMethod); |
1005 | |
1006 | String xmlDocument = buffer.toString(); |
1007 | assertXPathCount(xmlDocument, "method-info/synthetic", 1); |
1008 | } |
1009 | |
1010 | public void testNonPublicInnerClass() throws Exception { |
1011 | final InnerClass mockInnerClass = mock(InnerClass.class); |
1012 | |
1013 | checking(new Expectations() {{ |
1014 | one (mockInnerClass).isPublic(); will(returnValue(false)); |
1015 | ignoring (mockInnerClass); |
1016 | }}); |
1017 | |
1018 | printer.visitInnerClass(mockInnerClass); |
1019 | |
1020 | String xmlDocument = buffer.toString(); |
1021 | assertXPathCount(xmlDocument, "inner-class/public", 0); |
1022 | } |
1023 | |
1024 | public void testPublicInnerClass() throws Exception { |
1025 | final InnerClass mockInnerClass = mock(InnerClass.class); |
1026 | |
1027 | checking(new Expectations() {{ |
1028 | one (mockInnerClass).isPublic(); will(returnValue(true)); |
1029 | ignoring (mockInnerClass); |
1030 | }}); |
1031 | |
1032 | printer.visitInnerClass(mockInnerClass); |
1033 | |
1034 | String xmlDocument = buffer.toString(); |
1035 | assertXPathCount(xmlDocument, "inner-class/public", 1); |
1036 | } |
1037 | |
1038 | public void testNonPrivateInnerClass() throws Exception { |
1039 | final InnerClass mockInnerClass = mock(InnerClass.class); |
1040 | |
1041 | checking(new Expectations() {{ |
1042 | one (mockInnerClass).isPrivate(); will(returnValue(false)); |
1043 | ignoring (mockInnerClass); |
1044 | }}); |
1045 | |
1046 | printer.visitInnerClass(mockInnerClass); |
1047 | |
1048 | String xmlDocument = buffer.toString(); |
1049 | assertXPathCount(xmlDocument, "inner-class/private", 0); |
1050 | } |
1051 | |
1052 | public void testPrivateInnerClass() throws Exception { |
1053 | final InnerClass mockInnerClass = mock(InnerClass.class); |
1054 | |
1055 | checking(new Expectations() {{ |
1056 | one (mockInnerClass).isPrivate(); will(returnValue(true)); |
1057 | ignoring (mockInnerClass); |
1058 | }}); |
1059 | |
1060 | printer.visitInnerClass(mockInnerClass); |
1061 | |
1062 | String xmlDocument = buffer.toString(); |
1063 | assertXPathCount(xmlDocument, "inner-class/private", 1); |
1064 | } |
1065 | |
1066 | public void testNonProtectedInnerClass() throws Exception { |
1067 | final InnerClass mockInnerClass = mock(InnerClass.class); |
1068 | |
1069 | checking(new Expectations() {{ |
1070 | one (mockInnerClass).isProtected(); will(returnValue(false)); |
1071 | ignoring (mockInnerClass); |
1072 | }}); |
1073 | |
1074 | printer.visitInnerClass(mockInnerClass); |
1075 | |
1076 | String xmlDocument = buffer.toString(); |
1077 | assertXPathCount(xmlDocument, "inner-class/protected", 0); |
1078 | } |
1079 | |
1080 | public void testProtectedInnerClass() throws Exception { |
1081 | final InnerClass mockInnerClass = mock(InnerClass.class); |
1082 | |
1083 | checking(new Expectations() {{ |
1084 | one (mockInnerClass).isProtected(); will(returnValue(true)); |
1085 | ignoring (mockInnerClass); |
1086 | }}); |
1087 | |
1088 | printer.visitInnerClass(mockInnerClass); |
1089 | |
1090 | String xmlDocument = buffer.toString(); |
1091 | assertXPathCount(xmlDocument, "inner-class/protected", 1); |
1092 | } |
1093 | |
1094 | public void testNonStaticInnerClass() throws Exception { |
1095 | final InnerClass mockInnerClass = mock(InnerClass.class); |
1096 | |
1097 | checking(new Expectations() {{ |
1098 | one (mockInnerClass).isStatic(); will(returnValue(false)); |
1099 | ignoring (mockInnerClass); |
1100 | }}); |
1101 | |
1102 | printer.visitInnerClass(mockInnerClass); |
1103 | |
1104 | String xmlDocument = buffer.toString(); |
1105 | assertXPathCount(xmlDocument, "inner-class/static", 0); |
1106 | } |
1107 | |
1108 | public void testStaticInnerClass() throws Exception { |
1109 | final InnerClass mockInnerClass = mock(InnerClass.class); |
1110 | |
1111 | checking(new Expectations() {{ |
1112 | one (mockInnerClass).isStatic(); will(returnValue(true)); |
1113 | ignoring (mockInnerClass); |
1114 | }}); |
1115 | |
1116 | printer.visitInnerClass(mockInnerClass); |
1117 | |
1118 | String xmlDocument = buffer.toString(); |
1119 | assertXPathCount(xmlDocument, "inner-class/static", 1); |
1120 | } |
1121 | |
1122 | public void testNonFinalInnerClass() throws Exception { |
1123 | final InnerClass mockInnerClass = mock(InnerClass.class); |
1124 | |
1125 | checking(new Expectations() {{ |
1126 | one (mockInnerClass).isFinal(); will(returnValue(false)); |
1127 | ignoring (mockInnerClass); |
1128 | }}); |
1129 | |
1130 | printer.visitInnerClass(mockInnerClass); |
1131 | |
1132 | String xmlDocument = buffer.toString(); |
1133 | assertXPathCount(xmlDocument, "inner-class/final", 0); |
1134 | } |
1135 | |
1136 | public void testFinalInnerClass() throws Exception { |
1137 | final InnerClass mockInnerClass = mock(InnerClass.class); |
1138 | |
1139 | checking(new Expectations() {{ |
1140 | one (mockInnerClass).isFinal(); will(returnValue(true)); |
1141 | ignoring (mockInnerClass); |
1142 | }}); |
1143 | |
1144 | printer.visitInnerClass(mockInnerClass); |
1145 | |
1146 | String xmlDocument = buffer.toString(); |
1147 | assertXPathCount(xmlDocument, "inner-class/final", 1); |
1148 | } |
1149 | |
1150 | public void testNonInterfaceInnerClass() throws Exception { |
1151 | final InnerClass mockInnerClass = mock(InnerClass.class); |
1152 | |
1153 | checking(new Expectations() {{ |
1154 | one (mockInnerClass).isInterface(); will(returnValue(false)); |
1155 | ignoring (mockInnerClass); |
1156 | }}); |
1157 | |
1158 | printer.visitInnerClass(mockInnerClass); |
1159 | |
1160 | String xmlDocument = buffer.toString(); |
1161 | assertXPathCount(xmlDocument, "inner-class/is-interface", 0); |
1162 | } |
1163 | |
1164 | public void testInterfaceInnerClass() throws Exception { |
1165 | final InnerClass mockInnerClass = mock(InnerClass.class); |
1166 | |
1167 | checking(new Expectations() {{ |
1168 | one (mockInnerClass).isInterface(); will(returnValue(true)); |
1169 | ignoring (mockInnerClass); |
1170 | }}); |
1171 | |
1172 | printer.visitInnerClass(mockInnerClass); |
1173 | |
1174 | String xmlDocument = buffer.toString(); |
1175 | assertXPathCount(xmlDocument, "inner-class/is-interface", 1); |
1176 | } |
1177 | |
1178 | public void testNonAbstractInnerClass() throws Exception { |
1179 | final InnerClass mockInnerClass = mock(InnerClass.class); |
1180 | |
1181 | checking(new Expectations() {{ |
1182 | one (mockInnerClass).isAbstract(); will(returnValue(false)); |
1183 | ignoring (mockInnerClass); |
1184 | }}); |
1185 | |
1186 | printer.visitInnerClass(mockInnerClass); |
1187 | |
1188 | String xmlDocument = buffer.toString(); |
1189 | assertXPathCount(xmlDocument, "inner-class/abstract", 0); |
1190 | } |
1191 | |
1192 | public void testAbstractInnerClass() throws Exception { |
1193 | final InnerClass mockInnerClass = mock(InnerClass.class); |
1194 | |
1195 | checking(new Expectations() {{ |
1196 | one (mockInnerClass).isAbstract(); will(returnValue(true)); |
1197 | ignoring (mockInnerClass); |
1198 | }}); |
1199 | |
1200 | printer.visitInnerClass(mockInnerClass); |
1201 | |
1202 | String xmlDocument = buffer.toString(); |
1203 | assertXPathCount(xmlDocument, "inner-class/abstract", 1); |
1204 | } |
1205 | |
1206 | public void testNonSyntheticInnerClass() throws Exception { |
1207 | final InnerClass mockInnerClass = mock(InnerClass.class); |
1208 | |
1209 | checking(new Expectations() {{ |
1210 | one (mockInnerClass).isSynthetic(); will(returnValue(false)); |
1211 | ignoring (mockInnerClass); |
1212 | }}); |
1213 | |
1214 | printer.visitInnerClass(mockInnerClass); |
1215 | |
1216 | String xmlDocument = buffer.toString(); |
1217 | assertXPathCount(xmlDocument, "inner-class/synthetic", 0); |
1218 | } |
1219 | |
1220 | public void testSyntheticInnerClass() throws Exception { |
1221 | final InnerClass mockInnerClass = mock(InnerClass.class); |
1222 | |
1223 | checking(new Expectations() {{ |
1224 | one (mockInnerClass).isSynthetic(); will(returnValue(true)); |
1225 | ignoring (mockInnerClass); |
1226 | }}); |
1227 | |
1228 | printer.visitInnerClass(mockInnerClass); |
1229 | |
1230 | String xmlDocument = buffer.toString(); |
1231 | assertXPathCount(xmlDocument, "inner-class/synthetic", 1); |
1232 | } |
1233 | |
1234 | public void testNonAnnotationInnerClass() throws Exception { |
1235 | final InnerClass mockInnerClass = mock(InnerClass.class); |
1236 | |
1237 | checking(new Expectations() {{ |
1238 | one (mockInnerClass).isAnnotation(); will(returnValue(false)); |
1239 | ignoring (mockInnerClass); |
1240 | }}); |
1241 | |
1242 | printer.visitInnerClass(mockInnerClass); |
1243 | |
1244 | String xmlDocument = buffer.toString(); |
1245 | assertXPathCount(xmlDocument, "inner-class/is-annotation", 0); |
1246 | } |
1247 | |
1248 | public void testAnnotationInnerClass() throws Exception { |
1249 | final InnerClass mockInnerClass = mock(InnerClass.class); |
1250 | |
1251 | checking(new Expectations() {{ |
1252 | one (mockInnerClass).isAnnotation(); will(returnValue(true)); |
1253 | ignoring (mockInnerClass); |
1254 | }}); |
1255 | |
1256 | printer.visitInnerClass(mockInnerClass); |
1257 | |
1258 | String xmlDocument = buffer.toString(); |
1259 | assertXPathCount(xmlDocument, "inner-class/is-annotation", 1); |
1260 | } |
1261 | |
1262 | public void testNonEnumInnerClass() throws Exception { |
1263 | final InnerClass mockInnerClass = mock(InnerClass.class); |
1264 | |
1265 | checking(new Expectations() {{ |
1266 | one (mockInnerClass).isEnum(); will(returnValue(false)); |
1267 | ignoring (mockInnerClass); |
1268 | }}); |
1269 | |
1270 | printer.visitInnerClass(mockInnerClass); |
1271 | |
1272 | String xmlDocument = buffer.toString(); |
1273 | assertXPathCount(xmlDocument, "inner-class/enum", 0); |
1274 | } |
1275 | |
1276 | public void testEnumInnerClass() throws Exception { |
1277 | final InnerClass mockInnerClass = mock(InnerClass.class); |
1278 | |
1279 | checking(new Expectations() {{ |
1280 | one (mockInnerClass).isEnum(); will(returnValue(true)); |
1281 | ignoring (mockInnerClass); |
1282 | }}); |
1283 | |
1284 | printer.visitInnerClass(mockInnerClass); |
1285 | |
1286 | String xmlDocument = buffer.toString(); |
1287 | assertXPathCount(xmlDocument, "inner-class/enum", 1); |
1288 | } |
1289 | |
1290 | public void testVisitLocalVariable() throws Exception { |
1291 | final LocalVariable localVariable = mock(LocalVariable.class); |
1292 | |
1293 | checking(new Expectations() {{ |
1294 | one (localVariable).getStartPC(); |
1295 | one (localVariable).getLength(); |
1296 | one (localVariable).getRawName(); |
1297 | one (localVariable).getDescriptor(); |
1298 | will(returnValue("I")); |
1299 | one (localVariable).getIndex(); |
1300 | }}); |
1301 | |
1302 | printer.visitLocalVariable(localVariable); |
1303 | |
1304 | String xmlDocument = buffer.toString(); |
1305 | assertXPathCount(xmlDocument, "local-variable/@pc", 1); |
1306 | assertXPathCount(xmlDocument, "local-variable/@length", 1); |
1307 | assertXPathCount(xmlDocument, "local-variable/name", 1); |
1308 | assertXPathText(xmlDocument, "local-variable/type", "int"); |
1309 | assertXPathCount(xmlDocument, "local-variable/@index", 1); |
1310 | } |
1311 | |
1312 | public void testVisitLocalVariableType() throws Exception { |
1313 | final LocalVariableType localVariableType = mock(LocalVariableType.class); |
1314 | |
1315 | checking(new Expectations() {{ |
1316 | one (localVariableType).getStartPC(); |
1317 | one (localVariableType).getLength(); |
1318 | one (localVariableType).getRawName(); |
1319 | one (localVariableType).getRawSignature(); |
1320 | one (localVariableType).getIndex(); |
1321 | }}); |
1322 | |
1323 | printer.visitLocalVariableType(localVariableType); |
1324 | |
1325 | String xmlDocument = buffer.toString(); |
1326 | assertXPathCount(xmlDocument, "local-variable-type/@pc", 1); |
1327 | assertXPathCount(xmlDocument, "local-variable-type/@length", 1); |
1328 | assertXPathCount(xmlDocument, "local-variable-type/name", 1); |
1329 | assertXPathCount(xmlDocument, "local-variable-type/signature", 1); |
1330 | assertXPathCount(xmlDocument, "local-variable-type/@index", 1); |
1331 | } |
1332 | |
1333 | public void testVisitRuntimeVisibleAnnotations_attribute_WithoutAnnotations() throws Exception { |
1334 | final RuntimeVisibleAnnotations_attribute runtimeVisibleAnnotations = mock(RuntimeVisibleAnnotations_attribute.class); |
1335 | |
1336 | checking(new Expectations() {{ |
1337 | atLeast(1).of (runtimeVisibleAnnotations).getAnnotations(); |
1338 | }}); |
1339 | |
1340 | printer.visitRuntimeVisibleAnnotations_attribute(runtimeVisibleAnnotations); |
1341 | |
1342 | String xmlDocument = buffer.toString(); |
1343 | assertXPathCount(xmlDocument, "runtime-visible-annotations-attribute/annotations", 1); |
1344 | } |
1345 | |
1346 | public void testVisitRuntimeVisibleAnnotations_attribute_WithAnAnnotation() throws Exception { |
1347 | final RuntimeVisibleAnnotations_attribute runtimeVisibleAnnotations = mock(RuntimeVisibleAnnotations_attribute.class); |
1348 | final Annotation annotation = mock(Annotation.class); |
1349 | |
1350 | checking(new Expectations() {{ |
1351 | atLeast(1).of (runtimeVisibleAnnotations).getAnnotations(); |
1352 | will(returnValue(Collections.singleton(annotation))); |
1353 | one (annotation).accept(printer); |
1354 | }}); |
1355 | |
1356 | printer.visitRuntimeVisibleAnnotations_attribute(runtimeVisibleAnnotations); |
1357 | |
1358 | String xmlDocument = buffer.toString(); |
1359 | assertXPathCount(xmlDocument, "runtime-visible-annotations-attribute/annotations", 1); |
1360 | } |
1361 | |
1362 | public void testVisitRuntimeInvisibleAnnotations_attribute_WithoutAnnotations() throws Exception { |
1363 | final RuntimeInvisibleAnnotations_attribute runtimeInvisibleAnnotations = mock(RuntimeInvisibleAnnotations_attribute.class); |
1364 | |
1365 | checking(new Expectations() {{ |
1366 | atLeast(1).of (runtimeInvisibleAnnotations).getAnnotations(); |
1367 | }}); |
1368 | |
1369 | printer.visitRuntimeInvisibleAnnotations_attribute(runtimeInvisibleAnnotations); |
1370 | |
1371 | String xmlDocument = buffer.toString(); |
1372 | assertXPathCount(xmlDocument, "runtime-invisible-annotations-attribute/annotations", 1); |
1373 | } |
1374 | |
1375 | public void testVisitRuntimeInvisibleAnnotations_attribute_WithAnAnnotation() throws Exception { |
1376 | final RuntimeInvisibleAnnotations_attribute runtimeInvisibleAnnotations = mock(RuntimeInvisibleAnnotations_attribute.class); |
1377 | final Annotation annotation = mock(Annotation.class); |
1378 | |
1379 | checking(new Expectations() {{ |
1380 | atLeast(1).of (runtimeInvisibleAnnotations).getAnnotations(); |
1381 | will(returnValue(Collections.singleton(annotation))); |
1382 | one (annotation).accept(printer); |
1383 | }}); |
1384 | |
1385 | printer.visitRuntimeInvisibleAnnotations_attribute(runtimeInvisibleAnnotations); |
1386 | |
1387 | String xmlDocument = buffer.toString(); |
1388 | assertXPathCount(xmlDocument, "runtime-invisible-annotations-attribute/annotations", 1); |
1389 | } |
1390 | |
1391 | public void testVisitRuntimeVisibleParameterAnnotations_attribute_WithoutParameterAnnotations() throws Exception { |
1392 | final RuntimeVisibleParameterAnnotations_attribute runtimeVisibleParameterAnnotations = mock(RuntimeVisibleParameterAnnotations_attribute.class); |
1393 | |
1394 | checking(new Expectations() {{ |
1395 | atLeast(1).of (runtimeVisibleParameterAnnotations).getParameterAnnotations(); |
1396 | }}); |
1397 | |
1398 | printer.visitRuntimeVisibleParameterAnnotations_attribute(runtimeVisibleParameterAnnotations); |
1399 | |
1400 | String xmlDocument = buffer.toString(); |
1401 | assertXPathCount(xmlDocument, "runtime-visible-parameter-annotations-attribute/parameter-annotations", 1); |
1402 | } |
1403 | |
1404 | public void testVisitRuntimeVisibleParameterAnnotations_attribute_WithAParameterAnnotation() throws Exception { |
1405 | final RuntimeVisibleParameterAnnotations_attribute runtimeVisibleParameterAnnotations = mock(RuntimeVisibleParameterAnnotations_attribute.class); |
1406 | final Parameter parameter = mock(Parameter.class); |
1407 | |
1408 | checking(new Expectations() {{ |
1409 | atLeast(1).of (runtimeVisibleParameterAnnotations).getParameterAnnotations(); |
1410 | will(returnValue(Collections.singletonList(parameter))); |
1411 | one (parameter).accept(printer); |
1412 | }}); |
1413 | |
1414 | printer.visitRuntimeVisibleParameterAnnotations_attribute(runtimeVisibleParameterAnnotations); |
1415 | |
1416 | String xmlDocument = buffer.toString(); |
1417 | assertXPathCount(xmlDocument, "runtime-visible-parameter-annotations-attribute/parameter-annotations", 1); |
1418 | } |
1419 | |
1420 | public void testVisitRuntimeInvisibleParameterAnnotations_attribute_WithoutParameterAnnotations() throws Exception { |
1421 | final RuntimeInvisibleParameterAnnotations_attribute runtimeInvisibleParameterAnnotations = mock(RuntimeInvisibleParameterAnnotations_attribute.class); |
1422 | |
1423 | checking(new Expectations() {{ |
1424 | atLeast(1).of (runtimeInvisibleParameterAnnotations).getParameterAnnotations(); |
1425 | }}); |
1426 | |
1427 | printer.visitRuntimeInvisibleParameterAnnotations_attribute(runtimeInvisibleParameterAnnotations); |
1428 | |
1429 | String xmlDocument = buffer.toString(); |
1430 | assertXPathCount(xmlDocument, "runtime-invisible-parameter-annotations-attribute/parameter-annotations", 1); |
1431 | } |
1432 | |
1433 | public void testVisitRuntimeInvisibleParameterAnnotations_attribute_WithAParameterAnnotation() throws Exception { |
1434 | final RuntimeInvisibleParameterAnnotations_attribute runtimeInvisibleParameterAnnotations = mock(RuntimeInvisibleParameterAnnotations_attribute.class); |
1435 | final Parameter parameter = mock(Parameter.class); |
1436 | |
1437 | checking(new Expectations() {{ |
1438 | atLeast(1).of (runtimeInvisibleParameterAnnotations).getParameterAnnotations(); |
1439 | will(returnValue(Collections.singletonList(parameter))); |
1440 | one (parameter).accept(printer); |
1441 | }}); |
1442 | |
1443 | printer.visitRuntimeInvisibleParameterAnnotations_attribute(runtimeInvisibleParameterAnnotations); |
1444 | |
1445 | String xmlDocument = buffer.toString(); |
1446 | assertXPathCount(xmlDocument, "runtime-invisible-parameter-annotations-attribute/parameter-annotations", 1); |
1447 | } |
1448 | |
1449 | public void testVisitAnnotationDefault_attribute() throws Exception { |
1450 | final AnnotationDefault_attribute annotationDefault = mock(AnnotationDefault_attribute.class); |
1451 | final ElementValue elementValue = mock(ElementValue.class); |
1452 | |
1453 | checking(new Expectations() {{ |
1454 | atLeast(1).of (annotationDefault).getElemementValue(); |
1455 | will(returnValue(elementValue)); |
1456 | one (elementValue).accept(printer); |
1457 | }}); |
1458 | |
1459 | printer.visitAnnotationDefault_attribute(annotationDefault); |
1460 | |
1461 | String xmlDocument = buffer.toString(); |
1462 | assertXPathCount(xmlDocument, "annotation-default-attribute", 1); |
1463 | } |
1464 | |
1465 | public void testVisitParameter_WithoutAnnotations() throws Exception { |
1466 | final Parameter parameter = mock(Parameter.class); |
1467 | |
1468 | checking(new Expectations() {{ |
1469 | atLeast(1).of (parameter).getAnnotations(); |
1470 | }}); |
1471 | |
1472 | printer.visitParameter(parameter); |
1473 | |
1474 | String xmlDocument = buffer.toString(); |
1475 | assertXPathCount(xmlDocument, "parameter", 1); |
1476 | assertXPathCount(xmlDocument, "parameter/annotations", 1); |
1477 | } |
1478 | |
1479 | public void testVisitParameter_WithAnAnnotation() throws Exception { |
1480 | final Parameter parameter = mock(Parameter.class); |
1481 | final Annotation annotation = mock(Annotation.class); |
1482 | |
1483 | checking(new Expectations() {{ |
1484 | atLeast(1).of (parameter).getAnnotations(); |
1485 | will(returnValue(Collections.singleton(annotation))); |
1486 | one (annotation).accept(printer); |
1487 | }}); |
1488 | |
1489 | printer.visitParameter(parameter); |
1490 | |
1491 | String xmlDocument = buffer.toString(); |
1492 | assertXPathCount(xmlDocument, "parameter", 1); |
1493 | assertXPathCount(xmlDocument, "parameter/annotations", 1); |
1494 | } |
1495 | |
1496 | public void testVisitAnnotation_WithoutElementValuePairs() throws Exception { |
1497 | final Annotation annotation = mock(Annotation.class); |
1498 | |
1499 | checking(new Expectations() {{ |
1500 | atLeast(1).of (annotation).getType(); |
1501 | will(returnValue(ANNOTATION_TYPE)); |
1502 | atLeast(1).of (annotation).getElementValuePairs(); |
1503 | }}); |
1504 | |
1505 | printer.visitAnnotation(annotation); |
1506 | |
1507 | String xmlDocument = buffer.toString(); |
1508 | assertXPathCount(xmlDocument, "annotation", 1); |
1509 | assertXPathText(xmlDocument, "annotation/type", ANNOTATION_TYPE); |
1510 | assertXPathCount(xmlDocument, "annotation/element-value-pairs", 1); |
1511 | } |
1512 | |
1513 | public void testVisitAnnotation_WithAnElementValuePair() throws Exception { |
1514 | final Annotation annotation = mock(Annotation.class); |
1515 | final ElementValuePair elementValuePair = mock(ElementValuePair.class); |
1516 | |
1517 | checking(new Expectations() {{ |
1518 | atLeast(1).of (annotation).getType(); |
1519 | will(returnValue(ANNOTATION_TYPE)); |
1520 | atLeast(1).of (annotation).getElementValuePairs(); |
1521 | will(returnValue(Collections.singleton(elementValuePair))); |
1522 | one (elementValuePair).accept(printer); |
1523 | }}); |
1524 | |
1525 | printer.visitAnnotation(annotation); |
1526 | |
1527 | String xmlDocument = buffer.toString(); |
1528 | assertXPathCount(xmlDocument, "annotation", 1); |
1529 | assertXPathText(xmlDocument, "annotation/type", ANNOTATION_TYPE); |
1530 | assertXPathCount(xmlDocument, "annotation/element-value-pairs", 1); |
1531 | } |
1532 | |
1533 | public void testVisitElementValuePair() throws Exception { |
1534 | final ElementValuePair elementValuePair = mock(ElementValuePair.class); |
1535 | final ElementValue elementValue = mock(ElementValue.class); |
1536 | |
1537 | checking(new Expectations() {{ |
1538 | one (elementValuePair).getElementName(); |
1539 | will(returnValue(ELEMENT_NAME)); |
1540 | one (elementValuePair).getElementValue(); |
1541 | will(returnValue(elementValue)); |
1542 | one (elementValue).accept(printer); |
1543 | }}); |
1544 | |
1545 | printer.visitElementValuePair(elementValuePair); |
1546 | |
1547 | String xmlDocument = buffer.toString(); |
1548 | assertXPathCount(xmlDocument, "element-value-pair", 1); |
1549 | assertXPathText(xmlDocument, "element-value-pair/element-name", ELEMENT_NAME); |
1550 | } |
1551 | |
1552 | public void testVisitByteConstantElementValue() throws Exception { |
1553 | final ByteConstantElementValue constantElementValue = mock(ByteConstantElementValue.class); |
1554 | final ConstantPoolEntry constantPoolEntry = mock(ConstantPoolEntry.class); |
1555 | |
1556 | checking(new Expectations() {{ |
1557 | one (constantElementValue).getTag(); |
1558 | will(returnValue(ElementValueType.BYTE.getTag())); |
1559 | one (constantElementValue).getRawConstValue(); |
1560 | will(returnValue(constantPoolEntry)); |
1561 | one (constantPoolEntry).accept(printer); |
1562 | }}); |
1563 | |
1564 | printer.visitByteConstantElementValue(constantElementValue); |
1565 | |
1566 | String xmlDocument = buffer.toString(); |
1567 | assertXPathCount(xmlDocument, "byte-element-value", 1); |
1568 | assertXPathText(xmlDocument, "byte-element-value/@tag", String.valueOf(ElementValueType.BYTE.getTag())); |
1569 | } |
1570 | |
1571 | public void testVisitCharConstantElementValue() throws Exception { |
1572 | final CharConstantElementValue constantElementValue = mock(CharConstantElementValue.class); |
1573 | final ConstantPoolEntry constantPoolEntry = mock(ConstantPoolEntry.class); |
1574 | |
1575 | checking(new Expectations() {{ |
1576 | one (constantElementValue).getTag(); |
1577 | will(returnValue(ElementValueType.CHAR.getTag())); |
1578 | one (constantElementValue).getRawConstValue(); |
1579 | will(returnValue(constantPoolEntry)); |
1580 | one (constantPoolEntry).accept(printer); |
1581 | }}); |
1582 | |
1583 | printer.visitCharConstantElementValue(constantElementValue); |
1584 | |
1585 | String xmlDocument = buffer.toString(); |
1586 | assertXPathCount(xmlDocument, "char-element-value", 1); |
1587 | assertXPathText(xmlDocument, "char-element-value/@tag", String.valueOf(ElementValueType.CHAR.getTag())); |
1588 | } |
1589 | |
1590 | public void testVisitDoubleConstantElementValue() throws Exception { |
1591 | final DoubleConstantElementValue constantElementValue = mock(DoubleConstantElementValue.class); |
1592 | final ConstantPoolEntry constantPoolEntry = mock(ConstantPoolEntry.class); |
1593 | |
1594 | checking(new Expectations() {{ |
1595 | one (constantElementValue).getTag(); |
1596 | will(returnValue(ElementValueType.DOUBLE.getTag())); |
1597 | one (constantElementValue).getRawConstValue(); |
1598 | will(returnValue(constantPoolEntry)); |
1599 | one (constantPoolEntry).accept(printer); |
1600 | }}); |
1601 | |
1602 | printer.visitDoubleConstantElementValue(constantElementValue); |
1603 | |
1604 | String xmlDocument = buffer.toString(); |
1605 | assertXPathCount(xmlDocument, "double-element-value", 1); |
1606 | assertXPathText(xmlDocument, "double-element-value/@tag", String.valueOf(ElementValueType.DOUBLE.getTag())); |
1607 | } |
1608 | |
1609 | public void testVisitFloatConstantElementValue() throws Exception { |
1610 | final FloatConstantElementValue constantElementValue = mock(FloatConstantElementValue.class); |
1611 | final ConstantPoolEntry constantPoolEntry = mock(ConstantPoolEntry.class); |
1612 | |
1613 | checking(new Expectations() {{ |
1614 | one (constantElementValue).getTag(); |
1615 | will(returnValue(ElementValueType.FLOAT.getTag())); |
1616 | one (constantElementValue).getRawConstValue(); |
1617 | will(returnValue(constantPoolEntry)); |
1618 | one (constantPoolEntry).accept(printer); |
1619 | }}); |
1620 | |
1621 | printer.visitFloatConstantElementValue(constantElementValue); |
1622 | |
1623 | String xmlDocument = buffer.toString(); |
1624 | assertXPathCount(xmlDocument, "float-element-value", 1); |
1625 | assertXPathText(xmlDocument, "float-element-value/@tag", String.valueOf(ElementValueType.FLOAT.getTag())); |
1626 | } |
1627 | |
1628 | public void testVisitIntegerConstantElementValue() throws Exception { |
1629 | final IntegerConstantElementValue constantElementValue = mock(IntegerConstantElementValue.class); |
1630 | final ConstantPoolEntry constantPoolEntry = mock(ConstantPoolEntry.class); |
1631 | |
1632 | checking(new Expectations() {{ |
1633 | one (constantElementValue).getTag(); |
1634 | will(returnValue(ElementValueType.INTEGER.getTag())); |
1635 | one (constantElementValue).getRawConstValue(); |
1636 | will(returnValue(constantPoolEntry)); |
1637 | one (constantPoolEntry).accept(printer); |
1638 | }}); |
1639 | |
1640 | printer.visitIntegerConstantElementValue(constantElementValue); |
1641 | |
1642 | String xmlDocument = buffer.toString(); |
1643 | assertXPathCount(xmlDocument, "integer-element-value", 1); |
1644 | assertXPathText(xmlDocument, "integer-element-value/@tag", String.valueOf(ElementValueType.INTEGER.getTag())); |
1645 | } |
1646 | |
1647 | public void testVisitLongConstantElementValue() throws Exception { |
1648 | final LongConstantElementValue constantElementValue = mock(LongConstantElementValue.class); |
1649 | final ConstantPoolEntry constantPoolEntry = mock(ConstantPoolEntry.class); |
1650 | |
1651 | checking(new Expectations() {{ |
1652 | one (constantElementValue).getTag(); |
1653 | will(returnValue(ElementValueType.LONG.getTag())); |
1654 | one (constantElementValue).getRawConstValue(); |
1655 | will(returnValue(constantPoolEntry)); |
1656 | one (constantPoolEntry).accept(printer); |
1657 | }}); |
1658 | |
1659 | printer.visitLongConstantElementValue(constantElementValue); |
1660 | |
1661 | String xmlDocument = buffer.toString(); |
1662 | assertXPathCount(xmlDocument, "long-element-value", 1); |
1663 | assertXPathText(xmlDocument, "long-element-value/@tag", String.valueOf(ElementValueType.LONG.getTag())); |
1664 | } |
1665 | |
1666 | public void testVisitShortConstantElementValue() throws Exception { |
1667 | final ShortConstantElementValue constantElementValue = mock(ShortConstantElementValue.class); |
1668 | final ConstantPoolEntry constantPoolEntry = mock(ConstantPoolEntry.class); |
1669 | |
1670 | checking(new Expectations() {{ |
1671 | one (constantElementValue).getTag(); |
1672 | will(returnValue(ElementValueType.SHORT.getTag())); |
1673 | one (constantElementValue).getRawConstValue(); |
1674 | will(returnValue(constantPoolEntry)); |
1675 | one (constantPoolEntry).accept(printer); |
1676 | }}); |
1677 | |
1678 | printer.visitShortConstantElementValue(constantElementValue); |
1679 | |
1680 | String xmlDocument = buffer.toString(); |
1681 | assertXPathCount(xmlDocument, "short-element-value", 1); |
1682 | assertXPathText(xmlDocument, "short-element-value/@tag", String.valueOf(ElementValueType.SHORT.getTag())); |
1683 | } |
1684 | |
1685 | public void testVisitBooleanConstantElementValue() throws Exception { |
1686 | final BooleanConstantElementValue constantElementValue = mock(BooleanConstantElementValue.class); |
1687 | final ConstantPoolEntry constantPoolEntry = mock(ConstantPoolEntry.class); |
1688 | |
1689 | checking(new Expectations() {{ |
1690 | one (constantElementValue).getTag(); |
1691 | will(returnValue(ElementValueType.BOOLEAN.getTag())); |
1692 | one (constantElementValue).getRawConstValue(); |
1693 | will(returnValue(constantPoolEntry)); |
1694 | one (constantPoolEntry).accept(printer); |
1695 | }}); |
1696 | |
1697 | printer.visitBooleanConstantElementValue(constantElementValue); |
1698 | |
1699 | String xmlDocument = buffer.toString(); |
1700 | assertXPathCount(xmlDocument, "boolean-element-value", 1); |
1701 | assertXPathText(xmlDocument, "boolean-element-value/@tag", String.valueOf(ElementValueType.BOOLEAN.getTag())); |
1702 | } |
1703 | |
1704 | public void testVisitStringConstantElementValue() throws Exception { |
1705 | final StringConstantElementValue constantElementValue = mock(StringConstantElementValue.class); |
1706 | final ConstantPoolEntry constantPoolEntry = mock(ConstantPoolEntry.class); |
1707 | |
1708 | checking(new Expectations() {{ |
1709 | one (constantElementValue).getTag(); |
1710 | will(returnValue(ElementValueType.STRING.getTag())); |
1711 | one (constantElementValue).getRawConstValue(); |
1712 | will(returnValue(constantPoolEntry)); |
1713 | one (constantPoolEntry).accept(printer); |
1714 | }}); |
1715 | |
1716 | printer.visitStringConstantElementValue(constantElementValue); |
1717 | |
1718 | String xmlDocument = buffer.toString(); |
1719 | assertXPathCount(xmlDocument, "string-element-value", 1); |
1720 | assertXPathText(xmlDocument, "string-element-value/@tag", String.valueOf(ElementValueType.STRING.getTag())); |
1721 | } |
1722 | |
1723 | public void testVisitEnumElementValue() throws Exception { |
1724 | final EnumElementValue enumElementValue = mock(EnumElementValue.class); |
1725 | final String constName = "BAR"; |
1726 | |
1727 | checking(new Expectations() {{ |
1728 | one (enumElementValue).getTag(); |
1729 | will(returnValue(ElementValueType.ENUM.getTag())); |
1730 | one (enumElementValue).getTypeName(); |
1731 | will(returnValue(TEST_CLASS)); |
1732 | one (enumElementValue).getConstName(); |
1733 | will(returnValue(constName)); |
1734 | }}); |
1735 | |
1736 | printer.visitEnumElementValue(enumElementValue); |
1737 | |
1738 | String xmlDocument = buffer.toString(); |
1739 | assertXPathText(xmlDocument, "enum-element-value", TEST_CLASS + "." + constName); |
1740 | assertXPathText(xmlDocument, "enum-element-value/@tag", String.valueOf(ElementValueType.ENUM.getTag())); |
1741 | } |
1742 | |
1743 | public void testVisitClassElementValue() throws Exception { |
1744 | final ClassElementValue classElementValue = mock(ClassElementValue.class); |
1745 | |
1746 | checking(new Expectations() {{ |
1747 | one (classElementValue).getTag(); |
1748 | will(returnValue(ElementValueType.CLASS.getTag())); |
1749 | one (classElementValue).getClassInfo(); |
1750 | will(returnValue(TEST_CLASS)); |
1751 | }}); |
1752 | |
1753 | printer.visitClassElementValue(classElementValue); |
1754 | |
1755 | String xmlDocument = buffer.toString(); |
1756 | assertXPathText(xmlDocument, "class-element-value", TEST_CLASS); |
1757 | assertXPathText(xmlDocument, "class-element-value/@tag", String.valueOf(ElementValueType.CLASS.getTag())); |
1758 | } |
1759 | |
1760 | public void testVisitAnnotationElementValue() throws Exception { |
1761 | final AnnotationElementValue annotationElementValue = mock(AnnotationElementValue.class); |
1762 | final Annotation annotation = mock(Annotation.class); |
1763 | |
1764 | checking(new Expectations() {{ |
1765 | one (annotationElementValue).getTag(); |
1766 | will(returnValue(ElementValueType.ANNOTATION.getTag())); |
1767 | one (annotationElementValue).getAnnotation(); |
1768 | will(returnValue(annotation)); |
1769 | one (annotation).accept(printer); |
1770 | }}); |
1771 | |
1772 | printer.visitAnnotationElementValue(annotationElementValue); |
1773 | |
1774 | String xmlDocument = buffer.toString(); |
1775 | assertXPathCount(xmlDocument, "annotation-element-value", 1); |
1776 | assertXPathText(xmlDocument, "annotation-element-value/@tag", String.valueOf(ElementValueType.ANNOTATION.getTag())); |
1777 | } |
1778 | |
1779 | public void testVisitArrayElementValue() throws Exception { |
1780 | final ArrayElementValue arrayElementValue = mock(ArrayElementValue.class); |
1781 | final ElementValue elementValue = mock(ElementValue.class); |
1782 | |
1783 | checking(new Expectations() {{ |
1784 | one (arrayElementValue).getTag(); |
1785 | will(returnValue(ElementValueType.ARRAY.getTag())); |
1786 | atLeast(1).of (arrayElementValue).getValues(); |
1787 | will(returnValue(Collections.singleton(elementValue))); |
1788 | one (elementValue).accept(printer); |
1789 | }}); |
1790 | |
1791 | printer.visitArrayElementValue(arrayElementValue); |
1792 | |
1793 | String xmlDocument = buffer.toString(); |
1794 | assertXPathCount(xmlDocument, "array-element-value", 1); |
1795 | assertXPathText(xmlDocument, "array-element-value/@tag", String.valueOf(ElementValueType.ARRAY.getTag())); |
1796 | } |
1797 | |
1798 | private void assertXPathCount(String xmlDocument, String xPathExpression, int expectedCount) throws Exception { |
1799 | XPath xPath = XPathFactory.newInstance().newXPath(); |
1800 | InputSource in = new InputSource(new StringReader(xmlDocument)); |
1801 | |
1802 | NodeList nodeList = (NodeList) xPath.evaluate(xPathExpression, in, XPathConstants.NODESET); |
1803 | int actualCount = nodeList.getLength(); |
1804 | assertEquals("XPath \"" + xPathExpression + "\" in \n" + xmlDocument, expectedCount, actualCount); |
1805 | } |
1806 | |
1807 | private void assertXPathText(String xmlDocument, String xPathExpression, String expectedText) throws Exception { |
1808 | XPath xPath = XPathFactory.newInstance().newXPath(); |
1809 | InputSource in = new InputSource(new StringReader(xmlDocument)); |
1810 | |
1811 | String actualText = (String) xPath.evaluate(xPathExpression, in, XPathConstants.STRING); |
1812 | assertEquals("XPath \"" + xPathExpression + "\" in \n" + xmlDocument, expectedText, actualText); |
1813 | } |
1814 | } |