Skip to content

Commit 589ec5e

Browse files
committed
JUnit assertThrows FromXmlRuleSetTest
1 parent ba2556a commit 589ec5e

File tree

1 file changed

+23
-13
lines changed

1 file changed

+23
-13
lines changed

core/src/test/java/org/apache/commons/digester3/xmlrules/FromXmlRuleSetTest.java

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,15 @@
1919
package org.apache.commons.digester3.xmlrules;
2020

2121
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;
2226
import static org.junit.Assert.assertEquals;
2327
import static org.junit.Assert.assertTrue;
2428
import static org.junit.Assert.fail;
2529

30+
import java.io.IOException;
2631
import java.io.InputStream;
2732
import java.io.StringReader;
2833
import java.net.URL;
@@ -33,7 +38,10 @@
3338
import org.apache.commons.digester3.ObjectCreationFactoryTestImpl;
3439
import org.apache.commons.digester3.binder.RulesModule;
3540
import org.junit.Test;
41+
import org.junit.function.ThrowingRunnable;
3642
import org.xml.sax.InputSource;
43+
import org.xml.sax.SAXException;
44+
import org.xml.sax.SAXParseException;
3745

3846
/**
3947
* Tests loading Digester rules from an XML file.
@@ -250,22 +258,24 @@ public void testFactoryIgnoreCreateRule()
250258
}
251259

252260
@Test
253-
public void testFactoryNotIgnoreCreateRule()
254-
throws Exception
255-
{
261+
public void testFactoryNotIgnoreCreateRule() {
256262
final URL rules = getClass().getResource( "testfactorynoignore.xml" );
257263

258264
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")));
269279
}
270280

271281
@Test

0 commit comments

Comments
 (0)