|
17 | 17 | package org.apache.commons.digester3; |
18 | 18 |
|
19 | 19 | import static org.apache.commons.digester3.binder.DigesterLoader.newLoader; |
| 20 | +import static org.junit.jupiter.api.Assertions.assertThrows; |
20 | 21 |
|
21 | 22 | import java.io.File; |
22 | 23 |
|
23 | 24 | import org.apache.commons.digester3.binder.AbstractRulesModule; |
24 | 25 | import org.junit.Test; |
| 26 | +import org.junit.jupiter.api.function.Executable; |
25 | 27 | import org.xml.sax.ErrorHandler; |
26 | 28 | import org.xml.sax.SAXException; |
27 | 29 | import org.xml.sax.SAXParseException; |
28 | 30 |
|
29 | 31 | /** |
30 | 32 | * Tests for entity resolution and dtd validation |
31 | 33 | */ |
32 | | -public class DTDValidationTestCase |
33 | | -{ |
| 34 | +public class DTDValidationTestCase { |
34 | 35 |
|
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() { |
65 | 38 |
|
| 39 | + // FIXME Simplification once upgraded to Java 1.8 and use lambda |
| 40 | + final Executable testMethod = new Executable() { |
66 | 41 | @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")); |
71 | 75 | } |
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); |
76 | 78 | } |
77 | 79 |
|
78 | 80 | @Test |
|
0 commit comments