类org.junit.runners.model.FrameworkMethod源码实例Demo

下面列出了怎么用org.junit.runners.model.FrameworkMethod的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: buck   文件: EndToEndRunner.java
/**
 * Marks validation errors in errors if 2 methods marked by @EnvironmentFor contain the same test
 * names
 *
 * <p>Note: Adds an error to the list for each pair of duplicates found
 */
private void validateEnvironmentMapContainsNoDuplicates(List<Throwable> errors) {
  List<FrameworkMethod> environmentForMethods =
      getTestClass().getAnnotatedMethods(EnvironmentFor.class);
  Map<String, String> seenTestNames = new HashMap<>();
  for (FrameworkMethod environmentForMethod : environmentForMethods) {
    String[] environmentForTestNames =
        environmentForMethod.getAnnotation(EnvironmentFor.class).testNames();
    for (String testName : environmentForTestNames) {
      if (seenTestNames.containsKey(testName)) {
        errors.add(
            new AnnotationFormatError(
                String.format(
                    "EnvironmentFor methods %s and %s are both marked as for %s",
                    environmentForMethod.getName(), seenTestNames.get(testName), testName)));
      }
      seenTestNames.put(testName, environmentForMethod.getName());
    }
  }
}
 
源代码2 项目: Pushjet-Android   文件: Sample.java
public Statement apply(final Statement base, FrameworkMethod method, Object target) {
    final String sampleName = getSampleName(method);
    sampleDir = sampleName == null ? null : testDirectoryProvider.getTestDirectory().file(sampleName);

    return new Statement() {
        @Override
        public void evaluate() throws Throwable {
            if (sampleName != null) {
                TestFile srcDir = new IntegrationTestBuildContext().getSamplesDir().file(sampleName).assertIsDir();
                logger.debug("Copying sample '{}' to test directory.", sampleName);
                srcDir.copyTo(sampleDir);
            } else {
                logger.debug("No sample specified for this test, skipping.");
            }
            base.evaluate();
        }
    };
}
 
源代码3 项目: karate   文件: Karate.java
public Karate(Class<?> clazz) throws InitializationError, IOException {
    super(clazz);
    List<FrameworkMethod> testMethods = getTestClass().getAnnotatedMethods(Test.class);
    if (!testMethods.isEmpty()) {
        logger.warn("WARNING: there are methods annotated with '@Test', they will NOT be run when using '@RunWith(Karate.class)'");
    }
    RunnerOptions options = RunnerOptions.fromAnnotationAndSystemProperties(clazz);
    List<Resource> resources = FileUtils.scanForFeatureFiles(options.getFeatures(), clazz.getClassLoader());
    children = new ArrayList(resources.size());
    featureMap = new HashMap(resources.size());
    for (Resource resource : resources) {
        Feature feature = FeatureParser.parse(resource);
        feature.setCallName(options.getName());
        feature.setCallLine(resource.getLine());
        children.add(feature);
    }
    tagSelector = Tags.fromKarateOptionsTags(options.getTags());
}
 
源代码4 项目: geowave   文件: GeoWaveITRunner.java
@Override
protected Statement withAfterClasses(final Statement statement) {
  // add test environment tear down
  try {
    final Statement newStatement = super.withAfterClasses(statement);
    final Method tearDownMethod = GeoWaveITRunner.class.getDeclaredMethod("tearDown");
    tearDownMethod.setAccessible(true);
    return new RunAfters(
        newStatement,
        Collections.singletonList(new FrameworkMethod(tearDownMethod)),
        this);
  } catch (NoSuchMethodException | SecurityException e) {
    LOGGER.warn("Unable to find tearDown method", e);
  }
  return super.withAfterClasses(statement);
}
 
源代码5 项目: zerocode   文件: ZeroCodeUnitRunner.java
private List<String> getSmartChildrenList() {
    List<FrameworkMethod> children = getChildren();
    children.forEach(
            frameworkMethod -> {
                JsonTestCase jsonTestCaseAnno = frameworkMethod.getAnnotation(JsonTestCase.class);

                if(jsonTestCaseAnno == null){
                    jsonTestCaseAnno = evalScenarioToJsonTestCase(frameworkMethod.getAnnotation(Scenario.class));
                }

                if (jsonTestCaseAnno != null) {
                    smartTestCaseNames.add(jsonTestCaseAnno.value());
                } else {
                    smartTestCaseNames.add(frameworkMethod.getName());
                }
            }
    );

    return smartTestCaseNames;
}
 
