Java 类org.junit.runners.model.InitializationError 实例源码

项目:courgette-jvm    文件:Courgette.java   
public Courgette(Class clazz) throws IOException, InitializationError {
    super(clazz);
    classLoader = clazz.getClassLoader();

    final CourgetteOptions courgetteOptions = getCourgetteOptions(clazz);
    courgetteProperties = new CourgetteProperties(courgetteOptions, createSessionId(), courgetteOptions.threads());

    final CourgetteFeatureLoader courgetteFeatureLoader = new CourgetteFeatureLoader(courgetteProperties);
    cucumberFeatures = courgetteFeatureLoader.getCucumberFeatures();

    runtimeOptions = courgetteFeatureLoader.getCucumberRuntimeOptions();

    runnerInfoList = new ArrayList<>();

    if (courgetteOptions.runLevel().equals(CourgetteRunLevel.FEATURE)) {
        cucumberFeatures.forEach(feature -> runnerInfoList.add(new CourgetteRunnerInfo(courgetteProperties, feature, null)));
    } else {
        final Map<CucumberFeature, Integer> scenarios = courgetteFeatureLoader.getCucumberScenarios();
        scenarios
                .keySet()
                .forEach(scenario -> runnerInfoList.add(new CourgetteRunnerInfo(courgetteProperties, scenario, scenarios.get(scenario))));
    }
}
项目:Oleaster    文件:RoboOleaster.java   
public RoboOleaster(Class testClass) throws InitializationError {
    super(testClass);
    Config config = getConfig(testClass);
    AndroidManifest androidManifest = getAppManifest(config);
    interceptors = new Interceptors(findInterceptors());
    SdkEnvironment sdkEnvironment = getSandbox(config, androidManifest);

    // Configure shadows *BEFORE* setting the ClassLoader. This is necessary because
    // creating the ShadowMap loads all ShadowProviders via ServiceLoader and this is
    // not available once we install the Robolectric class loader.
    configureShadows(sdkEnvironment);

    Class bootstrappedTestClass = sdkEnvironment.bootstrappedClass(testClass);
    try {

        this.oleasterRobolectricRunner = sdkEnvironment
                .bootstrappedClass(OleasterRobolectricRunner.class)
                .getConstructor(Class.class, SdkEnvironment.class, Config.class, AndroidManifest.class)
                .newInstance(bootstrappedTestClass, sdkEnvironment, config, androidManifest);

    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
项目:spockito    文件:Spockito.java   
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;
}
项目:Bytecoder    文件:BytecoderUnitTestRunner.java   
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);
        }
    }
}
项目:junit-easy-tools    文件:AssignmentsStatement.java   
private void runWithIncompleteAssignments(ProducerAssignments assignments) throws Throwable {
    List<ParameterProducer> parameterProducers = assignments.potentialNextParameterProducers();
    if (parameterProducers.isEmpty()) {
        throw new InitializationError(
                "No @DataProducer found to inject to suite method " + method.getName());
    }
    for (ParameterProducer parameterProducer : parameterProducers) {
        runWithAssignments(assignments.assignNext(parameterProducer));
    }
}
项目:junit-easy-tools    文件:TestObject.java   
private void validateFactoryMethod(Method factoryMethod) throws InitializationError {
    if (!factoryMethod.getReturnType().isAssignableFrom(testClass.getJavaClass())) {
        throw new InitializationError("Illegal factory method return type.");
    }
    if (!Modifier.isStatic(factoryMethod.getModifiers())) {
        throw new InitializationError("@FactoryMethod must be static!");
    }
}
项目:junit-easy-tools    文件:PotentialAssignments.java   
private static Type getMethodGenericReturnType (Method method) throws InitializationError {
    final Type genericReturnType = method.getGenericReturnType();
    if (genericReturnType instanceof ParameterizedTypeImpl) {
        final Type[] actualTypeArguments = ((ParameterizedTypeImpl) genericReturnType).getActualTypeArguments();
        return actualTypeArguments[0];
    }
    throw new InitializationError(
            "Illegal return type of " + genericReturnType + " for method as @DataProducer");
}
项目:junit-easy-tools    文件:ProducerAssignmentsMethodAsProducerTest.java   
@Test
public void shouldValidateMethodProducerReturnType() throws Exception {
    TestClass testClass = new TestClass(ProducerIsNotCollection.class);
    ProducerAssignments assignments = ProducerAssignments.allUnassigned(
            testClass, testClass.getJavaClass().getMethod("a", String.class));

    assertThatExceptionOfType(InitializationError.class)
            .isThrownBy(assignments::potentialNextParameterProducers);
}
项目:junit-easy-tools    文件:JUnitEasyToolsValidationTest.java   
@Test
public void shouldThrowExceptionOnNoDataProducer() throws Throwable {
    Method testMethod = NoDataProducer.class.getMethod("a", String.class);
    FrameworkMethod method = new FrameworkMethod(testMethod);
    FrameworkMethod spyMethod = spy(method);
    when(spyMethod.getAnnotation(Ignore.class)).thenReturn(null);
    assertThatExceptionOfType(InitializationError.class).isThrownBy(() ->
            new JUnitEasyTools(NoDataProducer.class).methodBlock(method).evaluate());
}
项目:Reer    文件:AbstractMultiTestRunner.java   
private void initExecutions() {
    if (!executionsInitialized) {
        try {
            Runner descriptionProvider = createRunnerFor(Arrays.asList(target), Collections.<Filter>emptyList());
            templateDescription = descriptionProvider.getDescription();
        } catch (InitializationError initializationError) {
            throw UncheckedException.throwAsUncheckedException(initializationError);
        }
        createExecutions();
        for (Execution execution : executions) {
            execution.init(target, templateDescription);
        }
        executionsInitialized = true;
    }
}
项目:n4js    文件:JUnitGuiceClassRunner.java   
private Iterable<? extends Module> toModules(final Class<? extends Module>[] baseModules) {
    return transform(newArrayList(baseModules), moduleClass -> {
        try {
            return moduleClass.newInstance();
        } catch (InstantiationException | IllegalAccessException e) {
            throw new RuntimeException(new InitializationError(e));
        }
    });
}
项目:dockerunit    文件:DockerUnitRunner.java   
public DockerUnitRunner(Class<?> klass) throws InitializationError {
    super(klass);
    ServiceLoader<DiscoveryProviderFactory> loader = ServiceLoader.load(DiscoveryProviderFactory.class);
    List<DiscoveryProviderFactory> implementations = new ArrayList<>();
    loader.forEach(impl -> {
        logger.info("Found discovery provider factory of type " + impl.getClass().getSimpleName());
        implementations.add(impl);
    });
    if(implementations.size() > 0) {
        logger.info("Using discovery provider factory " + implementations.get(0).getClass().getSimpleName());
        discoveryProvider = implementations.get(0).getProvider();
    } else {
        throw new InitializationError("No discovery provider factory found. Aborting test.");
    }
}
项目:easy-test    文件:EasySuite.java   
/**
 * Called by this class and subclasses once the runners making up the suite have been determined
 *
 * @param klass   root of the suite
 * @param runners for each class in the suite, a {@link Runner}
 */
