~ubuntu-branches/ubuntu/precise/xom/precise

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/* Copyright 2003-2005 Elliotte Rusty Harold
   
   This library is free software; you can redistribute it and/or modify
   it under the terms of version 2.1 of the GNU Lesser General Public 
   License as published by the Free Software Foundation.
   
   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
   GNU Lesser General Public License for more details.
   
   You should have received a copy of the GNU Lesser General Public
   License along with this library; if not, write to the 
   Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
   Boston, MA 02111-1307  USA
   
   You can contact Elliotte Rusty Harold by sending e-mail to
   elharo@metalab.unc.edu. Please include the word "XOM" in the
   subject line. The XOM home page is located at http://www.xom.nu/
*/

package nu.xom.tests;

import nu.xom.xinclude.BadEncodingAttributeException;
import nu.xom.xinclude.BadParseAttributeException;
import nu.xom.xinclude.MisplacedFallbackException;
import nu.xom.xinclude.NoIncludeLocationException;
import nu.xom.xinclude.XIncludeException;

/**
 * <p>
 *   Unit tests for the <code>XIncludeException</code> class.
 * </p>
 * 
 * @author Elliotte Rusty Harold
 * @version 1.1b3
 *
 */
public class XIncludeExceptionTest extends XOMTestCase {
    
    private XIncludeException ex;
    private Exception cause;
    
    
    public XIncludeExceptionTest(String name) {
        super(name);
    }

    
    protected void setUp() {
        ex = new XIncludeException("message");
        cause = new Exception();
    }
    
    
    public void testConstructor() {
        ex = new XIncludeException("test", "http://ex.com/");
        assertEquals("test", ex.getMessage());
        assertEquals("http://ex.com/", ex.getURI());
    }

    
    public void testInitCause() {
        
        assertNull(ex.getCause());
        ex.initCause(cause);
        assertEquals(cause, ex.getCause());
        
        try {
            ex.initCause(null);   
            fail("Reinitialized cause over null");   
        }
        catch (IllegalStateException result) {
            // success   
        }
        
        try {
            ex.initCause(new Exception());   
            fail("Reinitialized cause over null");   
        }
        catch (IllegalStateException result) {
            // success   
        }
        
    }


    public void testNullInitCause() {
        
        XIncludeException ex
          = new XIncludeException("message", (Exception) null);
        assertNull(ex.getCause());
        
        try {
            ex.initCause(new Exception());
            fail("Reinitialized cause over null");   
        }
        catch (IllegalStateException result) {
            // success   
        }

        try {
            ex.initCause(null);   
            fail("Reinitialized cause over null");   
        }
        catch (IllegalStateException result) {
            // success   
        }
        
    }

    
    public void testSelfCause() {
        
        try {
            ex.initCause(ex);   
            fail("Allowed self-causation");   
        }
        catch (IllegalArgumentException success) {
            // success   
        }
        
    }

    
    public void testGetMessage() {      
        Exception ex = new XIncludeException("testing");
        assertEquals("testing", ex.getMessage());
    }
    
    
    public void testMisplacedFallbackException() {
        String message = "message";
        Exception ex = new MisplacedFallbackException(message);
        assertEquals(message, ex.getMessage());
    }

    
    public void testBadParseAttributeException() {
        String message = "message";
        Exception ex = new BadParseAttributeException(message);
        assertEquals(message, ex.getMessage());
    }

    
    public void testBadEncodingAttributeException() {
        String message = "message";
        Exception ex = new BadEncodingAttributeException(message);
        assertEquals(message, ex.getMessage());
    }

    
    public void testNoIncludeLocationException() {
        
        String message = "message";
        XIncludeException ex = new NoIncludeLocationException(message);
        assertEquals(message, ex.getMessage());
        assertNull(ex.getCause());
        
        Exception cause = new Exception();
        ex = new NoIncludeLocationException(message, cause);
        assertEquals(message, ex.getMessage());
        assertEquals(cause, ex.getCause());
        
    }

}