org.junit.runners.parameterized.TestWithParameters Java Examples

The following examples show how to use org.junit.runners.parameterized.TestWithParameters. 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: ParameterizedBehaviorTestFactory.java    From FreeBuilder with Apache License 2.0 6 votes vote down vote up
ParameterizedBehaviorTestRunner(TestWithParameters test) throws InitializationError {
  super(test);

  FeatureSet features = FluentIterable
      .from(test.getParameters())
      .filter(FeatureSet.class)
      .first()
      .orNull();
  checkState(features != null, "No FeatureSet parameter found");

  // JDK-8 bug: Cannot use `super::` if the superclass method is protected; see
  //     https://bugs.openjdk.java.net/browse/JDK-8139836
  testing = new SharedBehaviorTesting(
      notifier -> super.childrenInvoker(notifier),
      (method, notifier) -> super.runChild(method, notifier),
      super::createTest,
      super::getDescription,
      super::getTestClass,
      (cls, name) -> Description.createTestDescription(cls, name + test.getParameters()),
      features);
}
 
Example #2
Source File: CustomParameterizedRunner.java    From registry with Apache License 2.0 6 votes vote down vote up
private List<Runner> createRunnersForParameters(
        Iterable<Object> allParameters, String namePattern,
        ParametersRunnerFactory runnerFactory) throws Exception {
    try {
        List<TestWithParameters> tests = createTestsForParameters(
                allParameters, namePattern);
        List<Runner> runners = new ArrayList<Runner>();
        for (TestWithParameters test : tests) {
            runners.add(runnerFactory
                    .createRunnerForTestWithParameters(test));
        }
        return runners;
    } catch (ClassCastException e) {
        throw parametersMethodReturnedWrongType();
    }
}
 
Example #3
Source File: CustomParameterizedRunner.java    From registry with Apache License 2.0 6 votes vote down vote up
private List<Runner> createRunnersForParameters(
        Iterable<Object> allParameters, String namePattern,
        ParametersRunnerFactory runnerFactory) throws Exception {
    try {
        List<TestWithParameters> tests = createTestsForParameters(
                allParameters, namePattern);
        List<Runner> runners = new ArrayList<Runner>();
        for (TestWithParameters test : tests) {
            runners.add(runnerFactory
                    .createRunnerForTestWithParameters(test));
        }
        return runners;
    } catch (ClassCastException e) {
        throw parametersMethodReturnedWrongType();
    }
}
 
Example #4
Source File: Live.java    From denominator with Apache License 2.0 5 votes vote down vote up
protected List<Runner> createRunners(Class<?> klass) throws InitializationError {
  List<Runner> result = new ArrayList<Runner>();
  TestWithParameters test = new TestWithParameters(graph.manager().toString(), getTestClass(),
                                                   Arrays.<Object>asList(graph.manager()));
  result.add(new BlockJUnit4ClassRunnerWithParameters(test));
  return Collections.unmodifiableList(result);
}
 
Example #5
Source File: CustomParameterizedBlockJUnit4Runner.java    From registry with Apache License 2.0 5 votes vote down vote up
public CustomParameterizedBlockJUnit4Runner(TestWithParameters test)
        throws InitializationError {
    super(test.getTestClass().getJavaClass());
    parameters = test.getParameters().toArray(
            new Object[test.getParameters().size()]);
    name = test.getName();
}
 
Example #6
Source File: CustomParameterizedRunner.java    From registry with Apache License 2.0 5 votes vote down vote up
private TestWithParameters createTestWithParameters(
        TestClass testClass, String pattern, int index,
        Object[] parameters) {
    String finalPattern = pattern.replaceAll("\\{index\\}",
            Integer.toString(index));
    String name = MessageFormat.format(finalPattern, parameters);
    return new TestWithParameters("[" + name + "]", testClass,
            Arrays.asList(parameters));
}
 
