Replaced deprecated methods etc.

This commit is contained in:
Philip Helger 2025-10-24 12:27:20 +02:00 committed by Renzo Kottmann
parent c030aaff02
commit 0b22c3ea91
37 changed files with 204 additions and 288 deletions

View file

@ -25,16 +25,13 @@ import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URISyntaxException;
import java.net.URL;
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;
@ -45,7 +42,6 @@ import de.kosit.validationtool.impl.TestObjectFactory;
import de.kosit.validationtool.impl.input.SourceInput;
import de.kosit.validationtool.impl.model.Result;
import de.kosit.validationtool.model.reportInput.XMLSyntaxError;
import net.sf.saxon.dom.NodeOverNodeInfo;
import net.sf.saxon.s9api.BuildingContentHandler;
import net.sf.saxon.s9api.DocumentBuilder;
@ -61,9 +57,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);
@ -81,15 +74,13 @@ public class InputFactoryTest {
assertThat(s1).isNotEqualTo(s3);
}
@Test
@Test(expected = IllegalArgumentException.class)
public void testWrongAlgorithm() {
this.expectedException.expect(IllegalArgumentException.class);
new InputFactory("unknown");
}
@Test
@Test(expected = IllegalArgumentException.class)
public void testNullInputURL() {
this.expectedException.expect(IllegalArgumentException.class);
InputFactory.read((URL) null);
}
@ -105,44 +96,40 @@ public class InputFactoryTest {
assertThat(input).isNotNull();
}
@Test
@Test(expected = IllegalArgumentException.class)
public void testNullStream() {
this.expectedException.expect(IllegalArgumentException.class);
final Input input = InputFactory.read((InputStream) null, SOME_VALUE);
InputFactory.read((InputStream) null, SOME_VALUE);
}
@Test
public void testInputFile() throws URISyntaxException {
public void testInputFile() {
final Input input = InputFactory.read(new File(Simple.SIMPLE_VALID));
assertThat(input).isNotNull();
}
@Test
public void testInputPath() throws URISyntaxException {
public void testInputPath() {
final Input input = InputFactory.read(Paths.get(Simple.SIMPLE_VALID));
assertThat(input).isNotNull();
}
@Test
@Test(expected = IllegalArgumentException.class)
public void testNullInput() {
this.expectedException.expect(IllegalArgumentException.class);
InputFactory.read((byte[]) null, SOME_VALUE);
}
@Test
@Test(expected = IllegalArgumentException.class)
public void testNullInputName() {
this.expectedException.expect(IllegalArgumentException.class);
InputFactory.read(SOME_VALUE.getBytes(), null);
}
@Test
@Test(expected = IllegalArgumentException.class)
public void testEmptyInputName() throws IOException {
this.expectedException.expect(IllegalArgumentException.class);
final Input input = InputFactory.read(SOME_VALUE.getBytes(), "");
drain(input);
}
@Test
@Test(expected = IllegalStateException.class)
public void testSourceInput() throws IOException {
try ( final InputStream s = Simple.SIMPLE_VALID.toURL().openStream() ) {
final SourceInput input = (SourceInput) InputFactory.read(new StreamSource(s));
@ -150,12 +137,11 @@ public class InputFactoryTest {
drain(input);
assertThat(input.getHashCode()).isNotNull();
assertThat(input.getLength()).isGreaterThan(0L);
this.expectedException.expect(IllegalStateException.class);
input.getSource();
}
}
@Test
@Test(expected = IllegalStateException.class)
public void testSourceInputReader() throws IOException {
try ( final InputStream s = Simple.SIMPLE_VALID.toURL().openStream();
final InputStreamReader reader = new InputStreamReader(s) ) {
@ -164,14 +150,12 @@ public class InputFactoryTest {
drain(input);
assertThat(input.getHashCode()).isNotNull();
assertThat(input.getLength()).isGreaterThan(0L);
this.expectedException.expect(IllegalStateException.class);
input.getSource();
}
}
@Test
@Test(expected = IllegalArgumentException.class)
public void testUnexistingInput() {
this.expectedException.expect(IllegalArgumentException.class);
InputFactory.read(Simple.NOT_EXISTING);
}

View file

@ -18,7 +18,6 @@ package de.kosit.validationtool.cmd;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
@ -45,11 +44,8 @@ public class CheckAssertionActionTest {
private static final URL SAMPLE_ASSERTIONS = CheckAssertionActionTest.class.getResource("/examples/assertions/tests-xrechnung.xml");
private CommandLine commandLine;
@Before
public void setup() throws IOException {
this.commandLine = new CommandLine();
public void setup() {
CommandLine.activate();
}

View file

@ -46,6 +46,7 @@ public class CommandLine {
*/
private static class ReplaceableOutputStream<O extends OutputStream> extends OutputStream {
@SuppressWarnings("hiding")
@Getter
@Setter
private O out;

View file

@ -26,7 +26,7 @@ import java.nio.file.Paths;
import java.util.List;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.Strings;
import org.assertj.core.api.Condition;
import org.junit.After;
import org.junit.Before;
@ -45,13 +45,10 @@ public class CommandlineApplicationTest {
public static final String RESULT_OUTPUT = "Processing 1 object(s) completed";
private CommandLine commandLine;
private final Path output = Paths.get("target/test-output");
@Before
public void setup() throws IOException {
this.commandLine = new CommandLine();
CommandLine.activate();
if (Files.exists(this.output)) {
FileUtils.deleteDirectory(this.output.toFile());
@ -194,7 +191,7 @@ public class CommandlineApplicationTest {
CommandLineApplication.mainProgram(args);
assertThat(CommandLine.getErrorOutput()).contains(RESULT_OUTPUT);
assertThat(CommandLine.getOutputLines()).haveAtLeastOne(new Condition<>(
s -> StringUtils.contains(s, "<?xml version=\"1.0\" " + "encoding=\"UTF-8\"?>"), "Must " + "contain xml preambel"));
s -> Strings.CS.contains(s, "<?xml version=\"1.0\" " + "encoding=\"UTF-8\"?>"), "Must " + "contain xml preambel"));
}
@Test
@ -242,7 +239,7 @@ public class CommandlineApplicationTest {
}
@Test
public void testAndre() throws IOException {
public void testAndre() {
final String[] args = { "-s", Paths.get(Simple.SCENARIOS).toString(), "-r", Paths.get(Simple.REPOSITORY_URI).toString(),
Paths.get(Simple.SIMPLE_VALID).toString(), "--report-prefix", "andre1" };
CommandLineApplication.mainProgram(args);

View file

@ -35,13 +35,10 @@ import de.kosit.validationtool.impl.tasks.CheckAction;
*/
public class PrintReportActionTest {
private CommandLine commandLine;
private PrintReportAction action;
@Before
public void setup() {
this.commandLine = new CommandLine();
CommandLine.activate();
this.action = new PrintReportAction(TestObjectFactory.createProcessor());
}

View file

@ -20,15 +20,14 @@ 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.assertTrue;
import static org.junit.Assert.fail;
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 +40,69 @@ public class ConfigurationBuilderTest {
public static final LocalDate EPOCH = LocalDate.of(1970, 1, 1);
@Rule
public ExpectedException exceptions = ExpectedException.none();
@Test
@Test(expected = IllegalStateException.class)
public void testNoConfiguration() {
this.exceptions.expect(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());
try {
final ConfigurationBuilder builder = createSimpleConfiguration();
builder.with((FallbackBuilder) null);
builder.build(Helper.getTestProcessor());
fail();
} catch (final IllegalStateException ex) {
assertTrue(ex.getMessage().contains("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());
try {
final ConfigurationBuilder builder = createSimpleConfiguration();
builder.getScenarios().get(0).validate((SchemaBuilder) null);
builder.build(Helper.getTestProcessor());
fail();
} catch (final IllegalStateException ex) {
assertTrue(ex.getMessage().contains("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());
try {
final ConfigurationBuilder builder = createSimpleConfiguration();
builder.getScenarios().get(0).validate(schematron("invalid").source(URI.create("DoesNotExist")));
builder.build(Helper.getTestProcessor());
fail();
} catch (final IllegalStateException ex) {
assertTrue(ex.getMessage().contains("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());
try {
final ConfigurationBuilder builder = createSimpleConfiguration();
builder.getScenarios().get(0).validate(schematron("invalid"));
builder.build(Helper.getTestProcessor());
fail();
} catch (final IllegalStateException ex) {
assertTrue(ex.getMessage().contains("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());
try {
final ConfigurationBuilder builder = createSimpleConfiguration();
builder.getScenarios().get(0).with(report("invalid"));
builder.build(Helper.getTestProcessor());
fail();
} catch (final IllegalStateException ex) {
assertTrue(ex.getMessage().contains("report"));
}
}
@Test

View file

@ -24,9 +24,7 @@ import java.util.List;
import java.util.Map;
import org.apache.commons.lang3.RandomStringUtils;
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;
@ -43,9 +41,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());
@ -161,7 +156,7 @@ public class ScenarioBuilderTest {
@Test
public void testBasicAttributes() {
final ContentRepository repository = Simple.createContentRepository();
final String random = RandomStringUtils.random(5);
final String random = RandomStringUtils.secure().next(5);
final ScenarioBuilder builder = createScenario();
builder.name(random).description(random);
final Result<Scenario, String> result = builder.build(repository);

View file

@ -28,7 +28,6 @@ import org.junit.Test;
import de.kosit.validationtool.impl.ContentRepository;
import de.kosit.validationtool.impl.Helper.Simple;
import de.kosit.validationtool.impl.model.Result;
import net.sf.saxon.s9api.XPathExecutable;
/**
@ -40,7 +39,7 @@ public class XPathBuilderTest {
@Test
public void testSimpleString() {
final String name = RandomStringUtils.randomAlphanumeric(5);
final String name = RandomStringUtils.secure().nextAlphanumeric(5);
final XPathBuilder b = new XPathBuilder(name);
b.setXpath("//*");
final Result<XPathExecutable, String> result = b.build(Simple.createContentRepository());
@ -54,7 +53,7 @@ public class XPathBuilderTest {
@Test
public void testStringWithNamespace() {
final String name = RandomStringUtils.randomAlphanumeric(5);
final String name = RandomStringUtils.secure().nextAlphanumeric(5);
final XPathBuilder b = new XPathBuilder(name);
final Map<String, String> ns = new HashMap<>();
ns.put("p", "http://somens");
@ -69,7 +68,7 @@ public class XPathBuilderTest {
@Test
public void testStringWithUnknownNamespace() {
final String name = RandomStringUtils.randomAlphanumeric(5);
final String name = RandomStringUtils.secure().nextAlphanumeric(5);
final XPathBuilder b = new XPathBuilder(name);
final Map<String, String> ns = new HashMap<>();
ns.put("p", "http://somens");
@ -82,7 +81,7 @@ public class XPathBuilderTest {
@Test
public void testExecutable() {
final String name = RandomStringUtils.randomAlphanumeric(5);
final String name = RandomStringUtils.secure().nextAlphanumeric(5);
final ContentRepository repository = Simple.createContentRepository();
final XPathExecutable xpath = repository.createXPath("//*", Collections.emptyMap());
final XPathBuilder b = new XPathBuilder(name);
@ -96,7 +95,7 @@ public class XPathBuilderTest {
@Test
public void testExecutableWithNamespace() {
final String name = RandomStringUtils.randomAlphanumeric(5);
final String name = RandomStringUtils.secure().nextAlphanumeric(5);
final ContentRepository repository = Simple.createContentRepository();
final Map<String, String> ns = new HashMap<>();
ns.put("p", "http://somens");
@ -123,7 +122,7 @@ public class XPathBuilderTest {
@Test
public void testNoConfig() {
final String name = RandomStringUtils.randomAlphanumeric(5);
final String name = RandomStringUtils.secure().nextAlphanumeric(5);
final XPathBuilder b = new XPathBuilder(name);
final Result<XPathExecutable, String> result = b.build(Simple.createContentRepository());
assertThat(result).isNotNull();

View file

@ -15,6 +15,7 @@ import net.sf.saxon.lib.UnparsedTextURIResolver;
public class MiscDocExampleCodes {
@SuppressWarnings("unused")
void m1() {
final Configuration config = Configuration.load(URI.create("myscenarios.xml")).setResolvingMode(ResolvingMode.STRICT_LOCAL)
.build(ProcessorProvider.getProcessor());
@ -43,6 +44,7 @@ public class MiscDocExampleCodes {
}
}
@SuppressWarnings("unused")
void m2() {
final Configuration config = Configuration.load(URI.create("myscenarios.xml"))
.setResolvingStrategy(new MyCustomResolvingConfigurationStrategy()).build(ProcessorProvider.getProcessor());

View file

@ -19,6 +19,7 @@ import de.kosit.validationtool.impl.xml.ProcessorProvider;
*/
public class MyValidator {
@SuppressWarnings("unused")
public static void main(final String[] args) {
final Configuration config = Configuration.create().name("myconfiguration")
.with(scenario("firstScenario").match("//myNode").validate(schema("Sample Schema").schemaLocation(URI.create("simple.xsd")))

View file

@ -20,6 +20,7 @@ import de.kosit.validationtool.impl.xml.ProcessorProvider;
*/
public class StandardExample {
@SuppressWarnings("unused")
public void run(final Path testDocument) throws URISyntaxException {
// Load scenarios.xml from classpath
final URL scenarios = this.getClass().getClassLoader().getResource("examples/simple/scenarios-with-relative-paths.xml");

View file

@ -28,12 +28,9 @@ 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;
import net.sf.saxon.s9api.XPathExecutable;
import net.sf.saxon.s9api.XsltExecutable;
@ -46,9 +43,6 @@ public class ContentRepositoryTest {
private ContentRepository repository;
@Rule
public ExpectedException exception = ExpectedException.none();
@Before
public void setup() {
this.repository = Simple.createContentRepository();
@ -60,9 +54,8 @@ public class ContentRepositoryTest {
assertThat(schema).isNotNull();
}
@Test
@Test(expected = IllegalStateException.class)
public void testCreateSchemaNotExisting() throws Exception {
this.exception.expect(IllegalStateException.class);
this.repository.createSchema(Simple.NOT_EXISTING.toURL());
}
@ -72,9 +65,8 @@ public class ContentRepositoryTest {
assertThat(executable).isNotNull();
}
@Test
@Test(expected = IllegalStateException.class)
public void testLoadXSLTNotExisting() {
this.exception.expect(IllegalStateException.class);
this.repository.loadXsltScript(Simple.NOT_EXISTING);
}
@ -90,15 +82,13 @@ public class ContentRepositoryTest {
assertThat(xPath).isNotNull();
}
@Test
@Test(expected = IllegalStateException.class)
public void testXpathCreationWithoutNamespace() {
this.exception.expect(IllegalStateException.class);
this.repository.createXPath("//html:html", null);
}
@Test
@Test(expected = IllegalStateException.class)
public void testIllegalXpath() {
this.exception.expect(IllegalStateException.class);
this.repository.createXPath("kein Xpath Ausdruck", null);
}

View file

@ -16,16 +16,13 @@
package de.kosit.validationtool.impl;
import static org.assertj.core.api.Java6Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
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 +37,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;
@ -53,15 +47,13 @@ public class ConversionServiceTest {
this.repository = Simple.createContentRepository();
}
@Test
@Test(expected = ConversionService.ConversionExeption.class)
public void testMarshalNull() {
this.exception.expect(ConversionService.ConversionExeption.class);
this.service.writeXml(null);
}
@Test
@Test(expected = ConversionService.ConversionExeption.class)
public void testMarshalUnknown() {
this.exception.expect(ConversionService.ConversionExeption.class);
this.service.writeXml(new Serializable() {
});
}
@ -80,33 +72,28 @@ public class ConversionServiceTest {
assertThat(s.getName()).isEqualToIgnoringCase("HTML-TestSuite");
}
@Test
@Test(expected = ConversionService.ConversionExeption.class)
public void testUnmarshalInvalidXml() {
this.exception.expect(ConversionService.ConversionExeption.class);
this.service.readXml(Invalid.SCENARIOS, Scenarios.class, this.repository.createSchema(SCHEMA));
}
@Test
@Test(expected = ConversionService.ConversionExeption.class)
public void testUnmarshalIllFormed() {
this.exception.expect(ConversionService.ConversionExeption.class);
this.service.readXml(Invalid.SCENARIOS_ILLFORMED, Scenarios.class, this.repository.createSchema(SCHEMA));
}
@Test
@Test(expected = ConversionService.ConversionExeption.class)
public void testUnmarshalEmpty() {
this.exception.expect(ConversionService.ConversionExeption.class);
this.service.readXml(null, Scenarios.class);
}
@Test
public void testUnmarshalUnknownType() throws URISyntaxException {
this.exception.expect(ConversionService.ConversionExeption.class);
@Test(expected = ConversionService.ConversionExeption.class)
public void testUnmarshalUnknownType() {
this.service.readXml(Simple.SCENARIOS, ConversionService.class);
}
@Test
public void testUnmarshalWithoutType() throws URISyntaxException {
this.exception.expect(ConversionService.ConversionExeption.class);
@Test(expected = ConversionService.ConversionExeption.class)
public void testUnmarshalWithoutType() {
this.service.readXml(Simple.SCENARIOS, null);
}

View file

@ -26,9 +26,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 +47,6 @@ public class RelativeUriResolverTest {
}
}
@Rule
public ExpectedException exception = ExpectedException.none();
private URIResolver resolver = new RelativeUriResolver(BASE);
@Test
@ -60,15 +55,13 @@ public class RelativeUriResolverTest {
assertThat(resource).isNotNull();
}
@Test
@Test(expected = TransformerException.class)
public void testNotExisting() throws TransformerException {
this.exception.expect(TransformerException.class);
this.resolver.resolve("ubl-0001", BASE.toASCIIString());
}
@Test
@Test(expected = TransformerException.class)
public void testOutOfPath() throws TransformerException {
this.exception.expect(TransformerException.class);
this.resolver.resolve("../results/report.xml", BASE.toASCIIString());
}

View file

@ -25,15 +25,12 @@ 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;
import de.kosit.validationtool.impl.model.Result;
import de.kosit.validationtool.model.scenarios.ScenarioType;
import net.sf.saxon.s9api.XPathExecutable;
import net.sf.saxon.s9api.XdmNode;
@ -45,9 +42,6 @@ import net.sf.saxon.s9api.XdmNode;
public class ScenarioRepositoryTest {
@Rule
public ExpectedException expectedException = ExpectedException.none();
private ScenarioRepository repository;
private TestConfiguration configInstance;
@ -107,9 +101,8 @@ public class ScenarioRepositoryTest {
assertThat(scenario.getObject().getName()).isEqualTo("fallback");
}
@Test
@Test(expected = IllegalArgumentException.class)
public void testNoConfiguration() {
this.expectedException.expect(IllegalArgumentException.class);
this.repository = new ScenarioRepository();
}

View file

@ -22,11 +22,8 @@ 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,16 +41,10 @@ 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;
@Before
public void setup() {
this.repository = Simple.createContentRepository();
this.service = new ConversionService();
}
@ -69,15 +60,13 @@ public class VersioningTest {
assertThat(result).isNotNull();
}
@Test
@Test(expected = ConversionService.ConversionExeption.class)
public void testNewFeature() throws URISyntaxException {
this.exception.expect(ConversionService.ConversionExeption.class);
this.service.readXml(NEW_FEATURE.toURI(), Scenarios.class, SchemaProvider.getScenarioSchema());
}
@Test
@Test(expected = ConversionService.ConversionExeption.class)
public void testNewVersion() throws URISyntaxException {
this.exception.expect(ConversionService.ConversionExeption.class);
this.service.readXml(NEW_VERSION.toURI(), Scenarios.class, SchemaProvider.getScenarioSchema());
}
}

View file

@ -20,15 +20,12 @@ import static de.kosit.validationtool.api.InputFactory.read;
import static org.assertj.core.api.Assertions.assertThat;
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;
import de.kosit.validationtool.impl.model.Result;
import de.kosit.validationtool.model.reportInput.XMLSyntaxError;
import net.sf.saxon.s9api.XdmNode;
/**
@ -38,9 +35,6 @@ import net.sf.saxon.s9api.XdmNode;
*/
public class DocumentParseActionTest {
@Rule
public ExpectedException exception = ExpectedException.none();
private DocumentParseAction action;
@Before
@ -66,9 +60,8 @@ public class DocumentParseActionTest {
assertThat(result.isValid()).isFalse();
}
@Test
@Test(expected = IllegalArgumentException.class)
public void testNullInput() {
this.exception.expect(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

@ -25,9 +25,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 +49,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);
@ -62,9 +57,8 @@ public class BaseResolverConfigurationTest {
s.setInternalProperty(sf, true);
}
@Test
@Test(expected = IllegalStateException.class)
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());

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

@ -16,8 +16,12 @@
package de.kosit.validationtool.impl.xml;
import static org.junit.Assert.assertNotNull;
import javax.xml.validation.SchemaFactory;
import org.junit.Test;
import de.kosit.validationtool.impl.ResolvingMode;
/**
@ -25,6 +29,10 @@ import de.kosit.validationtool.impl.ResolvingMode;
*/
public class SchemaProviderTest {
private final SchemaFactory schemaFactory = ResolvingMode.STRICT_RELATIVE.getStrategy().createSchemaFactory();
@Test
public void testBasic() {
final SchemaFactory schemaFactory = ResolvingMode.STRICT_RELATIVE.getStrategy().createSchemaFactory();
assertNotNull(schemaFactory);
}
}

View file

@ -17,14 +17,13 @@
package de.kosit.validationtool.impl.xml;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static org.junit.Assert.assertTrue;
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 +36,16 @@ 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());
try {
final ResolvingConfigurationStrategy s = new StrictLocalResolvingStrategy();
final SchemaFactory schemaFactory = s.createSchemaFactory();
schemaFactory.newSchema(Resolving.SCHEMA_WITH_REMOTE_REFERENCE.toURL());
fail();
} catch (SAXParseException ex) {
assertTrue(ex.getMessage().contains("schema_reference"));
}
}
@Test

View file

@ -17,14 +17,13 @@
package de.kosit.validationtool.impl.xml;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static org.junit.Assert.assertTrue;
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 +36,16 @@ 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());
try {
final ResolvingConfigurationStrategy s = new StrictLocalResolvingStrategy();
final SchemaFactory schemaFactory = s.createSchemaFactory();
schemaFactory.newSchema(Resolving.SCHEMA_WITH_REMOTE_REFERENCE.toURL());
fail();
} catch (SAXParseException ex) {
assertTrue(ex.getMessage().contains("schema_reference"));
}
}
@Test