Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@
<version>4.13</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,15 @@
package org.apache.commons.digester3.xmlrules;

import static org.apache.commons.digester3.binder.DigesterLoader.newLoader;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.io.IOException;
import java.io.InputStream;
import java.io.StringReader;
import java.net.URL;
Expand All @@ -34,6 +39,8 @@
import org.apache.commons.digester3.binder.RulesModule;
import org.junit.Test;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;

/**
* Tests loading Digester rules from an XML file.
Expand Down Expand Up @@ -250,22 +257,17 @@ public void testFactoryIgnoreCreateRule()
}

@Test
public void testFactoryNotIgnoreCreateRule()
throws Exception
{
public void testFactoryNotIgnoreCreateRule() {
final URL rules = getClass().getResource( "testfactorynoignore.xml" );

final String xml = "<?xml version='1.0' ?><root one='good' two='bad' three='ugly'><foo/></root>";
try
{
newLoader( createRules( rules ) ).newDigester().parse( new StringReader( xml ) );
fail( "Exception should have been propagated from create method." );
}
catch ( final Exception e )
{
/* What we expected */
assertEquals( org.xml.sax.SAXParseException.class, e.getClass() );
}

final org.xml.sax.SAXParseException thrown = assertThrows("Exception should have been propagated from create method.",
org.xml.sax.SAXParseException.class, () ->
newLoader(createRules(rules))
.newDigester()
.parse(new StringReader(xml)));
assertThat(thrown.getMessage(), is(equalTo("Error at line 1 char 63: null")));
}

@Test
Expand Down Expand Up @@ -355,4 +357,5 @@ public void testBasePath()

assertEquals( "success", testObject.getProperty() );
}

}