1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.betwixt.io;
18
19 import java.io.StringWriter;
20
21 import org.apache.commons.betwixt.ElementDescriptor;
22 import org.xml.sax.helpers.AttributesImpl;
23
24 import junit.framework.TestCase;
25
26 /***
27 * Test for <code>BeanWriter</code>
28 * @author <a href='http://jakarta.apache.org/'>Jakarta Commons Team</a>
29 * @version $Revision: 155402 $
30 */
31 public class TestBeanWriter extends TestCase {
32
33 public void testSetEndTagForEmptyElementTrue() throws Exception
34 {
35 StringWriter out = new StringWriter();
36 BeanWriter writer = new BeanWriter(out);
37 writer.setEndTagForEmptyElement(true);
38 WriteContext context = new WriteContext() {
39
40 public ElementDescriptor getCurrentDescriptor() {
41 return null;
42 }
43
44 };
45 writer.startElement(
46 context,
47 null,
48 null,
49 "element",
50 new AttributesImpl());
51 writer.endElement(
52 context,
53 null,
54 null,
55 "element");
56 assertEquals("<element></element>\n", out.getBuffer().toString());
57 }
58
59
60 public void testSetEndTagForEmptyElementFalse() throws Exception
61 {
62 StringWriter out = new StringWriter();
63 BeanWriter writer = new BeanWriter(out);
64 writer.setEndTagForEmptyElement(false);
65 WriteContext context = new WriteContext() {
66
67 public ElementDescriptor getCurrentDescriptor() {
68 return null;
69 }
70
71 };
72 writer.startElement(
73 context,
74 null,
75 null,
76 "element",
77 new AttributesImpl());
78 writer.endElement(
79 context,
80 null,
81 null,
82 "element");
83 assertEquals("<element/>\n", out.getBuffer().toString());
84 }
85 }