源代码6 项目: htmlunit   文件: StandardsTestClass.java
/**
 * {@inheritDoc}
 */
@Override
protected void scanAnnotatedMembers(final Map<Class<? extends Annotation>,
        List<FrameworkMethod>> methodsForAnnotations,
        final Map<Class<? extends Annotation>, List<FrameworkField>> fieldsForAnnotations) {
    for (final Class<?> eachClass : getSuperClasses(getJavaClass())) {
        for (final Method eachMethod : MethodSorter.getDeclaredMethods(eachClass)) {
            addToAnnotationLists(new FrameworkMethod(eachMethod), methodsForAnnotations);
        }
        // Fields are ignored
    }
    for (final  Map.Entry<Class<? extends Annotation>,
            List<FrameworkMethod>> methodsEntry : methodsForAnnotations.entrySet()) {
        final Class<? extends Annotation> key = methodsEntry.getKey();
        if (key == Test.class) {
            final List<FrameworkMethod> methods = methodsEntry.getValue();
            final List<FrameworkMethod> newMethods = new ArrayList<>(methods.size() * 2);
            for (final FrameworkMethod m : methods) {
                newMethods.add(new StandardsFrameworkMethod(m.getMethod(), false));
                newMethods.add(new StandardsFrameworkMethod(m.getMethod(), true));
            }
            methodsForAnnotations.put(key, newMethods);
        }
    }
}
 
源代码7 项目: datakernel   文件: DatakernelServiceRunner.java
@Override
protected Statement methodInvoker(FrameworkMethod method, Object test) {
	return new LambdaStatement(() -> {
		// create args before running the service graph so that those args that are services are found by service graph
		Object[] args = getArgs(method);

		ServiceGraph serviceGraph = currentInjector.getInstanceOrNull(ServiceGraph.class);

		if (serviceGraph == null) {
			method.invokeExplosively(test, args);
			return;
		}

		serviceGraph.startFuture().get();

		method.invokeExplosively(test, args);

		serviceGraph.stopFuture().get();
	});
}
 
源代码8 项目: android-test   文件: UiThreadStatement.java
public static boolean shouldRunOnUiThread(FrameworkMethod method) {
  Class<? extends Annotation> deprecatedUiThreadTestClass =
      loadUiThreadClass("android.test.UiThreadTest");
  if (hasAnnotation(method, deprecatedUiThreadTestClass)) {
    return true;
  } else {
    // to avoid circular dependency on Rules module use the class name directly
    @SuppressWarnings("unchecked") // reflection
    Class<? extends Annotation> uiThreadTestClass =
        loadUiThreadClass("androidx.test.annotation.UiThreadTest");
    if (hasAnnotation(method, deprecatedUiThreadTestClass)
        || hasAnnotation(method, uiThreadTestClass)) {
        return true;
      }
  }
  return false;
}
 
源代码9 项目: pinpoint   文件: ForkedPinpointPluginTestRunner.java
@Override
protected Statement methodBlock(FrameworkMethod method) {
    final Statement fromSuper = super.methodBlock(method);
    final boolean manageTraceObject = this.manageTraceObject && (method.getAnnotation(TraceObjectManagable.class) == null);
    
    return new Statement() {
        
        @Override
        public void evaluate() throws Throwable {
            PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
            
            verifier.initialize(manageTraceObject);
            try {
                fromSuper.evaluate();
            } finally {
                verifier.cleanUp(manageTraceObject);
            }
        }
    };
}
 
