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

View file

@ -9,6 +9,7 @@ import org.junit.jupiter.params.provider.Arguments;
import sop.SOP; import sop.SOP;
import sop.testsuite.SOPInstanceFactory; import sop.testsuite.SOPInstanceFactory;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -19,25 +20,30 @@ public abstract class AbstractSOPTest {
private static final List<Arguments> backends = new ArrayList<>(); private static final List<Arguments> backends = new ArrayList<>();
static { static {
// populate instances list via configured test subject factory initBackends();
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();
// 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()) { for (String key : testSubjects.keySet()) {
backends.add(Arguments.of(Named.of(key, testSubjects.get(key)))); 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);
}
}
} }
public static Stream<Arguments> provideBackends() { public static Stream<Arguments> provideBackends() {