01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
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: * Test for <code>BeanWriter</code>
29: * @author <a href='http://jakarta.apache.org/'>Jakarta Commons Team</a>
30: * @version $Revision: 438373 $
31: */
32: public class TestBeanWriter extends TestCase {
33:
34: public void testSetEndTagForEmptyElementTrue() throws Exception {
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(context, null, null, "element",
46: new AttributesImpl());
47: writer.endElement(context, null, null, "element");
48: assertEquals("<element></element>" + writer.getEndOfLine(), out
49: .getBuffer().toString());
50: }
51:
52: public void testSetEndTagForEmptyElementFalse() throws Exception {
53: StringWriter out = new StringWriter();
54: BeanWriter writer = new BeanWriter(out);
55: writer.setEndTagForEmptyElement(false);
56: WriteContext context = new WriteContext() {
57:
58: public ElementDescriptor getCurrentDescriptor() {
59: return null;
60: }
61:
62: };
63: writer.startElement(context, null, null, "element",
64: new AttributesImpl());
65: writer.endElement(context, null, null, "element");
66: assertEquals("<element/>" + writer.getEndOfLine(), out
67: .getBuffer().toString());
68: }
69: }
|