1   /*
2    * Copyright 2004 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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  }