Java Code Examples for org.junit.runners.model.FrameworkMethod#getName()

The following examples show how to use org.junit.runners.model.FrameworkMethod#getName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BrowserVersionClassRunnerWithParameters.java    From htmlunit with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected String testName(final FrameworkMethod method) {
    String prefix = "";
    if (isNotYetImplemented(method) && !isRealBrowser()) {
        prefix = "(NYI) ";
    }

    String browserString = getBrowserVersion().getNickname();
    if (isRealBrowser()) {
        browserString = "Real " + browserString;
    }

    final String methodName = method.getName();

    if (!maven_) {
        return String.format("%s [%s]", methodName, browserString);
    }
    String className = method.getMethod().getDeclaringClass().getName();
    className = className.substring(className.lastIndexOf('.') + 1);
    return String.format("%s%s [%s]", prefix, className + '.' + methodName, browserString);
}
 
Example 2
Source File: SpecRunner.java    From yatspec with Apache License 2.0 6 votes vote down vote up
@Override
protected Statement methodInvoker(final FrameworkMethod method, final Object test) {
    final Statement statement = super.methodInvoker(method, test);
    return new Statement() {
        @Override
        public void evaluate() throws Throwable {
            final String fullyQualifiedTestMethod = test.getClass().getCanonicalName() + "." + method.getName();
            final Scenario scenario = testResult.getScenario(method.getName());
            currentScenario.put(fullyQualifiedTestMethod, scenario);

            if (test instanceof WithTestState) {
                TestState testState = ((WithTestState) test).testState();
                currentScenario.get(fullyQualifiedTestMethod).setTestState(testState);
            }
            statement.evaluate();
        }
    };
}
 
Example 3
Source File: AbstractTestExcluder.java    From cache2k with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public Statement apply(Statement statement, FrameworkMethod frameworkMethod, Object o) {
  final String methodName = frameworkMethod.getName();
  final String className = frameworkMethod.getMethod().getDeclaringClass().getName();
  if (isExcluded(methodName)) {
    return new ExcludedStatement(className, methodName, logger);
  } else {
    return statement;
  }
}
 
Example 4
Source File: OrcasParameterizedParallel.java    From orcas with Apache License 2.0 5 votes vote down vote up
@Override
protected String testName( FrameworkMethod pMethod )
{
  if( OrcasCoreIntegrationConfigSystemProperties.getOrcasCoreIntegrationConfig().isFlatTestNames() )
  {
    return getName() + pMethod.getName();
  }
  else
  {
    return super.testName( pMethod );
  }
}
 
Example 5
Source File: Injected.java    From ion-java with Apache License 2.0 5 votes vote down vote up
@Override
protected String testName(FrameworkMethod method)
{
    // Eclipse (Helios) can't display results properly if the names
    // are not unique.
    return method.getName() + getName();
}
 
Example 6
Source File: PolySuite.java    From elk-reasoner with Apache License 2.0 5 votes vote down vote up
private static FrameworkMethod getConfigMethod(TestClass testClass) {
  List<FrameworkMethod> methods = testClass.getAnnotatedMethods(Config.class);
  if (methods.isEmpty()) {
    throw new IllegalStateException("@" + Config.class.getSimpleName() + " method not found");
  }
  if (methods.size() > 1) {
    throw new IllegalStateException("Too many @" + Config.class.getSimpleName() + " methods");
  }
  FrameworkMethod method = methods.get(0);
  int modifiers = method.getMethod().getModifiers();
  if (!(Modifier.isStatic(modifiers) && Modifier.isPublic(modifiers))) {
    throw new IllegalStateException("@" + Config.class.getSimpleName() + " method \"" + method.getName() + "\" must be public static");
  }
  return method;
}
 
Example 7
Source File: MetaRunner.java    From tomee with Apache License 2.0 5 votes vote down vote up
/**
 * Flags an error if you have annotated a test with both @Test and @Keys. Any method annotated with @Test will be ignored anyways.
 */
