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

« back to all changes in this revision

Viewing changes to src/nu/xom/tests/XIncludeExceptionTest.java

  • Committer: Bazaar Package Importer
  • Author(s): Varun Hiremath
  • Date: 2007-11-25 15:50:40 UTC
  • Revision ID: james.westby@ubuntu.com-20071125155040-r75ikcqf1vu0cei7
Tags: upstream-1.1
ImportĀ upstreamĀ versionĀ 1.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright 2003-2005 Elliotte Rusty Harold
 
2
   
 
3
   This library is free software; you can redistribute it and/or modify
 
4
   it under the terms of version 2.1 of the GNU Lesser General Public 
 
5
   License as published by the Free Software Foundation.
 
6
   
 
7
   This library is distributed in the hope that it will be useful,
 
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 
10
   GNU Lesser General Public License for more details.
 
11
   
 
12
   You should have received a copy of the GNU Lesser General Public
 
13
   License along with this library; if not, write to the 
 
14
   Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
 
15
   Boston, MA 02111-1307  USA
 
16
   
 
17
   You can contact Elliotte Rusty Harold by sending e-mail to
 
18
   elharo@metalab.unc.edu. Please include the word "XOM" in the
 
19
   subject line. The XOM home page is located at http://www.xom.nu/
 
20
*/
 
21
 
 
22
package nu.xom.tests;
 
23
 
 
24
import nu.xom.xinclude.BadEncodingAttributeException;
 
25
import nu.xom.xinclude.BadParseAttributeException;
 
26
import nu.xom.xinclude.MisplacedFallbackException;
 
27
import nu.xom.xinclude.NoIncludeLocationException;
 
28
import nu.xom.xinclude.XIncludeException;
 
29
 
 
30
/**
 
31
 * <p>
 
32
 *   Unit tests for the <code>XIncludeException</code> class.
 
33
 * </p>
 
34
 * 
 
35
 * @author Elliotte Rusty Harold
 
36
 * @version 1.1b3
 
37
 *
 
38
 */
 
39
public class XIncludeExceptionTest extends XOMTestCase {
 
40
    
 
41
    private XIncludeException ex;
 
42
    private Exception cause;
 
43
    
 
44
    
 
45
    public XIncludeExceptionTest(String name) {
 
46
        super(name);
 
47
    }
 
48
 
 
49
    
 
50
    protected void setUp() {
 
51
        ex = new XIncludeException("message");
 
52
        cause = new Exception();
 
53
    }
 
54
    
 
55
    
 
56
    public void testConstructor() {
 
57
        ex = new XIncludeException("test", "http://ex.com/");
 
58
        assertEquals("test", ex.getMessage());
 
59
        assertEquals("http://ex.com/", ex.getURI());
 
60
    }
 
61
 
 
62
    
 
63
    public void testInitCause() {
 
64
        
 
65
        assertNull(ex.getCause());
 
66
        ex.initCause(cause);
 
67
        assertEquals(cause, ex.getCause());
 
68
        
 
69
        try {
 
70
            ex.initCause(null);   
 
71
            fail("Reinitialized cause over null");   
 
72
        }
 
73
        catch (IllegalStateException result) {
 
74
            // success   
 
75
        }
 
76
        
 
77
        try {
 
78
            ex.initCause(new Exception());   
 
79
            fail("Reinitialized cause over null");   
 
80
        }
 
81
        catch (IllegalStateException result) {
 
82
            // success   
 
83
        }
 
84
        
 
85
    }
 
86
 
 
87
 
 
88
    public void testNullInitCause() {
 
89
        
 
90
        XIncludeException ex
 
91
          = new XIncludeException("message", (Exception) null);
 
92
        assertNull(ex.getCause());
 
93
        
 
94
        try {
 
95
            ex.initCause(new Exception());
 
96
            fail("Reinitialized cause over null");   
 
97
        }
 
98
        catch (IllegalStateException result) {
 
99
            // success   
 
100
        }
 
101
 
 
102
        try {
 
103
            ex.initCause(null);   
 
104
            fail("Reinitialized cause over null");   
 
105
        }
 
106
        catch (IllegalStateException result) {
 
107
            // success   
 
108
        }
 
109
        
 
110
    }
 
111
 
 
112
    
 
113
    public void testSelfCause() {
 
114
        
 
115
        try {
 
116
            ex.initCause(ex);   
 
117
            fail("Allowed self-causation");   
 
118
        }
 
119
        catch (IllegalArgumentException success) {
 
120
            // success   
 
121
        }
 
122
        
 
123
    }
 
124
 
 
125
    
 
126
    public void testGetMessage() {      
 
127
        Exception ex = new XIncludeException("testing");
 
128
        assertEquals("testing", ex.getMessage());
 
129
    }
 
130
    
 
131
    
 
132
    public void testMisplacedFallbackException() {
 
133
        String message = "message";
 
134
        Exception ex = new MisplacedFallbackException(message);
 
135
        assertEquals(message, ex.getMessage());
 
136
    }
 
137
 
 
138
    
 
139
    public void testBadParseAttributeException() {
 
140
        String message = "message";
 
141
        Exception ex = new BadParseAttributeException(message);
 
142
        assertEquals(message, ex.getMessage());
 
143
    }
 
144
 
 
145
    
 
146
    public void testBadEncodingAttributeException() {
 
147
        String message = "message";
 
148
        Exception ex = new BadEncodingAttributeException(message);
 
149
        assertEquals(message, ex.getMessage());
 
150
    }
 
151
 
 
152
    
 
153
    public void testNoIncludeLocationException() {
 
154
        
 
155
        String message = "message";
 
156
        XIncludeException ex = new NoIncludeLocationException(message);
 
157
        assertEquals(message, ex.getMessage());
 
158
        assertNull(ex.getCause());
 
159
        
 
160
        Exception cause = new Exception();
 
161
        ex = new NoIncludeLocationException(message, cause);
 
162
        assertEquals(message, ex.getMessage());
 
163
        assertEquals(cause, ex.getCause());
 
164
        
 
165
    }
 
166
 
 
167
}