源代码10 项目: qpid-broker-j   文件: QpidUnitTestRunner.java
@Override
protected void runChild(final FrameworkMethod method, final RunNotifier notifier)
{
    LOGGER.info("========================= executing test : {}", _testClass.getSimpleName() + "#" + method.getName());
    setClassQualifiedTestName(_testClass.getName() + "." + method.getName());
    LOGGER.info("========================= start executing test : {}", _testClass.getSimpleName() + "#" + method.getName());

    try
    {
        super.runChild(method, notifier);
    }
    finally
    {
        LOGGER.info("========================= stop executing test : {} ", _testClass.getSimpleName() + "#" + method.getName());
        setClassQualifiedTestName(_testClass.getName());
        LOGGER.info("========================= cleaning up test environment for test : {}", _testClass.getSimpleName() + "#" + method.getName());
    }
}
 
源代码11 项目: junit-dataprovider   文件: TestGeneratorTest.java
@Test
public void testExplodeTestMethodsUseDataProviderShouldReturnFrameworkMethodInjectedToUseDataProviderMethodIfExists() throws Throwable {
    // Given:
    final Method method = getMethod("dataProviderMethod");
    when(dataProviderMethod.getMethod()).thenReturn(method);

    List<Object[]> dataConverterResult = listOfArrays(new Object[] { null });
    when(dataConverter.convert(any(), anyBoolean(), any(Class[].class), any(DataProvider.class))).thenReturn(dataConverterResult);
    when(dataProviderMethod.getAnnotation(DataProvider.class)).thenReturn(dataProvider);
    when(dataProvider.format()).thenReturn(DataProvider.DEFAULT_FORMAT);
    when(dataProvider.cache()).thenReturn(true);

    // When:
    List<FrameworkMethod> result = underTest.explodeTestMethod(testMethod, dataProviderMethod);

    // Then:
    assertThat(TestGenerator.dataProviderDataCache).hasSize(1).containsKey(dataProviderMethod);
    assertThat(result).hasSize(1);
    verify(dataProviderMethod).invokeExplosively(null, testMethod);
}
 
源代码12 项目: JQF   文件: JQF.java
private void validateFuzzMethods(List<Throwable> errors) {
    for (FrameworkMethod method : getTestClass().getAnnotatedMethods(Fuzz.class)) {
        method.validatePublicVoid(false, errors);
        if (method.getAnnotation(Property.class) != null) {
            errors.add(new Exception("Method " + method.getName() +
                    " cannot have both @Property and @Fuzz annotations"));
        }
    }
}
 
/**
 * {@inheritDoc}
 * <p>
 * Look at the classes java doc for detailed description of the applied strategies.
 *
 * @return the resolved dataprovider method or an empty {@link List} if dataprovider could not be found (never null)
 * @see DefaultDataProviderMethodResolver
 */
@Override
public List<FrameworkMethod> resolve(FrameworkMethod testMethod, UseDataProvider useDataProvider) {
    checkNotNull(testMethod, "testMethod must not be null");
    checkNotNull(useDataProvider, "useDataProvider must not be null");

    List<TestClass> dataProviderLocations = findDataProviderLocations(testMethod, useDataProvider.location());
    return findDataProviderMethods(dataProviderLocations, testMethod.getName(), useDataProvider.value());
}
 
源代码14 项目: bazel   文件: DesugarRunner.java
/**
 * In replacement of {@link BlockJUnit4ClassRunner#validatePublicVoidNoArgMethods} for @Test
 * method signature validation.
 */
private void validatePublicVoidMethodsWithInjectableArgs(
    Class<? extends Annotation> annotation, boolean isStatic, List<Throwable> errors) {
  List<FrameworkMethod> methods = getTestClass().getAnnotatedMethods(annotation);
  for (FrameworkMethod eachTestMethod : methods) {
    eachTestMethod.validatePublicVoid(isStatic, errors);
    validateInjectableParameters(eachTestMethod, errors);
    validateParameterValueSource(eachTestMethod, errors);
  }
}
 
源代码15 项目: registry   文件: CustomParameterizedRunner.java
private FrameworkMethod getParametersMethod() throws Exception {
    List<FrameworkMethod> methods = testClass
            .getAnnotatedMethods(Parameters.class);
    for (FrameworkMethod each : methods) {
        if (each.isStatic() && each.isPublic()) {
            return each;
        }
    }

    throw new Exception("No public static parameters method on class "
            + testClass.getName());
}
 
