diff --git a/src/test/java/emissary/test/core/junit5/TestingResourcesTest.java b/src/test/java/emissary/test/core/junit5/TestingResourcesTest.java index 3a37c30ef9..a4b5904b91 100644 --- a/src/test/java/emissary/test/core/junit5/TestingResourcesTest.java +++ b/src/test/java/emissary/test/core/junit5/TestingResourcesTest.java @@ -16,11 +16,13 @@ public class TestingResourcesTest extends ExtractionTest { public static Stream data() { - return getMyTestParameterFiles(HtmlEscapePlaceTest.class, TestingResourcesTest.class); + return getMyTestParameterFiles(HtmlEscapePlaceTest.class); } @Override public IServiceProviderPlace createPlace() throws IOException { return new HtmlEscapePlace(); } + + } diff --git a/src/test/java/emissary/test/core/junit5/UnitTest.java b/src/test/java/emissary/test/core/junit5/UnitTest.java index fdc5d5c0a5..0c8fd25c64 100644 --- a/src/test/java/emissary/test/core/junit5/UnitTest.java +++ b/src/test/java/emissary/test/core/junit5/UnitTest.java @@ -10,7 +10,6 @@ import org.jdom2.Document; import org.jdom2.input.SAXBuilder; import org.jdom2.input.sax.XMLReaders; -import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; @@ -25,7 +24,6 @@ import java.io.File; import java.io.InputStream; import java.lang.management.ThreadInfo; -import java.util.ArrayList; import java.util.List; import java.util.stream.Stream; import javax.annotation.Nullable; @@ -42,8 +40,6 @@ public abstract class UnitTest { // Runtime typed logger protected Logger logger = LoggerFactory.getLogger(this.getClass()); - protected static List answerFiles = new ArrayList<>(); - @TempDir public static File temporaryDirectory; protected static String TMPDIR = "/tmp"; @@ -82,10 +78,6 @@ public void tearDown() throws Exception { assertMaxNonSystemThreadCount(1); } - @AfterAll - public static void clearAnswerFiles() { - answerFiles.clear(); - } /** * Configure the test stuff @@ -137,31 +129,15 @@ protected List getMyTestResources() { * Get all test resources (*.dat) for this class in a format suitable for Junit Parameterized Tests */ public static Stream getMyTestParameterFiles(Class clz) { - return getMyTestParameterFiles(clz, clz); - } - - /** - * Get test resources (*.dat) and test answers when they are in two different directories. - * - * @param dataClz class that provides the test resource (*.dat) files - * @param ansClz class that provides the test answer files - * @return the stream of test resource files to be used for JUnit Parameterized Tests - */ - public static Stream getMyTestParameterFiles(Class dataClz, Class ansClz) { ResourceReader rr = new ResourceReader(); - List rs = rr.findDataResourcesFor(dataClz); - answerFiles = getMyTestAnswerFiles(rr, ansClz); + List rs = rr.findDataResourcesFor(clz); return rs.stream().map(Arguments::of); } - private static List getMyTestAnswerFiles(ResourceReader resourceReader, Class ansClz) { - return resourceReader.findXmlResourcesFor(ansClz); - } - /** * Get all xml resources (*.xml) for this class */ - protected List getMyXmlResources() { + protected List getMyTestXmlResources() { ResourceReader rr = new ResourceReader(); return rr.findXmlResourcesFor(this.getClass()); } @@ -228,13 +204,19 @@ protected Document getAnswerDocumentFor(String resource) { return null; } + // get String of resource's test location, to see if data files are in different directory than answer files + int resourceDir = resource.lastIndexOf("/"); + String cutResource = resource.substring(0, resourceDir); + int classDir = cutResource.lastIndexOf("/") + 1; + String datClass = cutResource.substring(classDir); + String aname = ""; - if (answerFiles.isEmpty()) { + if (datClass.equals(this.getClass().getSimpleName())) { aname = resource.substring(0, datPos) + ResourceReader.XML_SUFFIX; } else { // if answer files are in different directory than data files, this will be used to find matching answer to data pair String testFileName = FilenameUtils.getBaseName(resource); - for (String answer : answerFiles) { + for (String answer : getMyTestXmlResources()) { if (FilenameUtils.getBaseName(answer).equals(testFileName)) { aname = answer; break;