@Override
protected void collectInitializationErrors(final List<Throwable> errors) {
    super.collectInitializationErrors(errors);
    final List<FrameworkMethod> methodsAnnotatedWithKeys = getTestClass().getAnnotatedMethods(MetaTest.class);
    for (final FrameworkMethod frameworkMethod : methodsAnnotatedWithKeys) {
        if (frameworkMethod.getAnnotation(Test.class) != null) {
            final String gripe = "The method " + frameworkMethod.getName() + "() can only be annotated with @MetaTest";
            errors.add(new Exception(gripe));
        }
    }
}
 
Example 8
Source File: CmmnTestRunner.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
protected String getCmmnDefinitionResource(FrameworkMethod method) {
    String className = method.getMethod().getDeclaringClass().getName().replace('.', '/');
    String methodName = method.getName();
    for (String suffix : CmmnDeployer.CMMN_RESOURCE_SUFFIXES) {
        String resource = className + "." + methodName + suffix;
        if (CmmnTestRunner.class.getClassLoader().getResource(resource) != null) {
            return resource;
        }
    }
    return className + "." + method.getName() + ".cmmn";
}
 
Example 9
Source File: TestHdfsHelper.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
public Statement apply(Statement statement, FrameworkMethod frameworkMethod, Object o) {
  TestHdfs testHdfsAnnotation = frameworkMethod.getAnnotation(TestHdfs.class);
  if (testHdfsAnnotation != null) {
    statement = new HdfsStatement(statement, frameworkMethod.getName());
  }
  return super.apply(statement, frameworkMethod, o);
}
 
Example 10
Source File: ATHJUnitRunner.java    From blueocean-plugin with MIT License 5 votes vote down vote up
private void writeScreenShotCause(Throwable t, Object test, FrameworkMethod method) throws IOException {
    WebDriver driver = injector.getInstance(WebDriver.class);
    File file = new File("target/screenshots/"+ test.getClass().getName() + "_" + method.getName() + ".png");

    Throwable cause = t.getCause();
    boolean fromException = false;
    while(cause != null) {
        if(cause instanceof ScreenshotException) {
            ScreenshotException se = ((ScreenshotException) cause);

            byte[] screenshot =  Base64.getMimeDecoder().decode(se.getBase64EncodedScreenshot());

            Files.createParentDirs(file);
            Files.write(screenshot, file);
            logger.info("Wrote screenshot to " + file.getAbsolutePath());
            fromException = true;
            break;
        } else {
            cause = cause.getCause();
        }
    }

    if(!fromException) {
        File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
        FileUtils.copyFile(scrFile, file);
        logger.info("Wrote screenshot to " + file.getAbsolutePath());
    }
}
 
Example 11
Source File: TestHdfsHelper.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
public Statement apply(Statement statement, FrameworkMethod frameworkMethod, Object o) {
  TestHdfs testHdfsAnnotation = frameworkMethod.getAnnotation(TestHdfs.class);
  if (testHdfsAnnotation != null) {
    statement = new HdfsStatement(statement, frameworkMethod.getName());
  }
  return super.apply(statement, frameworkMethod, o);
}
 
Example 12
Source File: TestValidator.java    From junit-dataprovider with Apache License 2.0 5 votes vote down vote up
/**
 * Checks if the given {@code dataProviderMethod} is a valid dataprovider and adds a {@link Exception} to
 * {@code errors} if it
 * <ul>
 * <li>is not public,</li>
 * <li>is not static,</li>
 * <li>takes parameters, or</li>
 * <li>does return a convertible type, see {@link DataConverter#canConvert(java.lang.reflect.Type)}
 * </ul>
 * <p>
 * This method is package private (= visible) for testing.
 * </p>
 *
 * @param dataProviderMethod the method to check
 * @param dataProvider the {@code @}{@link DataProvider} annotation used on {@code dataProviderMethod}
 * @param errors to be "returned" and thrown as {@link InitializationError}
 * @throws NullPointerException iif any argument is {@code null}
 */