源代码16 项目: pravega   文件: SystemTestRunner.java
@Override
protected void runChild(final FrameworkMethod method, RunNotifier notifier) {
    Description description = describeChild(method);
    if (isIgnored(method)) {
        notifier.fireTestIgnored(description);
    } else {
        //read the type of testExecutor from system property. This is sent by the gradle task. By default
        //the tests are executed locally.
        TestExecutorType executionType = TestExecutorType.valueOf(getConfig("execType", "LOCAL"));
        //sleep for 15 seconds before running tests, remove once pravega/pravega/issues/1665 is resolved
        Exceptions.handleInterrupted(() -> TimeUnit.SECONDS.sleep(15));
        invokeTest(notifier, executionType, method);
    }
}
 
源代码17 项目: sql-layer   文件: NamedParameterizedRunner.java
boolean onlyIfFilter(FrameworkMethod method) throws OnlyIfException {
    OnlyIf onlyIf = method.getAnnotation(OnlyIf.class);
    if (onlyIf != null) {
        if (!runOnlyIf(onlyIf.value(), true)) {
            return false;
        }
    }
    OnlyIfNot onlyIfNot = method.getAnnotation(OnlyIfNot.class);
    return onlyIfNot == null || runOnlyIf(onlyIfNot.value(), false);
}
 
源代码18 项目: j2cl   文件: AsyncTestRunner.java
@Override
protected void validatePublicVoidNoArgMethods(
    Class<? extends Annotation> annotation, boolean isStatic, List<Throwable> errors) {
  List<FrameworkMethod> methods = getTestClass().getAnnotatedMethods(annotation);

  for (FrameworkMethod eachTestMethod : methods) {
    validateTestMethod(isStatic, errors, eachTestMethod);
  }
}
 
源代码19 项目: sql-layer   文件: NamedParameterizedRunner.java
boolean expectedToPass(FrameworkMethod method)
{
    if (overrideOn)
    {
        return true;
    }
    if (! parameterization.expectedToPass())
    {
        return false;
    }
    Failing failing = method.getAnnotation(Failing.class);
    if (failing == null)
    {
        return true;
    }
    if (failing.value().length == 0)
    {
        return false;
    }

    for (final String paramName : failing.value())
    {
        if (paramNameUsesRegex(paramName))
        {
            if (paramNameMatchesRegex(parameterization.getName(), paramName))
            {
                return false;
            }
        }
        else if (parameterization.getName().equals(paramName))
        {
            return false;
        }
    }
    return true;
}
 
@Override
protected void runChild(final FrameworkMethod method, RunNotifier notifier) {
  Description description = describeChild(method);
  if (isIgnored(method)) {
    notifier.fireTestIgnored(description);
  } else {
    runLeaf2(methodBlock(method), description, notifier);
  }
}
 
@Override
protected Statement methodBlock(final FrameworkMethod method) {
	return new Statement() {
		@Override
		public void evaluate() throws Throwable {
			String testData = AbstractParallelScenarioRunner.this.testData.remove(method);
			if (testData != null)
				process(testData);
		}
	};
}
 
源代码22 项目: alfresco-sdk   文件: AlfrescoTestRunner.java
@Override
protected void runChild(FrameworkMethod method, RunNotifier notifier) {
    if (areWeRunningInAlfresco()) {
        // Just run the test as normally
        super.runChild(method, notifier);
    } else {
        // We are not running in an Alfresco Server, we need to call one and have it execute the test...
        Description desc = describeChild(method);
        if (method.getAnnotation(Ignore.class) != null) {
            notifier.fireTestIgnored(desc);
        } else {
            callProxiedChild(method, notifier, desc);
        }
    }
}
 
源代码23 项目: stratio-cassandra   文件: MethodComparator.java
private MethodPosition getIndexOfMethodPosition(final Object method)
{
    if (method instanceof FrameworkMethod)
    {
        return this.getIndexOfMethodPosition((FrameworkMethod) method);
    }
    else if (method instanceof Method)
    {
        return this.getIndexOfMethodPosition((Method) method);
    }
    else
    {
        return new NullMethodPosition();
    }
}
 
