|
19 | 19 | package org.apache.commons.digester3.xmlrules; |
20 | 20 |
|
21 | 21 | import static org.apache.commons.digester3.binder.DigesterLoader.newLoader; |
| 22 | +import static org.hamcrest.MatcherAssert.assertThat; |
| 23 | +import static org.hamcrest.core.Is.is; |
| 24 | +import static org.hamcrest.core.IsEqual.equalTo; |
| 25 | +import static org.junit.Assert.assertThrows; |
22 | 26 | import static org.junit.Assert.assertEquals; |
23 | 27 | import static org.junit.Assert.assertTrue; |
24 | 28 | import static org.junit.Assert.fail; |
25 | 29 |
|
| 30 | +import java.io.IOException; |
26 | 31 | import java.io.InputStream; |
27 | 32 | import java.io.StringReader; |
28 | 33 | import java.net.URL; |
|
33 | 38 | import org.apache.commons.digester3.ObjectCreationFactoryTestImpl; |
34 | 39 | import org.apache.commons.digester3.binder.RulesModule; |
35 | 40 | import org.junit.Test; |
| 41 | +import org.junit.function.ThrowingRunnable; |
36 | 42 | import org.xml.sax.InputSource; |
| 43 | +import org.xml.sax.SAXException; |
| 44 | +import org.xml.sax.SAXParseException; |
37 | 45 |
|
38 | 46 | /** |
39 | 47 | * Tests loading Digester rules from an XML file. |
@@ -250,22 +258,24 @@ public void testFactoryIgnoreCreateRule() |
250 | 258 | } |
251 | 259 |
|
252 | 260 | @Test |
253 | | - public void testFactoryNotIgnoreCreateRule() |
254 | | - throws Exception |
255 | | - { |
| 261 | + public void testFactoryNotIgnoreCreateRule() { |
256 | 262 | final URL rules = getClass().getResource( "testfactorynoignore.xml" ); |
257 | 263 |
|
258 | 264 | final String xml = "<?xml version='1.0' ?><root one='good' two='bad' three='ugly'><foo/></root>"; |
259 | | - try |
260 | | - { |
261 | | - newLoader( createRules( rules ) ).newDigester().parse( new StringReader( xml ) ); |
262 | | - fail( "Exception should have been propagated from create method." ); |
263 | | - } |
264 | | - catch ( final Exception e ) |
265 | | - { |
266 | | - /* What we expected */ |
267 | | - assertEquals( org.xml.sax.SAXParseException.class, e.getClass() ); |
268 | | - } |
| 265 | + |
| 266 | + // FIXME Simplification once upgraded to Java 1.8 |
| 267 | + final ThrowingRunnable testMethod = new ThrowingRunnable() { |
| 268 | + public void run() |
| 269 | + throws IOException, |
| 270 | + SAXException { |
| 271 | + newLoader( createRules( rules ) ) |
| 272 | + .newDigester() |
| 273 | + .parse( new StringReader( xml ) ); |
| 274 | + } |
| 275 | + }; |
| 276 | + final org.xml.sax.SAXParseException thrown = assertThrows("Exception should have been propagated from create method.", |
| 277 | + org.xml.sax.SAXParseException.class, testMethod); |
| 278 | + assertThat(thrown.getMessage(), is(equalTo("Error at line 1 char 63: null"))); |
269 | 279 | } |
270 | 280 |
|
271 | 281 | @Test |
|
0 commit comments