Example #7
Source File: CustomParameterizedRunner.java    From registry with Apache License 2.0 5 votes vote down vote up
private List<TestWithParameters> createTestsForParameters(
        Iterable<Object> allParameters, String namePattern)
        throws Exception {
    int i = 0;
    List<TestWithParameters> children = new ArrayList<TestWithParameters>();
    for (Object parametersOfSingleTest : allParameters) {
        children.add(createTestWithNotNormalizedParameters(namePattern,
                i++, parametersOfSingleTest));
    }
    return children;
}
 
Example #8
Source File: CustomParameterizedRunner.java    From registry with Apache License 2.0 5 votes vote down vote up
private TestWithParameters createTestWithNotNormalizedParameters(
        String pattern, int index, Object parametersOrSingleParameter) {
    Object[] parameters = (parametersOrSingleParameter instanceof Object[]) ? (Object[]) parametersOrSingleParameter
            : new Object[] { parametersOrSingleParameter };
    return createTestWithParameters(testClass, pattern, index,
            parameters);
}
 
Example #9
Source File: CustomParameterizedBlockJUnit4Runner.java    From registry with Apache License 2.0 5 votes vote down vote up
public CustomParameterizedBlockJUnit4Runner(TestWithParameters test)
        throws InitializationError {
    super(test.getTestClass().getJavaClass());
    parameters = test.getParameters().toArray(
            new Object[test.getParameters().size()]);
    name = test.getName();
}
 
Example #10
Source File: CustomParameterizedRunner.java    From registry with Apache License 2.0 5 votes vote down vote up
private TestWithParameters createTestWithParameters(
        TestClass testClass, String pattern, int index,
        Object[] parameters) {
    String finalPattern = pattern.replaceAll("\\{index\\}",
            Integer.toString(index));
    String name = MessageFormat.format(finalPattern, parameters);
    return new TestWithParameters("[" + name + "]", testClass,
            Arrays.asList(parameters));
}
 
Example #11
Source File: CustomParameterizedRunner.java    From registry with Apache License 2.0 5 votes vote down vote up
private List<TestWithParameters> createTestsForParameters(
        Iterable<Object> allParameters, String namePattern)
        throws Exception {
    int i = 0;
    List<TestWithParameters> children = new ArrayList<TestWithParameters>();
    for (Object parametersOfSingleTest : allParameters) {
        children.add(createTestWithNotNormalizedParameters(namePattern,
                i++, parametersOfSingleTest));
    }
    return children;
}
 
Example #12
Source File: BrowserParameterizedRunner.java    From htmlunit with Apache License 2.0 5 votes vote down vote up
private static TestWithParameters createTestWithParameters(
        final TestClass testClass, final String pattern, final int index, final Object[] parameters) {
    final String finalPattern = pattern.replaceAll("\\{index\\}",
            Integer.toString(index));
    final String name = MessageFormat.format(finalPattern, parameters);
    return new TestWithParameters("[" + name + "]", testClass,
            Arrays.asList(parameters));
}
 
Example #13
Source File: BrowserParameterizedRunner.java    From htmlunit with Apache License 2.0 5 votes vote down vote up
private List<TestWithParameters> createTestsForParameters(
        final Iterable<Object> allParameters, final String namePattern) {
    int i = 0;
    final List<TestWithParameters> children = new ArrayList<>();
    for (final Object parametersOfSingleTest : allParameters) {
        children.add(createTestWithNotNormalizedParameters(namePattern,
                i++, parametersOfSingleTest));
    }
    return children;
}
 
Example #14
Source File: BrowserParameterizedRunner.java    From htmlunit with Apache License 2.0 5 votes vote down vote up
private TestWithParameters createTestWithNotNormalizedParameters(
        final String pattern, final int index, final Object parametersOrSingleParameter) {
    final Object[] parameters = (parametersOrSingleParameter instanceof Object[])
            ? (Object[]) parametersOrSingleParameter
            : new Object[] {parametersOrSingleParameter};
    return createTestWithParameters(getTestClass(), pattern, index,
            parameters);
}
 