源代码24 项目: quickperf   文件: MainJvmAfterJUnitStatement.java
public MainJvmAfterJUnitStatement(
          FrameworkMethod frameworkMethod
        , TestExecutionContext testExecutionContext
        , QuickPerfConfigs quickPerfConfigs
        , Statement junitAfters) {
    this.testExecutionContext = testExecutionContext;
    this.frameworkMethod = frameworkMethod;
    this.testAnnotationConfigs = quickPerfConfigs.getTestAnnotationConfigs();
    this.junitAfters = junitAfters;
}
 
源代码25 项目: wildfly-core   文件: ParameterDescriptions.java
synchronized ParameterDescription take(final FrameworkMethod method) {
    final Queue<ParameterDescription> descriptions = parameters.get(method);
    try {
        if (descriptions == null || descriptions.isEmpty()) {
            return null;
        }
        return descriptions.poll();
    } finally {
        if (descriptions != null && descriptions.isEmpty()) {
            parameters.remove(method);
        }
    }
}
 
源代码26 项目: astor   文件: RetryRunner.java
@Override
public Statement methodInvoker(final FrameworkMethod method,
                               Object test) {
    final Statement singleTryStatement = super.methodInvoker(method, test);
    return new Statement() {
        /**
         * Evaluate the statement.
         * We attempt several runs for the test, at most MAX_ATTEMPTS.
         * if one attempt succeeds, we succeed, if all attempts fail, we
         * fail with the reason corresponding to the last attempt
         */
        @Override
        public void evaluate() throws Throwable {
            Throwable failureReason = null;

            final Retry retry = method.getAnnotation(Retry.class);
            if (retry == null) {
                // Do a single test run attempt.
                singleTryStatement.evaluate();
            } else {
                final int numRetries = retry.value();

                for (int i = 0; i < numRetries; ++i) {
                    try {
                        // Do a single test run attempt.
                        singleTryStatement.evaluate();
                        // Attempt succeeded, stop evaluation here.
                        return;
                    } catch (Throwable t) {
                        // Attempt failed, store the reason.
                        failureReason = t;
                    }
                }

                // All attempts failed.
                throw failureReason;
            }
        }
    };
}
 
源代码27 项目: junit-dataprovider   文件: TestGeneratorTest.java
@Test
public void testGenerateExplodedTestMethodsForShouldReturnEmptyListIfArgumentIsNull() {
    // Given:

    // When:
    List<FrameworkMethod> result = underTest.generateExplodedTestMethodsFor(null, null);

    // Then:
    assertThat(result).isEmpty();
}
 
源代码28 项目: Pushjet-Android   文件: TestResources.java
public Statement apply(Statement base, final FrameworkMethod method, Object target) {
    final Statement statement = resources.apply(base, method, target);
    return new Statement() {
        @Override
        public void evaluate() throws Throwable {
            String className = method.getMethod().getDeclaringClass().getSimpleName();
            maybeCopy(String.format("%s/shared", className));
            maybeCopy(String.format("%s/%s", className, method.getName()));
            for (String extraResource : extraResources) {
                maybeCopy(extraResource);
            }
            statement.evaluate();
        }
    };
}
 
源代码29 项目: dsl-devkit   文件: ClassRunner.java
/** {@inheritDoc} */
@Override
protected List<FrameworkMethod> computeTestMethods() {
  final Collection<FrameworkMethod> result = Sets.newHashSet();
  for (final Class<? extends Annotation> annotationClass : TEST_ANNOTATIONS) {
    result.addAll(getTestClass().getAnnotatedMethods(annotationClass));
  }
  return Lists.newArrayList(result);
}
 
源代码30 项目: qpid-jms   文件: QpidJMSTestRunner.java
/**
 * Check for the presence of a {@link Repeat} annotation and return a {@link RepeatStatement}
 * to handle executing the test repeated or the original value if not repeating.
 *
 * @return either a {@link RepeatStatement}, or the supplied {@link Statement} as appropriate.
 */
protected Statement withPotentialRepeat(FrameworkMethod frameworkMethod, Statement next) {

    Repeat repeatAnnotation = frameworkMethod.getAnnotation(Repeat.class);

    if (repeatAnnotation != null) {
        next = RepeatStatement.builder().build(repeatAnnotation, next);
    }

    return next;
}
 
 类所在包
 同包方法