Skip to content

Commit

Permalink
Fixes issue xspec#53: do not fail when testDir does not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
urwa01 committed May 13, 2020
1 parent 76dd4bf commit 2e3c26f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
16 changes: 8 additions & 8 deletions src/main/java/io/xspec/maven/xspecMavenPlugin/XSpecRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import java.net.URISyntaxException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Properties;
import javax.xml.parsers.ParserConfigurationException;
Expand Down Expand Up @@ -92,6 +93,7 @@
import io.xspec.maven.xspecMavenPlugin.utils.extenders.CatalogWriterExtender;
import java.io.PrintStream;
import java.util.Iterator;
import java.util.stream.Collectors;
import javax.xml.transform.ErrorListener;
import net.sf.saxon.lib.TraceListener;
import net.sf.saxon.s9api.XdmDestination;
Expand Down Expand Up @@ -827,17 +829,15 @@ private static Configuration getSaxonConfiguration() {
* Package private to allow unit tests
*/
List<File> findAllXSpecs() throws XSpecPluginException {
if (!options.testDir.exists()) {
return Collections.emptyList();
}
FileFinder finder = new FileFinder(options.testDir, "**/*.xspec", options.excludes, getLog());
final Path testPath = options.testDir.toPath();
try {
List<Path> found = finder.search();
List<File> ret = new ArrayList<>(found.size());
found.stream().forEach((p) -> {
File resolved = testPath.resolve(p).toFile();
ret.add(resolved);
}
);
return ret;
return finder.search().stream()
.map(p -> testPath.resolve(p).toFile())
.collect(Collectors.toList());
} catch(IOException ex) {
throw new XSpecPluginException(ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,25 @@ public void findAllXSpecsTests() throws Exception {
assertEquals("wrong number of XSpecFiles found", 1, xspecFiles.size());
assertEquals("wrong file found", "xsl1.xspec", xspecFiles.get(0).getName());
}


@Test
public void findAllXSpecsTestsNonExistingDir() throws Exception {
RunnerOptions runnerOptions = new RunnerOptions(getProjectDirectory());
runnerOptions.testDir = new File(getTestDirectory(), "unexisting");
XSpecRunner runner = getNewRunner(new SaxonOptions(), runnerOptions);
List<File> xspecFiles = runner.findAllXSpecs();
assertEquals("wrong number of XSpecFiles found", 0, xspecFiles.size());
}

@Test
public void findAllXSpecsTestsDirWithoutXspecFiles() throws Exception {
RunnerOptions runnerOptions = new RunnerOptions(getProjectDirectory());
runnerOptions.testDir = new File(getTestDirectory(), "samples");
XSpecRunner runner = getNewRunner(new SaxonOptions(), runnerOptions);
List<File> xspecFiles = runner.findAllXSpecs();
assertEquals("wrong number of XSpecFiles found", 0, xspecFiles.size());
}

private XSpecRunner getNewRunner(SaxonOptions saxonOptions, RunnerOptions runnerOptions) throws IllegalStateException, XSpecPluginException, MalformedURLException, URISyntaxException {
XSpecRunner runner = new XSpecRunner(getLog(), getBaseDirectory());
runner.setResources(
Expand Down

0 comments on commit 2e3c26f

Please sign in to comment.