protected EasySuite(Class<?> klass, List<Runner> runners) throws InitializationError {
    super(klass);
    try {
        Class.forName(klass.getName());
    } catch (Exception e) {
        e.printStackTrace();
    }
    this.runners = Collections.unmodifiableList(runners);
}
项目:Oleaster    文件:OleasterRobolectricRunner.java   
public OleasterRobolectricRunner(
        Class<?> testClass,
        SdkEnvironment sandbox,
        Config config,
        AndroidManifest androidManifest)
        throws
        InitializationError {
    super(testClass);
    this.sandbox = sandbox;

    this.config = config;
    this.androidManifest = androidManifest;
}
项目:spockito    文件:SingleRowMultiTestRunner.java   
public SingleRowMultiTestRunner(final Class<?> clazz,
                                final TableRow tableRow,
                                final ValueConverter defaultValueConverter) throws InitializationError {
    super(clazz);
    this.tableRow = Objects.requireNonNull(tableRow);
    this.defaultValueConverter = Objects.requireNonNull(defaultValueConverter);
    validate();
}
项目:spockito    文件:SingleTestMultiRowRunner.java   
public SingleTestMultiRowRunner(final Class<?> clazz,
                                final FrameworkMethod testMethod,
                                final ValueConverter methodValueConverter) throws InitializationError {
    super(clazz);
    this.testMethod = Objects.requireNonNull(testMethod);
    this.methodValueConverter = Objects.requireNonNull(methodValueConverter);
    validate();
}
项目:spockito    文件:SingleTestMultiRowRunner.java   
protected void validate() throws InitializationError {
    final List<Throwable> errors = new ArrayList<>();
    try {
        super.collectInitializationErrors(errors);
    } catch (final Exception e) {
        errors.add(e);
    }
    if (!errors.isEmpty()) {
        throw new InitializationError(testMethod + ": " + errors.get(0));
    }
}
项目:aws-sdk-java-v2    文件:ResourceCentricBlockJUnit4ClassRunner.java   
public ResourceCentricBlockJUnit4ClassRunner(Class<?> klass)
        throws InitializationError {
    super(klass);

    classRequiredResourcesAnnotation = klass.getAnnotation(RequiredResources.class);
    resourcesToBeDestroyedAfterAllTests = new HashSet<TestResource>();
}
项目:courgette-jvm    文件:Courgette.java   
@Override
public List<FeatureRunner> getChildren() {
    final Runtime runtime = createRuntime(runtimeOptions);
    final JUnitReporter jUnitReporter = new JUnitReporter(runtimeOptions.reporter(classLoader), runtimeOptions.formatter(classLoader), runtimeOptions.isStrict(), new JUnitOptions(runtimeOptions.getJunitOptions()));

    final List<FeatureRunner> children = new ArrayList<>();
    this.cucumberFeatures.forEach(cucumberFeature -> {
        try {
            children.add(new FeatureRunner(cucumberFeature, runtime, jUnitReporter));
        } catch (InitializationError error) {
            error.printStackTrace();
        }
    });
    return children;
}
项目:digits-migration-helper-android    文件:RobolectricGradleTestRunner.java   
public RobolectricGradleTestRunner(Class<?> testClass) throws InitializationError {
    super(testClass);
    String buildVariant = (BuildConfig.FLAVOR.isEmpty() ? "" : BuildConfig.FLAVOR+ "/") + BuildConfig.BUILD_TYPE;
    String intermediatesPath = BuildConfig.class.getResource("").toString().replace("file:", "");
    intermediatesPath = intermediatesPath.substring(0, intermediatesPath.indexOf("/classes"));

    System.setProperty("android.package", BuildConfig.APPLICATION_ID);
    System.setProperty("android.manifest", intermediatesPath + "/manifests/full/" + buildVariant + "/AndroidManifest.xml");
    System.setProperty("android.resources", intermediatesPath + "/res/" + buildVariant);
    System.setProperty("android.assets", intermediatesPath + "/assets/" + buildVariant);
}
项目:easy-test    文件:EasySuite.java   
private static Class<?>[] getAnnotatedClasses(Class<?> klass) throws InitializationError {
    EasySuite.SuiteClasses annotation = klass.getAnnotation(EasySuite.SuiteClasses.class);
    if (annotation == null) {
        throw new InitializationError(String.format("class '%s' must have a SuiteClasses annotation", klass.getName()));
    }
    return annotation.value();
}
项目:xtf    文件:XTFTestSuite.java   
@Synchronized
private static List<Runner> getRunners(@NonNull Class<?> suiteClass, @NonNull RunnerBuilder builder)
        throws InitializationError {

    List<Runner> runners = RUNNERS_CACHE.get(suiteClass);
    if (runners == null) {
        final List<Class<?>> testClasses = resolveTestClasses(suiteClass);
        runners = Collections.unmodifiableList(builder.runners(suiteClass, testClasses));
        RUNNERS_CACHE.put(suiteClass, runners);
        TEST_CLASSES_CACHE.put(suiteClass, testClasses);
    }
    return runners;
}
项目:xtf    文件:XTFTestSuite.java   
private static List<Class<?>> resolveTestClasses(Class<?> suiteClass) throws InitializationError {
    try {
        log.info("action=resolving-test-classes status=START suite={}", suiteClass);
        final List<Class<?>> classes = new XTFTestSuiteHelper(suiteClass).resolveTestClasses();
        log.info("action=resolving-test-classes status=START suite={} testClasses={}", suiteClass, classes.size());
        log.debug("Test classes:", classes.size());
        classes.forEach(c -> log.debug(" - {}", c.getName()));
        return classes;
    } catch (URISyntaxException | IOException e) {
        throw new InitializationError(e);
    }
}
项目:personium-core    文件:PersoniumIntegTestRunner.java   
/**
 * コンストラクタ.
 * @param klass klass
 * @throws InitializationError InitializationError
 * @throws IOException IOException
 * @throws CertificateException CertificateException
 * @throws InvalidKeySpecException InvalidKeySpecException
 * @throws NoSuchAlgorithmException NoSuchAlgorithmException
 * @throws javax.security.cert.CertificateException CertificateException
 */
