Skip to content

Commit 2c286f2

Browse files
committed
JUnit assertThrows DTDValidationTestCase
1 parent ba2556a commit 2c286f2

File tree

1 file changed

+42
-40
lines changed

1 file changed

+42
-40
lines changed

core/src/test/java/org/apache/commons/digester3/DTDValidationTestCase.java

Lines changed: 42 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -17,62 +17,64 @@
1717
package org.apache.commons.digester3;
1818

1919
import static org.apache.commons.digester3.binder.DigesterLoader.newLoader;
20+
import static org.junit.jupiter.api.Assertions.assertThrows;
2021

2122
import java.io.File;
2223

2324
import org.apache.commons.digester3.binder.AbstractRulesModule;
2425
import org.junit.Test;
26+
import org.junit.jupiter.api.function.Executable;
2527
import org.xml.sax.ErrorHandler;
2628
import org.xml.sax.SAXException;
2729
import org.xml.sax.SAXParseException;
2830

2931
/**
3032
* Tests for entity resolution and dtd validation
3133
*/
32-
public class DTDValidationTestCase
33-
{
34+
public class DTDValidationTestCase {
3435

35-
@Test( expected = SAXParseException.class )
36-
public void testDigesterDTDError()
37-
throws Exception
38-
{
39-
newLoader( new AbstractRulesModule() {
40-
41-
@Override
42-
protected void configure()
43-
{
44-
// do nothing
45-
}
46-
47-
} )
48-
.setValidating( true )
49-
.setErrorHandler( new ErrorHandler()
50-
{
51-
52-
@Override
53-
public void warning( final SAXParseException e )
54-
throws SAXException
55-
{
56-
throw e;
57-
}
58-
59-
@Override
60-
public void fatalError( final SAXParseException e )
61-
throws SAXException
62-
{
63-
throw e;
64-
}
36+
@Test
37+
public void testDigesterDTDError() {
6538

39+
// FIXME Simplification once upgraded to Java 1.8 and use lambda
40+
final Executable testMethod = new Executable() {
6641
@Override
67-
public void error( final SAXParseException e )
68-
throws SAXException
69-
{
70-
throw e;
42+
public void execute() throws Throwable {
43+
newLoader(new AbstractRulesModule() {
44+
45+
@Override
46+
protected void configure() {
47+
// do nothing
48+
}
49+
50+
})
51+
.setValidating(true)
52+
.setErrorHandler(new ErrorHandler() {
53+
54+
@Override
55+
public void warning(final SAXParseException e)
56+
throws SAXException {
57+
throw e;
58+
}
59+
60+
@Override
61+
public void fatalError(final SAXParseException e)
62+
throws SAXException {
63+
throw e;
64+
}
65+
66+
@Override
67+
public void error(final SAXParseException e)
68+
throws SAXException {
69+
throw e;
70+
}
71+
72+
})
73+
.newDigester()
74+
.parse(new File("src/test/resources/org/apache/commons/digester3/document-with-relative-dtd-error.xml"));
7175
}
72-
73-
} )
74-
.newDigester()
75-
.parse( new File( "src/test/resources/org/apache/commons/digester3/document-with-relative-dtd-error.xml" ) );
76+
};
77+
assertThrows(SAXParseException.class, testMethod);
7678
}
7779

7880
@Test

0 commit comments

Comments
 (0)