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