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

« back to all changes in this revision

Viewing changes to src/nu/xom/tests/CanonicalizationExceptionTest.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.canonical.CanonicalizationException;
 
25
 
 
26
/**
 
27
 * <p>
 
28
 *   Unit tests for the <code>CanonicalizationException</code> class.
 
29
 * </p>
 
30
 * 
 
31
 * @author Elliotte Rusty Harold
 
32
 * @version 1.1d7
 
33
 *
 
34
 */
 
35
public class CanonicalizationExceptionTest extends XOMTestCase {
 
36
    
 
37
    
 
38
    private CanonicalizationException ex;
 
39
    private Exception cause;
 
40
    
 
41
    
 
42
    public CanonicalizationExceptionTest(String name) {
 
43
        super(name);   
 
44
    }
 
45
 
 
46
    
 
47
    protected void setUp() {
 
48
        ex = new CanonicalizationException("message");
 
49
        cause = new Exception();
 
50
    }
 
51
    
 
52
    
 
53
    public void testConstructor() {
 
54
        String message = "testing 1-2-3";
 
55
        CanonicalizationException ex = new CanonicalizationException(message);
 
56
        assertEquals(message, ex.getMessage());
 
57
    }
 
58
 
 
59
    
 
60
    public void testInitCause() {
 
61
        
 
62
        assertNull(ex.getCause());
 
63
        ex.initCause(cause);
 
64
        assertEquals(cause, ex.getCause());
 
65
        
 
66
        try {
 
67
            ex.initCause(null);   
 
68
            fail("Reinitialized cause over null");   
 
69
        }
 
70
        catch (IllegalStateException success) {
 
71
            assertNotNull(success.getMessage()); 
 
72
        }
 
73
        
 
74
        try {
 
75
            ex.initCause(new Exception());   
 
76
            fail("Reinitialized cause over null");   
 
77
        }
 
78
        catch (IllegalStateException success) {
 
79
            assertNotNull(success.getMessage()); 
 
80
        }
 
81
        
 
82
    }
 
83
 
 
84
 
 
85
    public void testNullInitCause() {
 
86
        
 
87
        CanonicalizationException ex = new CanonicalizationException(null);
 
88
        ex.initCause(null);
 
89
        assertNull(ex.getCause());
 
90
        
 
91
        try {
 
92
            ex.initCause(new Exception());
 
93
            fail("Reinitialized cause over null");   
 
94
        }
 
95
        catch (IllegalStateException success) {
 
96
            assertNotNull(success.getMessage()); 
 
97
        }
 
98
 
 
99
        try {
 
100
            ex.initCause(null);   
 
101
            fail("Reinitialized cause over null");   
 
102
        }
 
103
        catch (IllegalStateException success) {
 
104
            assertNotNull(success.getMessage()); 
 
105
        }
 
106
        
 
107
    }
 
108
 
 
109
    
 
110
    public void testSelfCause() {
 
111
        
 
112
        try {
 
113
            ex.initCause(ex);   
 
114
            fail("Allowed self-causation");   
 
115
        }
 
116
        catch (IllegalArgumentException success) {
 
117
            assertNotNull(success.getMessage()); 
 
118
        }
 
119
        
 
120
    }
 
121
 
 
122
    
 
123
    public void testGetMessage() {      
 
124
        Exception ex = new CanonicalizationException("testing");
 
125
        assertEquals("testing", ex.getMessage());
 
126
    }
 
127
 
 
128
}