本文整理汇总了Java中org.junit.runners.model.FrameworkMethod类的典型用法代码示例。如果您正苦于以下问题:Java FrameworkMethod类的具体用法?Java FrameworkMethod怎么用?Java FrameworkMethod使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FrameworkMethod类属于org.junit.runners.model包,在下文中一共展示了FrameworkMethod类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: allPossible
import org.junit.runners.model.FrameworkMethod; //导入依赖的package包/类
Stream<Assignment> allPossible() throws Throwable {
final List<FrameworkMethod> annotatedMethods = testClass.getAnnotatedMethods(DataProducer.class);
Stream<Assignment> methodAssignments = Stream.empty();
for (FrameworkMethod annotatedMethod : annotatedMethods) {
final Type methodReturnType = getMethodGenericReturnType(annotatedMethod.getMethod());
methodAssignments = Stream.concat(methodAssignments, methodToStreamOfResults(annotatedMethod)
.map(value -> new MethodResultAssignment(value, methodReturnType, annotatedMethod)));
}
final List<FrameworkField> annotatedFields = testClass.getAnnotatedFields(DataProducer.class);
final Stream<Assignment> fieldsAssignments = annotatedFields.stream()
.map(FieldAssignment::new);
return Stream.concat(fieldsAssignments, methodAssignments);
}
示例2: apply
import org.junit.runners.model.FrameworkMethod; //导入依赖的package包/类
public Statement apply(final Statement base, FrameworkMethod method, Object target) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
originalStdOut = System.out;
originalStdErr = System.err;
stdOutRouter.setOut(originalStdOut);
stdErrRouter.setOut(originalStdErr);
try {
System.setOut(stdOutPrintStream);
System.setErr(stdErrPrintStream);
base.evaluate();
} finally {
System.setOut(originalStdOut);
System.setErr(originalStdErr);
stdOutRouter = null;
stdErrRouter = null;
stdOutPrintStream = null;
stdErrPrintStream = null;
stdoutContent = null;
stderrContent = null;
}
}
};
}
示例3: methodBlock
import org.junit.runners.model.FrameworkMethod; //导入依赖的package包/类
protected Statement methodBlock(FrameworkMethod method) {
Object test;
try {
test = new ReflectiveCallable() {
@Override
protected Object runReflectiveCall() throws Throwable {
return createTest();
}
}.run();
} catch (Throwable e) {
return new Fail(e);
}
Statement statement = methodInvoker(method, test);
statement = possiblyExpectingExceptions(method, test, statement);
statement = withPotentialTimeout(method, test, statement);
statement = withBefores(method, test, statement);
statement = withAfters(method, test, statement);
statement = withRules(method, test, statement);
return statement;
}
示例4: computeTestMethods
import org.junit.runners.model.FrameworkMethod; //导入依赖的package包/类
@Override
protected List<FrameworkMethod> computeTestMethods() {
List<FrameworkMethod> list = super.computeTestMethods();
Collections.sort(list, new Comparator<FrameworkMethod>() {
@Override
public int compare(FrameworkMethod f1, FrameworkMethod f2) {
Order o1 = f1.getAnnotation(Order.class);
Order o2 = f2.getAnnotation(Order.class);
if (o1 == null) {
if (o2 != null) { // o1 == null, o2 != null
return 1;
} else { // o1 == null, o2 == null
return f1.getName().compareTo(f2.getName());
}
} else {
if (o2 != null) {//o1 != null, o2 != null
return o1.value() - o2.value();
} else { //o1 != null, o2 == null
return -1;
}
}
}
});
return list;
}
示例5: computeTestMethods
import org.junit.runners.model.FrameworkMethod; //导入依赖的package包/类
@Override
protected List<FrameworkMethod> computeTestMethods() {
List<FrameworkMethod> list = super.computeTestMethods();
List<FrameworkMethod> copy = new ArrayList<>(list);
Collections.sort(copy, new Comparator<FrameworkMethod>() {
@Override
public int compare(FrameworkMethod f1, FrameworkMethod f2) {
Order o1 = f1.getAnnotation(Order.class);
Order o2 = f2.getAnnotation(Order.class);
if(o1 == null || o2 == null) {
return -1;
}
return o1.order() - o2.order();
}
});
return copy;
}
示例6: createRunners
import org.junit.runners.model.FrameworkMethod; //导入依赖的package包/类
private static List<Runner> createRunners(final Class<?> clazz) throws InitializationError {
final ValueConverter defaultValueConverter = getDefaultValueConverter(clazz);
final List<Runner> runners = new ArrayList<>();
final Table classWideTable = classWideTableOrNull(clazz);
if (classWideTable != null) {
for (final TableRow row : classWideTable) {
runners.add(new SingleRowMultiTestRunner(clazz, row, defaultValueConverter));
}
} else {
for (final FrameworkMethod testMethod : new TestClass(clazz).getAnnotatedMethods(Test.class)) {
final Spockito.UseValueConverter useValueConverter = testMethod.getAnnotation(Spockito.UseValueConverter.class);
final ValueConverter methodValueConverter = Spockito.getValueConverter(useValueConverter, defaultValueConverter);
runners.add(new SingleTestMultiRowRunner(clazz, testMethod, methodValueConverter));
}
}
return runners;
}
示例7: computeTestMethods
import org.junit.runners.model.FrameworkMethod; //导入依赖的package包/类
@Override
protected List<FrameworkMethod> computeTestMethods() {
List<FrameworkMethod> list = super.computeTestMethods();
List<FrameworkMethod> copy = new ArrayList<FrameworkMethod>(list);
Collections.sort(copy, new Comparator<FrameworkMethod>() {
@Override
public int compare(FrameworkMethod f1, FrameworkMethod f2) {
Order o1 = f1.getAnnotation(Order.class);
Order o2 = f2.getAnnotation(Order.class);
if (o1 == null || o2 == null) {
return -1;
}
return o1.order() - o2.order();
}
});
return copy;
}
示例8: apply
import org.junit.runners.model.FrameworkMethod; //导入依赖的package包/类
/**
* @see org.junit.rules.MethodRule#apply(org.junit.runners.model.Statement, org.junit.runners.model.FrameworkMethod, java.lang.Object)
*/
@Override
public Statement apply(final Statement base, final FrameworkMethod method, final Object target) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
final List<Module> moduleWithTarget = new ArrayList<>(Arrays.asList(modules));
if (target instanceof Module) {
moduleWithTarget.add((Module) target);
}
Guice.createInjector(moduleWithTarget).injectMembers(target);
try {
base.evaluate();
} finally {
new ThreadSafeMockingProgress().reset();
}
}
};
}
示例9: methodInvoker
import org.junit.runners.model.FrameworkMethod; //导入依赖的package包/类
@Override
protected Statement methodInvoker(final FrameworkMethod method, final Object test) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
PactFrameworkMethod pactFrameworkMethod = (PactFrameworkMethod) method;
if (pactFrameworkMethod.shouldExclude()) {
LOG.warn("Test has been excluded. Test will show as passed but was *NOT* run.");
return;
}
if (pactFrameworkMethod.getWorkflow() != null) {
setUpProviderState(test, pactFrameworkMethod.getWorkflow());
pactFrameworkMethod.invokeExplosively(test, pactFrameworkMethod.getWorkflow().getInteractions());
} else {
setUpProviderState(test, pactFrameworkMethod.getInteraction());
pactFrameworkMethod.invokeExplosively(test, Collections.singletonList(pactFrameworkMethod.getInteraction()));
}
}
};
}
示例10: BytecoderUnitTestRunner
import org.junit.runners.model.FrameworkMethod; //导入依赖的package包/类
public BytecoderUnitTestRunner(Class aClass) throws InitializationError {
super(aClass);
testClass = new TestClass(aClass);
testMethods = new ArrayList<>();
Method[] classMethods = aClass.getDeclaredMethods();
for (Method classMethod : classMethods) {
Class retClass = classMethod.getReturnType();
int length = classMethod.getParameterTypes().length;
int modifiers = classMethod.getModifiers();
if (retClass == null || length != 0 || Modifier.isStatic(modifiers)
|| !Modifier.isPublic(modifiers) || Modifier.isInterface(modifiers)
|| Modifier.isAbstract(modifiers)) {
continue;
}
String methodName = classMethod.getName();
if (methodName.toUpperCase().startsWith("TEST")
|| classMethod.getAnnotation(Test.class) != null) {
testMethods.add(new FrameworkMethod(classMethod));
}
if (classMethod.getAnnotation(Ignore.class) != null) {
testMethods.remove(classMethod);
}
}
}
示例11: computeTestMethods
import org.junit.runners.model.FrameworkMethod; //导入依赖的package包/类
@Override
protected List<FrameworkMethod> computeTestMethods() {
final List<FrameworkMethod> unordered = super.computeTestMethods();
List<FrameworkMethod> otherMethods = new ArrayList<>(unordered);
List<FrameworkMethod> orderedMethods = new ArrayList<>();
// extracting methods annotated ofRes Order
for (int i = 0; i < otherMethods.size(); i++) {
FrameworkMethod frameworkMethod = otherMethods.get(i);
Order order = frameworkMethod.getAnnotation(Order.class);
if (order != null) {
orderedMethods.add(frameworkMethod);
otherMethods.remove(i--);
}
}
// sorting ordered methods
Collections.sort(orderedMethods, new Comparator<FrameworkMethod>() {
@Override
public int compare(FrameworkMethod f1, FrameworkMethod f2) {
return f1.getAnnotation(Order.class).value() -
f2.getAnnotation(Order.class).value();
}
});
// appending other methods to ordered methods
orderedMethods.addAll(otherMethods);
return Collections.unmodifiableList(orderedMethods);
}
示例12: createTestObject
import org.junit.runners.model.FrameworkMethod; //导入依赖的package包/类
Object createTestObject() throws Exception {
List<FrameworkMethod> annotatedMethods = testClass.getAnnotatedMethods(TestFactory.class);
if (!annotatedMethods.isEmpty()) {
Method factoryMethod = annotatedMethods.get(0).getMethod();
validateFactoryMethod(factoryMethod);
return factoryMethod.invoke(null);
}
return testClass.getOnlyConstructor().newInstance();
}
示例13: methodToStreamOfResults
import org.junit.runners.model.FrameworkMethod; //导入依赖的package包/类
private static Stream<?> methodToStreamOfResults(FrameworkMethod annotatedMethod) {
try {
return ((Collection<?>) annotatedMethod.invokeExplosively(null)).stream();
} catch (Throwable throwable) {
throw new IllegalArgumentException(throwable);
}
}
示例14: validateTestMethods
import org.junit.runners.model.FrameworkMethod; //导入依赖的package包/类
@Override
protected void validateTestMethods(List<Throwable> errors) {
List<FrameworkMethod> annotatedMethods = getTestClass().getAnnotatedMethods(Test.class);
for (FrameworkMethod annotatedMethod : annotatedMethods) {
annotatedMethod.validatePublicVoid(false, errors);
}
}
示例15: findArchRuleMethods
import org.junit.runners.model.FrameworkMethod; //导入依赖的package包/类
private Collection<ArchTestExecution> findArchRuleMethods() {
List<ArchTestExecution> result = new ArrayList<>();
for (FrameworkMethod testMethod : getTestClass().getAnnotatedMethods(ArchTest.class)) {
result.add(new ArchTestMethodExecution(getTestClass().getJavaClass(), testMethod.getMethod(), false));
}
return result;
}