KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cactus > internal > server > runner > TestXMLFormatter


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

20 package org.apache.cactus.internal.server.runner;
21
22 import junit.framework.TestCase;
23 import junit.framework.TestResult;
24
25 /**
26  * Unit tests for {@link XMLFormatter}.
27  *
28  * @version $Id: TestXMLFormatter.java,v 1.1 2004/05/22 11:34:50 vmassol Exp $
29  */

30 public final class TestXMLFormatter extends TestCase
31 {
32     /**
33      * Instance to unit test
34      */

35     private XMLFormatter formatter;
36    
37     /**
38      * TestResult object used for testing
39      */

40     private TestResult testResult;
41     
42     /**
43      * Set up common mock behaviors.
44      */

45     public void setUp()
46     {
47         formatter = new XMLFormatter();
48         testResult = new TestResult();
49     }
50
51     /**
52      * Verify that calling {@link XMLFormatter#toXML(TestResult)} works
53      * when using the default encoding.
54      */

55     public void testToXmlEmptyWithDefaultEncoding()
56     {
57         String JavaDoc expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
58             + "<testsuites><testsuite name=\"null\" tests=\"0\" failures=\"0\""
59             + " errors=\"0\" time=\"0\"></testsuite></testsuites>";
60         
61         String JavaDoc result = formatter.toXML(testResult);
62         assertEquals(expected, result);
63     }
64
65     /**
66      * Verify that calling {@link XMLFormatter#toXML(TestResult)} works
67      * when using a custom encoding of ISO-8859-1.
68      */

69     public void testToXmlEmptyWithCustomEncoding()
70     {
71         String JavaDoc expected = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>"
72         + "<testsuites><testsuite name=\"null\" tests=\"0\" failures=\"0\""
73         + " errors=\"0\" time=\"0\"></testsuite></testsuites>";
74         
75         formatter.setEncoding("ISO-8859-1");
76         String JavaDoc result = formatter.toXML(testResult);
77         assertEquals(expected, result);
78     }
79 }
80
Popular Tags