mirror of
https://codeberg.org/PGPainless/sop-java.git
synced 2024-12-01 19:42:08 +01:00
Refactor AbstractSOPTest
This commit is contained in:
parent
a722e98578
commit
0fccf3051c
1 changed files with 23 additions and 17 deletions
|
@ -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() {
|
||||||
|
|
Loading…
Reference in a new issue