public PersoniumIntegTestRunner(Class<?> klass)
        throws InitializationError, NoSuchAlgorithmException,
        InvalidKeySpecException, CertificateException, IOException, javax.security.cert.CertificateException {
    super(klass);
    // トークン処理ライブラリの初期設定.
    TransCellAccessToken.configureX509(PersoniumUnitConfig.getX509PrivateKey(),
            PersoniumUnitConfig.getX509Certificate(), PersoniumUnitConfig.getX509RootCertificate());
    LocalToken.setKeyString(PersoniumUnitConfig.getTokenSecretKey());
    DataCryptor.setKeyString(PersoniumUnitConfig.getTokenSecretKey());
    PersoniumThread.createThreadPool(PersoniumUnitConfig.getThreadPoolNum());
}
项目:ArchUnit    文件:ArchUnitRunnerRunsRuleFieldsTest.java   
@Test
public void should_fail_on_wrong_field_type() throws InitializationError {
    ArchUnitRunner runner = newRunnerFor(WrongArchTestWrongFieldType.class, cache);

    thrown.expectMessage("Rule field " +
            WrongArchTestWrongFieldType.class.getSimpleName() + "." + NO_RULE_AT_ALL_FIELD_NAME +
            " to check must be of type " + ArchRule.class.getSimpleName());

    runner.runChild(ArchUnitRunnerTestUtils.getRule(NO_RULE_AT_ALL_FIELD_NAME, runner), runNotifier);
}
项目:ArchUnit    文件:ArchUnitRunnerRunsRuleFieldsTest.java   
@Test
public void should_skip_ignored_test() throws InitializationError {
    ArchUnitRunner runner = newRunnerFor(IgnoredArchTest.class, cache);

    runner.runChild(ArchUnitRunnerTestUtils.getRule(RULE_ONE_IN_IGNORED_TEST, runner), runNotifier);
    runner.runChild(ArchUnitRunnerTestUtils.getRule(RULE_TWO_IN_IGNORED_TEST, runner), runNotifier);

    verify(runNotifier, times(2)).fireTestIgnored(descriptionCaptor.capture());

    assertThat(descriptionCaptor.getAllValues()).extractingResultOf("getMethodName")
            .contains(RULE_ONE_IN_IGNORED_TEST, RULE_TWO_IN_IGNORED_TEST);
}
项目:aws-sdk-java-v2    文件:ResourceCentricBlockJUnit4ClassRunner.java   
public ResourceCentricBlockJUnit4ClassRunner(Class<?> klass)
        throws InitializationError {
    super(klass);

    classRequiredResourcesAnnotation = klass.getAnnotation(RequiredResources.class);
    resourcesToBeDestroyedAfterAllTests = new HashSet<TestResource>();
}
项目:ArchUnit    文件:ArchUnitRunnerRunsMethodsTest.java   
@Test
public void executes_test_methods_and_supplies_JavaClasses() throws InitializationError {
    runner.runChild(getRule(testSomething, runner), runNotifier);
    verify(runNotifier, never()).fireTestFailure(any(Failure.class));
    verify(runNotifier).fireTestFinished(descriptionCaptor.capture());
    assertThat(descriptionCaptor.getAllValues()).extractingResultOf("getMethodName")
            .contains(testSomething);
    assertThat(ArchTestWithTestMethod.suppliedClasses).as("Supplied Classes").isEqualTo(cachedClasses);
}
项目:ArchUnit    文件:ArchUnitRunnerRunsMethodsTest.java   
@Test
public void ignores_all_methods_in_classes_annotated_with_ArchIgnore() throws InitializationError {
    ArchUnitRunner runner = new ArchUnitRunner(IgnoredArchTest.class);

    runner.runChild(getRule(toBeIgnoredOne, runner), runNotifier);
    runner.runChild(getRule(toBeIgnoredTwo, runner), runNotifier);
    verify(runNotifier, times(2)).fireTestIgnored(descriptionCaptor.capture());
    assertThat(descriptionCaptor.getAllValues()).extractingResultOf("getMethodName")
            .contains(toBeIgnoredOne)
            .contains(toBeIgnoredTwo);
}
项目:ArchUnit    文件:ArchUnitRunnerRunsMethodsTest.java   
@Test
public void ignores_methods_annotated_with_ArchIgnore() throws InitializationError {
    ArchUnitRunner runner = new ArchUnitRunner(ArchTestWithIgnoredMethod.class);

    runner.runChild(getRule(toBeIgnored, runner), runNotifier);
    verify(runNotifier).fireTestIgnored(descriptionCaptor.capture());
    assertThat(descriptionCaptor.getValue().toString()).contains(toBeIgnored);
}
项目:ArchUnit    文件:ArchUnitRunnerTestUtils.java   
static ArchUnitRunner newRunnerFor(Class<?> testClass) {
    try {
        return new ArchUnitRunner(testClass);
    } catch (InitializationError initializationError) {
        throw new RuntimeException(initializationError);
    }
}
项目:monarch    文件:SuiteRunner.java   
private static List<Runner> getRunners(final Class<?> klass) throws InitializationError {
  SuiteClasses annotation = klass.getAnnotation(SuiteClasses.class);
  if (annotation == null) {
    throw new InitializationError(
        String.format("class '%s' must have a SuiteClasses annotation", klass.getName()));
  }
  Class<?>[] childClasses = annotation.value();
  List<Runner> runners = new ArrayList<>();
  for (Class childClass : childClasses) {
    runners.add(new SuiteBlockRunner(klass, childClass));
  }
  return runners;
}
项目:resource-verifier    文件:ExternalResourceAwareRunner.java   
public ExternalResourceAwareRunner(Class<?> klass) throws InitializationError {
    super(klass);
    this.executor = new ResourceVerifierExecutor();
    executeResourceVerifiers(klass);
}
项目:junit-easy-tools    文件:TestObjectTest.java   
@Test
public void shouldThrowExceptionOnWrongTypeOfFactory() throws Exception {
    TestClass testClass = new TestClass(WrongFactoryType.class);
    assertThatExceptionOfType(InitializationError.class)
            .isThrownBy(() -> new TestObject(testClass).createTestObject());
}
项目:junit-easy-tools    文件:TestObjectTest.java   
@Test
public void shouldValidateFactoryMethodIsStatic() throws Exception {
    TestClass testClass = new TestClass(NotStaticFactoryMethod.class);
    assertThatExceptionOfType(InitializationError.class)
            .isThrownBy(() -> new TestObject(testClass).createTestObject());
}
项目:Reer    文件:AbstractMultiTestRunner.java   
private Runner createExecutionRunner() throws InitializationError {
    List<? extends Class<?>> targetClasses = loadTargetClasses();
    return createRunnerFor(targetClasses, filters);
}
项目:q-mail    文件:K9RobolectricTestRunner.java   
public K9RobolectricTestRunner(Class<?> testClass) throws InitializationError {
    super(testClass);
}
项目:GitHub    文件:GithubSampleTestRunner.java   
public GithubSampleTestRunner(Class<?> testClass) throws InitializationError {
    super(testClass);
}
项目:dremio-oss    文件:GuavaPatcherRunner.java   
public GuavaPatcherRunner(Class<?> klass) throws InitializationError {
  super(klass);
}
项目:n4js    文件:XpectConfigurationDelegate.java   
/**
 * Runs provided File in Engine. Returns output of execution.
 */