public void validateDataProviderMethod(FrameworkMethod dataProviderMethod, DataProvider dataProvider,
        List<Throwable> errors) {

    checkNotNull(dataProviderMethod, "dataProviderMethod must not be null");
    checkNotNull(dataProvider, "dataProvider must not be null");
    checkNotNull(errors, "errors must not be null");

    Method method = dataProviderMethod.getMethod();

    String messageBasePart = "Dataprovider method '" + dataProviderMethod.getName() + "' must";
    if (!Modifier.isPublic(method.getModifiers())) {
        errors.add(new Exception(messageBasePart + " be public"));
    }
    if (!Modifier.isStatic(method.getModifiers())) {
        errors.add(new Exception(messageBasePart + " be static"));
    }
    if (method.getParameterTypes().length != 0
            && (method.getParameterTypes().length != 1 || !method.getParameterTypes()[0]
                    .equals(FrameworkMethod.class))) {
        errors.add(new Exception(messageBasePart + " either have a single FrameworkMethod parameter or none"));
    }
    if (!dataConverter.canConvert(method.getGenericReturnType())) {
        errors.add(new Exception(messageBasePart
                + " either return Object[][], Object[], String[], Iterable<Iterable<?>>, or Iterable<?>, whereby any subtype of Iterable as well as an arbitrary inner type are also accepted"));
    }
    if (dataProvider.value().length > 0) {
        errors.add(new Exception(messageBasePart + " not define @DataProvider.value()"));
    }
}
 
Example 13
Source File: WebTauRunner.java    From webtau with Apache License 2.0 5 votes vote down vote up
private JavaBasedTest createJavaBasedTest(FrameworkMethod method) {
    String canonicalClassName = method.getDeclaringClass().getCanonicalName();

    JavaBasedTest javaBasedTest = new JavaBasedTest(
            method.getName() + idGenerator.incrementAndGet(),
            method.getName());

    WebTauTest webTauTest = javaBasedTest.getTest();
    webTauTest.setClassName(canonicalClassName);
    webTauTest.setShortContainerId(canonicalClassName);

    return javaBasedTest;
}
 
Example 14
Source File: CustomParameterizedBlockJUnit4Runner.java    From registry with Apache License 2.0 4 votes vote down vote up
@Override
protected String testName(FrameworkMethod method) {
    return method.getName() + getName();
}
 
Example 15
Source File: PolySuite.java    From elk-reasoner with Apache License 2.0 4 votes vote down vote up
@Override
protected String testName(FrameworkMethod method) {
  return method.getName() + ": " + testName;
}
 
Example 16
Source File: RdfUnitJunitRunner.java    From RDFUnit with Apache License 2.0 4 votes vote down vote up
private String getTestInputBaseName(FrameworkMethod method) {
    final String basename = method.getAnnotation(TestInput.class).name();
    return basename.isEmpty() ? method.getName() : basename;
}
 
Example 17
Source File: EndToEndRunner.java    From buck with Apache License 2.0 4 votes vote down vote up
private EndToEndEnvironment getEnvironmentForMethod(FrameworkMethod testMethod) {
  String methodName = testMethod.getName();
  Optional<EndToEndEnvironment> environment =
      this.environmentMap.getOrDefault(methodName, Optional.empty());
  return environment.orElse(this.defaultEnv);
}
 
Example 18
Source File: XtextParametrizedRunner.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Implements behavior from: org.junit.runners.Parameterized$TestClassRunnerForParameters
 */
@Override
protected String testName(FrameworkMethod method) {
	return method.getName() + getName();
}
 
Example 19
Source File: GeoWaveITRunner.java    From geowave with Apache License 2.0 4 votes vote down vote up
@Override
protected String testName(final FrameworkMethod method) {
  return method.getName() + " - " + getName();
}
 
Example 20
Source File: TransformersTestParameterized.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
protected String testName(FrameworkMethod method) {
    return method.getName() + getName();
}