Refactor AbstractSOPTest

This commit is contained in:
Paul Schaub 2023-04-26 16:21:37 +02:00
parent a722e98578
commit 0fccf3051c
Signed by: vanitasvitae
GPG Key ID: 62BEE9264BF17311
1 changed files with 23 additions and 17 deletions

View File

@ -9,6 +9,7 @@ import org.junit.jupiter.params.provider.Arguments;
import sop.SOP;
import sop.testsuite.SOPInstanceFactory;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@ -19,24 +20,29 @@ public abstract class AbstractSOPTest {
private static final List<Arguments> backends = new ArrayList<>();
static {
// populate instances list via configured test subject factory
String factoryName = System.getenv("test.implementation");
if (factoryName != null) {
try {
Class testSubjectFactoryClass = Class.forName(factoryName);
SOPInstanceFactory factory = (SOPInstanceFactory) testSubjectFactoryClass.newInstance();
Map<String, SOP> testSubjects = factory.provideSOPInstances();
initBackends();
}
for (String key : testSubjects.keySet()) {
backends.add(Arguments.of(Named.of(key, testSubjects.get(key))));
}
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
} catch (InstantiationException e) {
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
// populate instances list via configured test subject factory
private static void initBackends() {
String factoryName = System.getenv("test.implementation");
if (factoryName == null) {
return;
}
SOPInstanceFactory factory;
try {
Class<?> testSubjectFactoryClass = Class.forName(factoryName);
factory = (SOPInstanceFactory) testSubjectFactoryClass
.getDeclaredConstructor().newInstance();
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException |
InvocationTargetException | NoSuchMethodException e) {
throw new RuntimeException(e);
}
Map<String, SOP> testSubjects = factory.provideSOPInstances();
for (String key : testSubjects.keySet()) {
backends.add(Arguments.of(Named.of(key, testSubjects.get(key))));
}
}