![JAR search and dependency download from the Maven repository](/logo.png)
com.github.dakusui.jcunit8.runners.junit4.TestScenarioFactoryForJUnit4 Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jcunit Show documentation
Show all versions of jcunit Show documentation
Automated combinatorial testing framework on top of JUnit
The newest version!
package com.github.dakusui.jcunit8.runners.junit4;
import com.github.dakusui.jcunit8.factorspace.TestPredicate;
import com.github.dakusui.jcunit8.runners.core.NodeUtils;
import com.github.dakusui.jcunit8.runners.junit4.annotations.AfterTestCase;
import com.github.dakusui.jcunit8.runners.junit4.annotations.BeforeTestCase;
import com.github.dakusui.jcunit8.runners.junit4.utils.InternalUtils;
import com.github.dakusui.jcunit8.testsuite.TestOracle;
import com.github.dakusui.jcunit8.testsuite.TestScenario;
import com.github.dakusui.jcunit8.testsuite.TupleConsumer;
import org.junit.*;
import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.TestClass;
import java.lang.annotation.Annotation;
import java.util.List;
import java.util.SortedMap;
import static com.github.dakusui.jcunit8.runners.junit4.utils.InternalUtils.toTestOracle;
import static java.util.stream.Collectors.toList;
public enum TestScenarioFactoryForJUnit4 {
;
public static TestScenario create(TestClass testClass) {
SortedMap predicates = NodeUtils.allTestPredicates(testClass);
return new TestScenario() {
@Override
public List preSuiteProcedures() {
return toTupleConsumer(testClass, BeforeClass.class);
}
@Override
public List preTestInputProcedures() {
return toTupleConsumer(testClass, BeforeTestCase.class);
}
@Override
public List preOracleProcedures() {
return toTupleConsumer(testClass, Before.class);
}
@Override
public List oracles() {
return testClass.getAnnotatedMethods(Test.class).stream(
).map(
(FrameworkMethod method) -> toTestOracle(method, predicates)
).collect(
toList()
);
}
@Override
public List postOracleProcedures() {
return toTupleConsumer(testClass, After.class);
}
@Override
public List postTestInputProcedures() {
return toTupleConsumer(testClass, AfterTestCase.class);
}
@Override
public List postSuiteProcedures() {
return toTupleConsumer(testClass, AfterClass.class);
}
};
}
private static List toTupleConsumer(TestClass testClass, Class extends Annotation> annotationClass) {
return testClass.getAnnotatedMethods(annotationClass).stream(
).map(
InternalUtils::toTupleConsumer
).collect(
toList()
);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy