Skip to content

Commit 6894168

Browse files
committed
JUnit assertThrows FromXmlRuleSetTest
1 parent 3d4068d commit 6894168

1 file changed

Lines changed: 16 additions & 13 deletions

File tree

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

Lines changed: 16 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;
@@ -34,6 +39,8 @@
3439
import org.apache.commons.digester3.binder.RulesModule;
3540
import org.junit.Test;
3641
import org.xml.sax.InputSource;
42+
import org.xml.sax.SAXException;
43+
import org.xml.sax.SAXParseException;
3744

3845
/**
3946
* Tests loading Digester rules from an XML file.
@@ -250,22 +257,17 @@ public void testFactoryIgnoreCreateRule()
250257
}
251258

252259
@Test
253-
public void testFactoryNotIgnoreCreateRule()
254-
throws Exception
255-
{
260+
public void testFactoryNotIgnoreCreateRule() {
256261
final URL rules = getClass().getResource( "testfactorynoignore.xml" );
257262

258263
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-
}
264+
265+
final org.xml.sax.SAXParseException thrown = assertThrows("Exception should have been propagated from create method.",
266+
org.xml.sax.SAXParseException.class, () ->
267+
newLoader(createRules(rules))
268+
.newDigester()
269+
.parse(new StringReader(xml)));
270+
assertThat(thrown.getMessage(), is(equalTo("Error at line 1 char 63: null")));
269271
}
270272

271273
@Test
@@ -355,4 +357,5 @@ public void testBasePath()
355357

356358
assertEquals( "success", testObject.getProperty() );
357359
}
360+
358361
}

0 commit comments

Comments
 (0)