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 package org.jaxen.test;
49
50 import junit.framework.TestCase;
51
52 import org.jaxen.saxpath.SAXPathException;
53 import org.jaxen.saxpath.XPathReader;
54 import org.jaxen.saxpath.helpers.XPathReaderFactory;
55
56 public class XPathReaderFactoryTest extends TestCase
57 {
58 public XPathReaderFactoryTest(String name)
59 {
60 super( name );
61 }
62
63
64 protected void tearDown() {
65 System.setProperty( XPathReaderFactory.DRIVER_PROPERTY, "" );
66 }
67
68 public void testDefault() throws SAXPathException
69 {
70 System.setProperty( XPathReaderFactory.DRIVER_PROPERTY,
71 "" );
72 XPathReader reader = XPathReaderFactory.createReader();
73 assertNotNull( reader );
74 }
75
76 public void testValidByProperty() throws SAXPathException
77 {
78 System.setProperty( XPathReaderFactory.DRIVER_PROPERTY,
79 "org.jaxen.test.MockXPathReader" );
80
81 XPathReader reader = XPathReaderFactory.createReader();
82 assertNotNull( reader );
83 assertSame( MockXPathReader.class, reader.getClass() );
84 }
85
86 public void testInvalidByProperty()
87 {
88 System.setProperty( XPathReaderFactory.DRIVER_PROPERTY,
89 "java.lang.String" );
90
91 try
92 {
93 XPathReaderFactory.createReader();
94 fail( "Should have thrown SAXPathException" );
95 }
96 catch (SAXPathException e) {
97
98 assertNotNull(e.getMessage());
99 }
100 }
101
102 public void testNonExistantByProperty()
103 {
104 System.setProperty( XPathReaderFactory.DRIVER_PROPERTY,
105 "i.am.a.class.that.does.not.Exist" );
106
107 try
108 {
109 XPathReaderFactory.createReader();
110 fail( "Should have thrown SAXPathException" );
111 }
112 catch (org.jaxen.saxpath.SAXPathException e)
113 {
114
115 }
116 }
117
118 public void testValidExplicit() throws SAXPathException
119 {
120 XPathReader reader = XPathReaderFactory.createReader( "org.jaxen.test.MockXPathReader" );
121 assertNotNull( reader );
122 assertSame( MockXPathReader.class, reader.getClass() );
123 }
124
125 public void testInvalidExplicit()
126 {
127 try
128 {
129 XPathReaderFactory.createReader( "java.lang.String" );
130 fail( "Should have thrown SAXPathException" );
131 }
132 catch (org.jaxen.saxpath.SAXPathException e)
133 {
134
135 }
136 }
137
138 public void testNonExistantExplicit()
139 {
140 try
141 {
142 XPathReaderFactory.createReader( "i.am.a.class.that.does.not.Exist" );
143 fail( "Should have thrown SAXPathException" );
144 }
145 catch (org.jaxen.saxpath.SAXPathException e)
146 {
147
148 }
149 }
150 }