Example #15
Source File: CustomParameterizedRunner.java    From registry with Apache License 2.0 5 votes vote down vote up
private TestWithParameters createTestWithNotNormalizedParameters(
        String pattern, int index, Object parametersOrSingleParameter) {
    Object[] parameters = (parametersOrSingleParameter instanceof Object[]) ? (Object[]) parametersOrSingleParameter
            : new Object[] { parametersOrSingleParameter };
    return createTestWithParameters(testClass, pattern, index,
            parameters);
}
 
Example #16
Source File: MixinAwareParametersRunnerFactory.java    From servicetalk with Apache License 2.0 4 votes vote down vote up
private MixinAwareRunnerWithParameters(final TestWithParameters test) throws InitializationError {
    super(test);
}
 
Example #17
Source File: MixinAwareParametersRunnerFactory.java    From servicetalk with Apache License 2.0 4 votes vote down vote up
@Override
public Runner createRunnerForTestWithParameters(final TestWithParameters testWithParameters)
        throws InitializationError {
    return new MixinAwareRunnerWithParameters(testWithParameters);
}
 
Example #18
Source File: ParameterizedRunnerFactory.java    From es6draft with MIT License 4 votes vote down vote up
@Override
public Runner createRunnerForTestWithParameters(TestWithParameters test) throws InitializationError {
    return new ParameterizedRunner(test);
}
 
Example #19
Source File: ParameterizedRunner.java    From es6draft with MIT License 4 votes vote down vote up
public ParameterizedRunner(TestWithParameters test) throws InitializationError {
    super(test);
}
 
Example #20
Source File: KurentoBlockJUnit4ClassRunnerWithParametersFactory.java    From kurento-java with Apache License 2.0 4 votes vote down vote up
@Override
public Runner createRunnerForTestWithParameters(TestWithParameters test)
    throws InitializationError {
  return new KurentoBlockJUnit4ClassRunnerWithParameters(test);
}
 
Example #21
Source File: KurentoBlockJUnit4ClassRunnerWithParameters.java    From kurento-java with Apache License 2.0 4 votes vote down vote up
public KurentoBlockJUnit4ClassRunnerWithParameters(TestWithParameters test)
    throws InitializationError {
  super(test);
}
 
Example #22
Source File: OrcasParameterizedParallel.java    From orcas with Apache License 2.0 4 votes vote down vote up
public OrcasBlockJUnit4ClassRunnerWithParameters( TestWithParameters pTest ) throws InitializationError
{
  super( pTest );

  testName = (String)pTest.getParameters().get( 0 );
}
 
Example #23
Source File: OrcasParameterizedParallel.java    From orcas with Apache License 2.0 4 votes vote down vote up
public Runner createRunnerForTestWithParameters( TestWithParameters pTest ) throws InitializationError
{
  return new OrcasBlockJUnit4ClassRunnerWithParameters( pTest );
}
 
Example #24
Source File: PtlBlockJUnit4ClassRunnerWithParametersFactory.java    From hifive-pitalium with Apache License 2.0 4 votes vote down vote up
@Override
public Runner createRunnerForTestWithParameters(TestWithParameters test) throws InitializationError {
	return new PtlBlockJUnit4ClassRunnerWithParameters(test);
}
 
Example #25
Source File: VertxUnitRunnerWithParameters.java    From vertx-unit with Apache License 2.0 4 votes vote down vote up
protected VertxUnitRunnerWithParameters(TestWithParameters test) throws InitializationError {
  super(test.getTestClass().getJavaClass());
  parameters = test.getParameters().toArray(
      new Object[test.getParameters().size()]);
  name = test.getName();
}
 
