Skip to content

Commit

Permalink
updating RegressionTest generateAnswers for when two classes are prov…
Browse files Browse the repository at this point in the history
…ided in getMyTestParameterFiles
  • Loading branch information
sambish5 committed Jun 17, 2024
1 parent 7e39ba0 commit 5580001
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public abstract class RegressionTest extends ExtractionTest {
* automatically
*/
@ForOverride
protected boolean generateAnswers() {
protected static boolean generateAnswers() {
return Boolean.getBoolean("generateAnswers");
}

Expand Down
20 changes: 19 additions & 1 deletion src/test/java/emissary/test/core/junit5/RegressionTestUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ public final class RegressionTestUtil {
*/
private static final Path TEST_RESX = getTestResx();

/**
* Used for RegressionTest generateAnswer when {@link UnitTest#getMyTestParameterFiles(Class, Class)} has two different
* classes, and we need to generate answer files in the ansClass directory
*/
@Nullable
private static String ansClass = null;

private RegressionTestUtil() {}

/**
Expand Down Expand Up @@ -200,7 +207,14 @@ public static Path getXmlPath(final String resource) {
return null;
}

final String xmlPath = resource.substring(0, datPos) + ResourceReader.XML_SUFFIX;
String xmlPath;
if (ansClass == null) {
xmlPath = resource.substring(0, datPos) + ResourceReader.XML_SUFFIX;
} else {
String ansPath = ansClass.replace(".", "/");
int testNamePos = resource.lastIndexOf("/");
xmlPath = ansPath + resource.substring(testNamePos, datPos) + ResourceReader.XML_SUFFIX;
}
return TEST_RESX.resolve(xmlPath);
}

Expand Down Expand Up @@ -350,4 +364,8 @@ public static void tweakFinalIbdoWithFormInFilename(final String resource, final
fail("Couldn't get path for resource: " + resource, e);
}
}

public static void setAnsClass(String ansClass) {
RegressionTestUtil.ansClass = ansClass;
}
}
5 changes: 5 additions & 0 deletions src/test/java/emissary/test/core/junit5/UnitTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ public static Stream<? extends Arguments> getMyTestParameterFiles(Class<?> clz)
* @return the stream of test resource files to be used for JUnit Parameterized Tests
*/
public static Stream<? extends Arguments> getMyTestParameterFiles(Class<?> dataClz, Class<?> ansClz) {
// check to see if answers need to be generated in ansClass directory
if (!dataClz.getName().equals(ansClz.getName()) && RegressionTest.generateAnswers()) {
RegressionTestUtil.setAnsClass(ansClz.getName().replace(".", "/"));
}

ResourceReader rr = new ResourceReader();
List<String> rs = rr.findDataResourcesFor(dataClz);
answerFiles = getMyTestAnswerFiles(rr, ansClz);
Expand Down

0 comments on commit 5580001

Please sign in to comment.