From da7d8b5e6a3a40954ea86708cc4ed10208689c82 Mon Sep 17 00:00:00 2001 From: Sam Bishop Date: Mon, 20 May 2024 12:29:02 -0400 Subject: [PATCH] further updates & clean-up based on review --- .../emissary/test/core/junit5/UnitTest.java | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/test/java/emissary/test/core/junit5/UnitTest.java b/src/test/java/emissary/test/core/junit5/UnitTest.java index 030dabe439..e74da355de 100644 --- a/src/test/java/emissary/test/core/junit5/UnitTest.java +++ b/src/test/java/emissary/test/core/junit5/UnitTest.java @@ -6,6 +6,7 @@ import emissary.util.ThreadDump; import emissary.util.io.ResourceReader; +import org.apache.commons.io.FilenameUtils; import org.jdom2.Document; import org.jdom2.input.SAXBuilder; import org.jdom2.input.sax.XMLReaders; @@ -136,25 +137,27 @@ 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) { - ResourceReader rr = new ResourceReader(); - List rs = rr.findDataResourcesFor(clz); - return rs.stream().map(Arguments::of); + return getMyTestParameterFiles(clz, clz); } /** * Get test resources (*.dat) and test answers when they are in two different directories. - * - * @param answerClass class that provides the test answer files - * @param dataClass class that provides the test resource (*.dat) files + * + * @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 getMyTestAnswerFiles(Class answerClass, Class dataClass) { + public static Stream getMyTestParameterFiles(Class dataClz, Class ansClz) { ResourceReader rr = new ResourceReader(); - answerFiles = rr.findXmlResourcesFor(answerClass); - List rs = rr.findDataResourcesFor(dataClass); + List rs = rr.findDataResourcesFor(dataClz); + answerFiles = getMyTestAnswerFiles(rr, ansClz); 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 */ @@ -227,9 +230,9 @@ protected Document getAnswerDocumentFor(String resource) { 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 - int testFileName = resource.lastIndexOf("/"); + String testFileName = FilenameUtils.getBaseName(resource); for (String answer : answerFiles) { - if (answer.contains(resource.substring(testFileName + 1, datPos))) { + if (FilenameUtils.getBaseName(answer).equals(testFileName)) { aname = answer; } }