Example #26
Source File: VertxUnitRunnerWithParametersFactory.java    From vertx-unit with Apache License 2.0 4 votes vote down vote up
@Override
public Runner createRunnerForTestWithParameters(TestWithParameters test) throws InitializationError {
  return new VertxUnitRunnerWithParameters(test);
}
 
Example #27
Source File: ParameterizedBehaviorTestFactory.java    From FreeBuilder with Apache License 2.0 4 votes vote down vote up
@Override
public Runner createRunnerForTestWithParameters(TestWithParameters test)
    throws InitializationError {
  return new ParameterizedBehaviorTestRunner(test);
}
 
Example #28
Source File: BrowserParameterizedRunner.java    From htmlunit with Apache License 2.0 4 votes vote down vote up
/**
 * Only called reflectively. Do not use programmatically.
 * @param klass the class
 * @throws Throwable if an error occurs
 */
public BrowserParameterizedRunner(final Class<WebTestCase> klass) throws Throwable {
    super(klass, Collections.<Runner>emptyList());

    verifyDefaultMEthod();

    final Parameters parameters = getParametersMethod().getAnnotation(Parameters.class);

    final List<TestWithParameters> tests = createTestsForParameters(
            allParameters(), parameters.name());

    if (BrowserVersionClassRunner.containsTestMethods(klass)) {
        final Set<String> browsers = WebDriverTestCase.getBrowsersProperties();
        if (WebDriverTestCase.class.isAssignableFrom(klass)) {
            if (browsers.contains("chrome")) {
                runners_.add(new BrowserVersionClassRunnerWithParameters(
                        klass, BrowserVersion.CHROME, true, tests));
            }
            if (browsers.contains("ff")) {
                runners_.add(new BrowserVersionClassRunnerWithParameters(
                        klass, BrowserVersion.FIREFOX, true, tests));
            }
            if (browsers.contains("ff68")) {
                runners_.add(new BrowserVersionClassRunnerWithParameters(
                        klass, BrowserVersion.FIREFOX_68, true, tests));
            }
            if (browsers.contains("ff60")) {
                runners_.add(new BrowserVersionClassRunnerWithParameters(
                        klass, BrowserVersion.FIREFOX_60, true, tests));
            }
            if (browsers.contains("ie")) {
                runners_.add(new BrowserVersionClassRunnerWithParameters(
                        klass, BrowserVersion.INTERNET_EXPLORER, true, tests));
            }
        }

        if (browsers.contains("hu-chrome")) {
            runners_.add(new BrowserVersionClassRunnerWithParameters(
                    klass, BrowserVersion.CHROME, false, tests));
        }
        if (browsers.contains("hu-ff")) {
            runners_.add(new BrowserVersionClassRunnerWithParameters(
                    klass, BrowserVersion.FIREFOX, false, tests));
        }
        if (browsers.contains("hu-ff68")) {
            runners_.add(new BrowserVersionClassRunnerWithParameters(
                    klass, BrowserVersion.FIREFOX_68, false, tests));
        }
        if (browsers.contains("hu-ff60")) {
            runners_.add(new BrowserVersionClassRunnerWithParameters(
                    klass, BrowserVersion.FIREFOX_60, false, tests));
        }
        if (browsers.contains("hu-ie")) {
            runners_.add(new BrowserVersionClassRunnerWithParameters(
                    klass, BrowserVersion.INTERNET_EXPLORER, false, tests));
        }
    }
    else {
        throw new IllegalStateException("No @Test method found");
    }
}
 
Example #29
Source File: CustomParameterizedBlockJUnit4RunnerFactory.java    From registry with Apache License 2.0 4 votes vote down vote up
public Runner createRunnerForTestWithParameters(TestWithParameters test)
        throws InitializationError {
    return new CustomParameterizedBlockJUnit4Runner(test);
}
 
Example #30
Source File: XtextParametersRunnerFactory.java    From solidity-ide with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public Runner createRunnerForTestWithParameters(TestWithParameters test) throws InitializationError {
	return new ParameterizedXtextRunner(test);
}