public void execute(ILaunch launch, XpectRunConfiguration runConfiguration) throws RuntimeException {

    Job job = new Job(launch.getLaunchConfiguration().getName()) {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            XpectRunner xr;
            try {
                xr = new XpectRunner(N4IDEXpectTestClass.class);
            } catch (InitializationError e) {
                N4IDEXpectUIPlugin.logError("cannot initialize xpect runner", e);
                return Status.CANCEL_STATUS;
            }

            // TODO support multiple selection
            /*
             * if Project provided, or package files should be discovered there. Also multiple selected files
             */
            String testFileLocation = runConfiguration.getXtFileToRun();

            IXpectURIProvider uriprov = xr.getUriProvider();
            if (uriprov instanceof N4IDEXpectTestURIProvider) {
                ((N4IDEXpectTestURIProvider) uriprov).addTestFileLocation(testFileLocation);
            }

            Result result = new Result();
            RunNotifier notifier = new RunNotifier();
            RunListener listener = result.createListener();
            N4IDEXpectRunListener n4Listener = new N4IDEXpectRunListener();

            notifier.addFirstListener(listener);
            notifier.addListener(n4Listener);

            try {
                notifier.fireTestRunStarted(xr.getDescription());
                xr.run(notifier);
                notifier.fireTestRunFinished(result);
            } finally {
                notifier.removeListener(n4Listener);
                notifier.removeListener(listener);
            }
            // Do something with test run result?
            // return result;

            return Status.OK_STATUS;
        }

    };
    job.setUser(true);
    job.schedule();
}