07-FixCompilationWarningsTest

This commit is contained in:
Adrian-Devries 2025-04-24 12:53:55 +02:00
parent adb4effcf9
commit d22b03cec1
17 changed files with 95 additions and 161 deletions

View file

@ -82,6 +82,7 @@
<version.checkstyle>10.23.0</version.checkstyle>
<version.commons-io>2.19.0</version.commons-io>
<version.commons-lang3>3.17.0</version.commons-lang3>
<version.commons-text>1.13.1</version.commons-text>
<version.jakarta.xml.bind-api>4.0.2</version.jakarta.xml.bind-api>
<version.jansi>2.4.1</version.jansi>
<version.jaxb-runtime>4.0.5</version.jaxb-runtime>
@ -185,6 +186,12 @@
<scope>provided</scope>
</dependency>
<!-- Test -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>${version.commons-text}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>de.kosit.validationtool</groupId>
<artifactId>packaged-test-scenarios</artifactId>

View file

@ -19,6 +19,7 @@ package de.kosit.validationtool.api;
import static de.kosit.validationtool.impl.Helper.Simple.SIMPLE_VALID;
import static de.kosit.validationtool.impl.input.StreamHelper.drain;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertThrows;
import java.io.ByteArrayInputStream;
import java.io.File;
@ -32,9 +33,7 @@ import java.nio.file.Paths;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamSource;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
@ -61,9 +60,6 @@ public class InputFactoryTest {
public static final String SOME_VALUE = "some value";
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Test
public void testDefaultDigestAlgorithm() {
assertThat(new InputFactory().getAlgorithm()).isEqualTo(InputFactory.DEFAULT_ALGORITH);
@ -83,14 +79,12 @@ public class InputFactoryTest {
@Test
public void testWrongAlgorithm() {
this.expectedException.expect(IllegalArgumentException.class);
new InputFactory("unknown");
assertThrows(IllegalArgumentException.class, () -> new InputFactory("unknown"));
}
@Test
public void testNullInputURL() {
this.expectedException.expect(IllegalArgumentException.class);
InputFactory.read((URL) null);
assertThrows(IllegalArgumentException.class, () -> InputFactory.read((URL) null));
}
@Test
@ -107,8 +101,7 @@ public class InputFactoryTest {
@Test
public void testNullStream() {
this.expectedException.expect(IllegalArgumentException.class);
final Input input = InputFactory.read((InputStream) null, SOME_VALUE);
assertThrows(IllegalArgumentException.class, () -> InputFactory.read((InputStream) null, SOME_VALUE));
}
@Test
@ -125,21 +118,20 @@ public class InputFactoryTest {
@Test
public void testNullInput() {
this.expectedException.expect(IllegalArgumentException.class);
InputFactory.read((byte[]) null, SOME_VALUE);
assertThrows(IllegalArgumentException.class, () -> InputFactory.read((byte[]) null, SOME_VALUE));
}
@Test
public void testNullInputName() {
this.expectedException.expect(IllegalArgumentException.class);
InputFactory.read(SOME_VALUE.getBytes(), null);
assertThrows(IllegalArgumentException.class, () -> InputFactory.read(SOME_VALUE.getBytes(), null));
}
@Test
public void testEmptyInputName() throws IOException {
this.expectedException.expect(IllegalArgumentException.class);
assertThrows(IllegalArgumentException.class, () -> {
final Input input = InputFactory.read(SOME_VALUE.getBytes(), "");
drain(input);
});
}
@Test
@ -150,8 +142,7 @@ public class InputFactoryTest {
drain(input);
assertThat(input.getHashCode()).isNotNull();
assertThat(input.getLength()).isGreaterThan(0L);
this.expectedException.expect(IllegalStateException.class);
input.getSource();
assertThrows(IllegalStateException.class, input::getSource);
}
}
@ -164,15 +155,13 @@ public class InputFactoryTest {
drain(input);
assertThat(input.getHashCode()).isNotNull();
assertThat(input.getLength()).isGreaterThan(0L);
this.expectedException.expect(IllegalStateException.class);
input.getSource();
assertThrows(IllegalStateException.class, input::getSource);
}
}
@Test
public void testUnexistingInput() {
this.expectedException.expect(IllegalArgumentException.class);
InputFactory.read(Simple.NOT_EXISTING);
assertThrows(IllegalArgumentException.class, () -> InputFactory.read(Simple.NOT_EXISTING));
}
@Test

View file

@ -20,15 +20,13 @@ import static de.kosit.validationtool.config.ConfigurationBuilder.report;
import static de.kosit.validationtool.config.ConfigurationBuilder.schematron;
import static de.kosit.validationtool.config.TestConfigurationFactory.createSimpleConfiguration;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertThrows;
import java.net.URI;
import java.time.LocalDate;
import java.util.Date;
import org.hamcrest.Matchers;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import de.kosit.validationtool.impl.Helper;
@ -41,58 +39,49 @@ public class ConfigurationBuilderTest {
public static final LocalDate EPOCH = LocalDate.of(1970, 1, 1);
@Rule
public ExpectedException exceptions = ExpectedException.none();
@Test
public void testNoConfiguration() {
this.exceptions.expect(IllegalStateException.class);
new ConfigurationBuilder().build(Helper.getTestProcessor());
assertThrows(IllegalStateException.class, () -> new ConfigurationBuilder().build(Helper.getTestProcessor()));
}
@Test
public void testNoFallback() {
this.exceptions.expect(IllegalStateException.class);
this.exceptions.expectMessage(Matchers.containsString("fallback"));
final ConfigurationBuilder builder = createSimpleConfiguration();
builder.with((FallbackBuilder) null);
builder.build(Helper.getTestProcessor());
Throwable e = assertThrows(IllegalStateException.class, () -> builder.build(Helper.getTestProcessor()));
assertThat(e).hasMessageContaining("fallback");
}
@Test
public void testNoSchema() {
this.exceptions.expect(IllegalStateException.class);
this.exceptions.expectMessage(Matchers.containsString("schema"));
final ConfigurationBuilder builder = createSimpleConfiguration();
builder.getScenarios().get(0).validate((SchemaBuilder) null);
builder.build(Helper.getTestProcessor());
Throwable e = assertThrows(IllegalStateException.class, () -> builder.build(Helper.getTestProcessor()));
assertThat(e).hasMessageContaining("schema");
}
@Test
public void testInvalidSchematron() {
this.exceptions.expect(IllegalStateException.class);
this.exceptions.expectMessage(Matchers.containsString("schematron"));
final ConfigurationBuilder builder = createSimpleConfiguration();
builder.getScenarios().get(0).validate(schematron("invalid").source(URI.create("DoesNotExist")));
builder.build(Helper.getTestProcessor());
Throwable e = assertThrows(IllegalStateException.class, () -> builder.build(Helper.getTestProcessor()));
assertThat(e).hasMessageContaining("schematron");
}
@Test
public void testInsufficientSchematron() {
this.exceptions.expect(IllegalStateException.class);
this.exceptions.expectMessage(Matchers.containsString("schematron"));
final ConfigurationBuilder builder = createSimpleConfiguration();
builder.getScenarios().get(0).validate(schematron("invalid"));
builder.build(Helper.getTestProcessor());
Throwable e = assertThrows(IllegalStateException.class, () -> builder.build(Helper.getTestProcessor()));
assertThat(e).hasMessageContaining("schematron");
}
@Test
public void testNoReport() {
this.exceptions.expect(IllegalStateException.class);
this.exceptions.expectMessage(Matchers.containsString("report"));
final ConfigurationBuilder builder = createSimpleConfiguration();
builder.getScenarios().get(0).with(report("invalid"));
builder.build(Helper.getTestProcessor());
Throwable e = assertThrows(IllegalStateException.class, () -> builder.build(Helper.getTestProcessor()));
assertThat(e).hasMessageContaining("report");
}
@Test

View file

@ -23,10 +23,9 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.text.RandomStringGenerator;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import de.kosit.validationtool.impl.ContentRepository;
import de.kosit.validationtool.impl.Helper.Simple;
@ -44,9 +43,6 @@ import net.sf.saxon.s9api.XPathExecutable;
*/
public class ScenarioBuilderTest {
@Rule
public ExpectedException exceptions = ExpectedException.none();
@Test
public void simpleValid() {
final Result<Scenario, String> result = createScenario().build(Simple.createContentRepository());
@ -143,7 +139,7 @@ public class ScenarioBuilderTest {
@Test
public void testBasicAttributes() {
final ContentRepository repository = Simple.createContentRepository();
final String random = RandomStringUtils.random(5);
final String random = getRandomString(5);
final ScenarioBuilder builder = createScenario();
builder.name(random).description(random);
final Result<Scenario, String> result = builder.build(repository);
@ -166,4 +162,10 @@ public class ScenarioBuilderTest {
assertThat(config.getDescription()).isNotNull();
assertThat(config.getDescription().getPOrOlOrUl()).isNotEmpty();
}
@SuppressWarnings("SameParameterValue")
private String getRandomString(final int length) {
RandomStringGenerator rsg = new RandomStringGenerator.Builder().filteredBy(Character::isLetterOrDigit).get();
return rsg.generate(length);
}
}

View file

@ -22,7 +22,7 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.text.RandomStringGenerator;
import org.junit.Test;
import de.kosit.validationtool.impl.ContentRepository;
@ -40,7 +40,7 @@ public class XPathBuilderTest {
@Test
public void testSimpleString() {
final String name = RandomStringUtils.randomAlphanumeric(5);
final String name = getRandomString(5);
final XPathBuilder b = new XPathBuilder(name);
b.setXpath("//*");
final Result<XPathExecutable, String> result = b.build(Simple.createContentRepository());
@ -54,7 +54,7 @@ public class XPathBuilderTest {
@Test
public void testStringWithNamespace() {
final String name = RandomStringUtils.randomAlphanumeric(5);
final String name = getRandomString(5);
final XPathBuilder b = new XPathBuilder(name);
final Map<String, String> ns = new HashMap<>();
ns.put("p", "http://somens");
@ -69,7 +69,7 @@ public class XPathBuilderTest {
@Test
public void testStringWithUnknownNamespace() {
final String name = RandomStringUtils.randomAlphanumeric(5);
final String name = getRandomString(5);
final XPathBuilder b = new XPathBuilder(name);
final Map<String, String> ns = new HashMap<>();
ns.put("p", "http://somens");
@ -82,7 +82,7 @@ public class XPathBuilderTest {
@Test
public void testExecutable() {
final String name = RandomStringUtils.randomAlphanumeric(5);
final String name = getRandomString(5);
final ContentRepository repository = Simple.createContentRepository();
final XPathExecutable xpath = repository.createXPath("//*", Collections.emptyMap());
final XPathBuilder b = new XPathBuilder(name);
@ -96,7 +96,7 @@ public class XPathBuilderTest {
@Test
public void testExecutableWithNamespace() {
final String name = RandomStringUtils.randomAlphanumeric(5);
final String name = getRandomString(5);
final ContentRepository repository = Simple.createContentRepository();
final Map<String, String> ns = new HashMap<>();
ns.put("p", "http://somens");
@ -123,10 +123,16 @@ public class XPathBuilderTest {
@Test
public void testNoConfig() {
final String name = RandomStringUtils.randomAlphanumeric(5);
final String name = getRandomString(5);
final XPathBuilder b = new XPathBuilder(name);
final Result<XPathExecutable, String> result = b.build(Simple.createContentRepository());
assertThat(result).isNotNull();
assertThat(result.isValid()).isFalse();
}
@SuppressWarnings("SameParameterValue")
private String getRandomString(final int length) {
RandomStringGenerator rsg = new RandomStringGenerator.Builder().filteredBy(Character::isLetterOrDigit).get();
return rsg.generate(length);
}
}

View file

@ -17,6 +17,7 @@
package de.kosit.validationtool.impl;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertThrows;
import java.net.MalformedURLException;
import java.net.URI;
@ -28,9 +29,7 @@ import java.util.Map;
import javax.xml.validation.Schema;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import de.kosit.validationtool.impl.Helper.Simple;
@ -46,9 +45,6 @@ public class ContentRepositoryTest {
private ContentRepository repository;
@Rule
public ExpectedException exception = ExpectedException.none();
@Before
public void setup() {
this.repository = Simple.createContentRepository();
@ -62,8 +58,7 @@ public class ContentRepositoryTest {
@Test
public void testCreateSchemaNotExisting() throws Exception {
this.exception.expect(IllegalStateException.class);
this.repository.createSchema(Simple.NOT_EXISTING.toURL());
assertThrows(IllegalStateException.class, () -> this.repository.createSchema(Simple.NOT_EXISTING.toURL()));
}
@Test
@ -74,8 +69,7 @@ public class ContentRepositoryTest {
@Test
public void testLoadXSLTNotExisting() {
this.exception.expect(IllegalStateException.class);
this.repository.loadXsltScript(Simple.NOT_EXISTING);
assertThrows(IllegalStateException.class, () -> this.repository.loadXsltScript(Simple.NOT_EXISTING));
}
@Test
@ -92,14 +86,12 @@ public class ContentRepositoryTest {
@Test
public void testXpathCreationWithoutNamespace() {
this.exception.expect(IllegalStateException.class);
this.repository.createXPath("//html:html", null);
assertThrows(IllegalStateException.class, () -> this.repository.createXPath("//html:html", null));
}
@Test
public void testIllegalXpath() {
this.exception.expect(IllegalStateException.class);
this.repository.createXPath("kein Xpath Ausdruck", null);
assertThrows(IllegalStateException.class, () -> this.repository.createXPath("kein Xpath Ausdruck", null));
}
@Test

View file

@ -16,16 +16,15 @@
package de.kosit.validationtool.impl;
import static org.assertj.core.api.Java6Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertThrows;
import java.io.Serializable;
import java.net.URISyntaxException;
import java.net.URL;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import de.kosit.validationtool.impl.Helper.Invalid;
import de.kosit.validationtool.impl.Helper.Simple;
@ -40,9 +39,6 @@ public class ConversionServiceTest {
private static final URL SCHEMA = ConversionServiceTest.class.getResource("/xsd/scenarios.xsd");
@Rule
public ExpectedException exception = ExpectedException.none();
private ConversionService service;
private ContentRepository repository;
@ -55,15 +51,15 @@ public class ConversionServiceTest {
@Test
public void testMarshalNull() {
this.exception.expect(ConversionService.ConversionException.class);
this.service.writeXml(null);
assertThrows(ConversionService.ConversionException.class, () -> this.service.writeXml(null));
}
@Test
public void testMarshalUnknown() {
this.exception.expect(ConversionService.ConversionException.class);
this.service.writeXml(new Serializable() {
});
assertThrows(ConversionService.ConversionException.class, () -> this.service.writeXml(new Serializable() {
private static final long serialVersionUID = 8745690876369610705L;
}));
}
@Test
@ -82,32 +78,29 @@ public class ConversionServiceTest {
@Test
public void testUnmarshalInvalidXml() {
this.exception.expect(ConversionService.ConversionException.class);
this.service.readXml(Invalid.SCENARIOS, Scenarios.class, this.repository.createSchema(SCHEMA));
assertThrows(ConversionService.ConversionException.class,
() -> this.service.readXml(Invalid.SCENARIOS, Scenarios.class, this.repository.createSchema(SCHEMA)));
}
@Test
public void testUnmarshalIllFormed() {
this.exception.expect(ConversionService.ConversionException.class);
this.service.readXml(Invalid.SCENARIOS_ILLFORMED, Scenarios.class, this.repository.createSchema(SCHEMA));
assertThrows(ConversionService.ConversionException.class,
() -> this.service.readXml(Invalid.SCENARIOS_ILLFORMED, Scenarios.class, this.repository.createSchema(SCHEMA)));
}
@Test
public void testUnmarshalEmpty() {
this.exception.expect(ConversionService.ConversionException.class);
this.service.readXml(null, Scenarios.class);
assertThrows(ConversionService.ConversionException.class, () -> this.service.readXml(null, Scenarios.class));
}
@Test
public void testUnmarshalUnknownType() throws URISyntaxException {
this.exception.expect(ConversionService.ConversionException.class);
this.service.readXml(Simple.SCENARIOS, ConversionService.class);
assertThrows(ConversionService.ConversionException.class, () -> this.service.readXml(Simple.SCENARIOS, ConversionService.class));
}
@Test
public void testUnmarshalWithoutType() throws URISyntaxException {
this.exception.expect(ConversionService.ConversionException.class);
this.service.readXml(Simple.SCENARIOS, null);
assertThrows(ConversionService.ConversionException.class, () -> this.service.readXml(Simple.SCENARIOS, null));
}
}

View file

@ -17,6 +17,7 @@
package de.kosit.validationtool.impl;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertThrows;
import java.net.URI;
import java.net.URISyntaxException;
@ -26,9 +27,7 @@ import javax.xml.transform.Source;
import javax.xml.transform.TransformerException;
import javax.xml.transform.URIResolver;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import de.kosit.validationtool.impl.xml.RelativeUriResolver;
@ -49,9 +48,6 @@ public class RelativeUriResolverTest {
}
}
@Rule
public ExpectedException exception = ExpectedException.none();
private URIResolver resolver = new RelativeUriResolver(BASE);
@Test
@ -62,14 +58,12 @@ public class RelativeUriResolverTest {
@Test
public void testNotExisting() throws TransformerException {
this.exception.expect(TransformerException.class);
this.resolver.resolve("ubl-0001", BASE.toASCIIString());
assertThrows(TransformerException.class, () -> this.resolver.resolve("ubl-0001", BASE.toASCIIString()));
}
@Test
public void testOutOfPath() throws TransformerException {
this.exception.expect(TransformerException.class);
this.resolver.resolve("../results/report.xml", BASE.toASCIIString());
assertThrows(TransformerException.class, () -> this.resolver.resolve("../results/report.xml", BASE.toASCIIString()));
}
@Test

View file

@ -18,6 +18,7 @@ package de.kosit.validationtool.impl;
import static de.kosit.validationtool.api.InputFactory.read;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertThrows;
import java.io.IOException;
import java.net.URI;
@ -25,9 +26,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import de.kosit.validationtool.config.TestConfiguration;
import de.kosit.validationtool.impl.Helper.Simple;
@ -45,9 +44,6 @@ import net.sf.saxon.s9api.XdmNode;
public class ScenarioRepositoryTest {
@Rule
public ExpectedException expectedException = ExpectedException.none();
private ScenarioRepository repository;
private TestConfiguration configInstance;
@ -109,8 +105,7 @@ public class ScenarioRepositoryTest {
@Test
public void testNoConfiguration() {
this.expectedException.expect(IllegalArgumentException.class);
this.repository = new ScenarioRepository();
assertThrows(IllegalArgumentException.class, () -> this.repository = new ScenarioRepository());
}
@Test

View file

@ -17,14 +17,13 @@
package de.kosit.validationtool.impl;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertThrows;
import java.net.URISyntaxException;
import java.net.URL;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import de.kosit.validationtool.impl.Helper.Simple;
import de.kosit.validationtool.model.scenarios.Scenarios;
@ -44,9 +43,6 @@ public class VersioningTest {
private static final URL NEW_VERSION = VersioningTest.class.getResource("/examples/versioning/scenarios-newversion.xml");
@Rule
public ExpectedException exception = ExpectedException.none();
private ConversionService service;
private ContentRepository repository;
@ -71,13 +67,13 @@ public class VersioningTest {
@Test
public void testNewFeature() throws URISyntaxException {
this.exception.expect(ConversionService.ConversionException.class);
this.service.readXml(NEW_FEATURE.toURI(), Scenarios.class, SchemaProvider.getScenarioSchema());
assertThrows(ConversionService.ConversionException.class,
() -> this.service.readXml(NEW_FEATURE.toURI(), Scenarios.class, SchemaProvider.getScenarioSchema()));
}
@Test
public void testNewVersion() throws URISyntaxException {
this.exception.expect(ConversionService.ConversionException.class);
this.service.readXml(NEW_VERSION.toURI(), Scenarios.class, SchemaProvider.getScenarioSchema());
assertThrows(ConversionService.ConversionException.class,
() -> this.service.readXml(NEW_VERSION.toURI(), Scenarios.class, SchemaProvider.getScenarioSchema()));
}
}

View file

@ -18,11 +18,10 @@ package de.kosit.validationtool.impl.tasks;
import static de.kosit.validationtool.api.InputFactory.read;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertThrows;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import de.kosit.validationtool.impl.Helper;
import de.kosit.validationtool.impl.Helper.Simple;
@ -38,9 +37,6 @@ import net.sf.saxon.s9api.XdmNode;
*/
public class DocumentParseActionTest {
@Rule
public ExpectedException exception = ExpectedException.none();
private DocumentParseAction action;
@Before
@ -68,9 +64,6 @@ public class DocumentParseActionTest {
@Test
public void testNullInput() {
this.exception.expect(IllegalArgumentException.class);
this.action.parseDocument(null);
assertThrows(IllegalArgumentException.class, () -> this.action.parseDocument(null));
}
}

View file

@ -35,7 +35,6 @@ import javax.xml.validation.Validator;
import org.junit.Before;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.xml.sax.SAXException;
import de.kosit.validationtool.api.Input;
@ -56,8 +55,6 @@ import de.kosit.validationtool.impl.tasks.CheckAction.Bag;
*/
public class SchemaValidatorActionTest {
public ExpectedException expectedException = ExpectedException.none();
private SchemaValidationAction service;
@Before

View file

@ -16,6 +16,7 @@
package de.kosit.validationtool.impl.xml;
import static org.junit.Assert.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
@ -25,9 +26,7 @@ import static org.mockito.Mockito.verify;
import javax.xml.XMLConstants;
import javax.xml.validation.SchemaFactory;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.xml.sax.SAXNotRecognizedException;
import org.xml.sax.SAXNotSupportedException;
@ -51,9 +50,6 @@ public class BaseResolverConfigurationTest {
public static final String NOT_EXISTING_SCHEME = "not-existing-scheme";
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Test
public void testIgnoreUnsupportedProperty() throws SAXNotRecognizedException, SAXNotSupportedException {
final SchemaFactory sf = mock(SchemaFactory.class);
@ -64,11 +60,10 @@ public class BaseResolverConfigurationTest {
@Test
public void testFailOnUnsupportedProperty() throws SAXNotRecognizedException, SAXNotSupportedException {
this.expectedException.expect(IllegalStateException.class);
final SchemaFactory sf = mock(SchemaFactory.class);
final TestResolvingStrategy s = new TestResolvingStrategy();
doThrow(new SAXNotRecognizedException("not supported")).when(sf).setProperty(any(), any());
s.setInternalProperty(sf, false);
assertThrows(IllegalStateException.class, () -> s.setInternalProperty(sf, false));
}
@Test

View file

@ -21,9 +21,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import de.kosit.validationtool.api.ResolvingConfigurationStrategy;
import de.kosit.validationtool.impl.Helper.Resolving;
@ -35,9 +33,6 @@ import de.kosit.validationtool.impl.Helper.Resolving;
*/
public class RemoteResolvingStrategyTest {
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Test
public void testRemoteSchemaResolving() throws Exception {
final ResolvingConfigurationStrategy s = new RemoteResolvingStrategy();

View file

@ -54,6 +54,7 @@ import net.sf.saxon.s9api.XsltTransformer;
@Slf4j
public class SaxonSecurityTest {
@SuppressWarnings("deprecation")
@Test
public void testEvilStylesheets() throws IOException {
final Processor p = TestObjectFactory.createProcessor();
@ -62,11 +63,13 @@ public class SaxonSecurityTest {
final URL resource = SaxonSecurityTest.class.getResource(String.format("/evil/evil%s.xsl", i));
final XsltCompiler compiler = p.newXsltCompiler();
final RelativeUriResolver resolver = new RelativeUriResolver(Simple.REPOSITORY_URI);
// TODO: Replace call to deprecated method.
compiler.setURIResolver(resolver);
final XsltExecutable executable = compiler.compile(new StreamSource(resource.openStream()));
final XsltTransformer transformer = executable.load();
final Source document = InputFactory.read("<root/>".getBytes(), "dummy").getSource();
// transformer.getUnderlyingController().setUnparsedTextURIResolver(resolver);
// TODO: Replace call to deprecated method.
transformer.setURIResolver(resolver);
transformer.setSource(document);
final XdmDestination result = new XdmDestination();

View file

@ -17,14 +17,12 @@
package de.kosit.validationtool.impl.xml;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertThrows;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import org.hamcrest.Matchers;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.xml.sax.SAXParseException;
import de.kosit.validationtool.api.ResolvingConfigurationStrategy;
@ -37,16 +35,12 @@ import de.kosit.validationtool.impl.Helper.Resolving;
*/
public class StrictLocalResolvingTest {
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Test
public void testRemoteSchemaResolving() throws Exception {
this.expectedException.expect(SAXParseException.class);
this.expectedException.expectMessage(Matchers.containsString("schema_reference"));
final ResolvingConfigurationStrategy s = new StrictLocalResolvingStrategy();
final SchemaFactory schemaFactory = s.createSchemaFactory();
schemaFactory.newSchema(Resolving.SCHEMA_WITH_REMOTE_REFERENCE.toURL());
Throwable e = assertThrows(SAXParseException.class, () -> schemaFactory.newSchema(Resolving.SCHEMA_WITH_REMOTE_REFERENCE.toURL()));
assertThat(e).hasMessageContaining("schema_reference");
}
@Test

View file

@ -17,14 +17,12 @@
package de.kosit.validationtool.impl.xml;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertThrows;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import org.hamcrest.Matchers;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.xml.sax.SAXParseException;
import de.kosit.validationtool.api.ResolvingConfigurationStrategy;
@ -37,16 +35,12 @@ import de.kosit.validationtool.impl.Helper.Resolving;
*/
public class StrictRelativeResolvingTest {
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Test
public void testRemoteSchemaResolving() throws Exception {
this.expectedException.expect(SAXParseException.class);
this.expectedException.expectMessage(Matchers.containsString("schema_reference"));
final ResolvingConfigurationStrategy s = new StrictLocalResolvingStrategy();
final SchemaFactory schemaFactory = s.createSchemaFactory();
schemaFactory.newSchema(Resolving.SCHEMA_WITH_REMOTE_REFERENCE.toURL());
Throwable e = assertThrows(SAXParseException.class, () -> schemaFactory.newSchema(Resolving.SCHEMA_WITH_REMOTE_REFERENCE.toURL()));
assertThat(e).hasMessageContaining("schema_reference");
}
@Test