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

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

源代码1 项目: java-specialagent   文件: AgentRunner.java
/**
 * Creates the {@link TestClass} object for this JUnit runner with the
 * specified test class.
 * <p>
 * This method has been overridden to retrofit the {@link FrameworkMethod}
 * objects.
 *
 * @param testClass The test class.
 * @return The {@link TestClass} object for this JUnit runner with the
 *         specified test class.
 */
@Override
protected TestClass createTestClass(final Class<?> testClass) {
  return new TestClass(testClass) {
    @Override
    public List<FrameworkMethod> getAnnotatedMethods(final Class<? extends Annotation> annotationClass) {
      final List<FrameworkMethod> retrofitted = new ArrayList<>();
      for (final FrameworkMethod method : super.getAnnotatedMethods(annotationClass))
        retrofitted.add(retrofitMethod(method));

      return Collections.unmodifiableList(retrofitted);
    }

    @Override
    protected void scanAnnotatedMembers(final Map<Class<? extends Annotation>,List<FrameworkMethod>> methodsForAnnotations, final Map<Class<? extends Annotation>,List<FrameworkField>> fieldsForAnnotations) {
      super.scanAnnotatedMembers(methodsForAnnotations, fieldsForAnnotations);
      for (final Map.Entry<Class<? extends Annotation>,List<FrameworkMethod>> entry : methodsForAnnotations.entrySet()) {
        final ListIterator<FrameworkMethod> iterator = entry.getValue().listIterator();
        while (iterator.hasNext())
          iterator.set(retrofitMethod(iterator.next()));
      }
    }
  };
}
 
源代码2 项目: 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);
        }
    }
}
 
源代码3 项目: n4js   文件: XtextParametrizedRunner.java
/**
 * Implements behavior from: org.junit.runners.Parameterized$TestClassRunnerForParameters
 */
private Object createTestUsingFieldInjection() throws Exception {
	List<FrameworkField> annotatedFieldsByParameter = getAnnotatedFieldsByParameter();
	if (annotatedFieldsByParameter.size() != fParameters.length) {
		throw new Exception("Wrong number of parameters and @Parameter fields."
				+ " @Parameter fields counted: " + annotatedFieldsByParameter.size()
				+ ", available parameters: " + fParameters.length + ".");
	}
	Object testClassInstance = getTestClass().getJavaClass().getConstructor().newInstance();
	for (FrameworkField each : annotatedFieldsByParameter) {
		Field field = each.getField();
		Parameter annotation = field.getAnnotation(Parameter.class);
		int index = annotation.value();
		try {
			field.set(testClassInstance, fParameters[index]);
		} catch (IllegalArgumentException iare) {
			throw new Exception(getTestClass().getName() + ": Trying to set " + field.getName()
					+ " with the value " + fParameters[index] + " that is not the right type ("
					+ fParameters[index].getClass().getSimpleName() + " instead of "
					+ field.getType().getSimpleName() + ").", iare);
		}
	}
	return testClassInstance;
}
 
源代码4 项目: neodymium-library   文件: ParameterStatement.java
private void injectTestParameter() throws Exception
{
    int parameterFieldCount = statementData.getParameterFrameworkFields().size();
    Object[] parameter = statementData.getParameter();

    if (parameterFieldCount != parameter.length)
    {
        throw new Exception("Number of parameters (" + parameter.length + ") and " + //
                            "fields (" + parameterFieldCount + ") " + //
                            "annotated with @Parameter must match!");
    }

    for (FrameworkField parameterFrameworkField : statementData.getParameterFrameworkFields())
    {
        Field field = parameterFrameworkField.getField();
        int parameterIndex = field.getAnnotation(Parameter.class).value();

        LOGGER.debug("Set parameter \"" + parameterFrameworkField.getName() + "\" to \"" + parameter[parameterIndex] + "\"");
        setField(field, parameter[parameterIndex]);
    }
}
 
源代码5 项目: baratine   文件: BaseRunner.java
public List<T> getInjectionTestPoints()
  throws IllegalAccessException
{
  List<T> result = new ArrayList<>();

  List<FrameworkField> fields = getTestClass().getAnnotatedFields();

  final MethodHandles.Lookup lookup = MethodHandles.lookup();

  for (FrameworkField field : fields) {
    Field javaField = field.getField();
    javaField.setAccessible(true);

    MethodHandle setter = lookup.unreflectSetter(javaField);

    T ip = createInjectionPoint(javaField.getType(),
                                javaField.getAnnotations(),
                                setter);

    result.add(ip);
  }

  return result;
}
 
源代码6 项目: baratine   文件: BaseRunner.java
@Override
protected void scanAnnotatedMembers(Map<Class<? extends Annotation>,List<FrameworkMethod>> methodsForAnnotations,
                                    Map<Class<? extends Annotation>,List<FrameworkField>> fieldsForAnnotations)
{
  super.scanAnnotatedMembers(methodsForAnnotations, fieldsForAnnotations);

  for (Map.Entry<Class<? extends Annotation>,List<FrameworkMethod>> entry
    : methodsForAnnotations.entrySet()) {
    if (Test.class.equals(entry.getKey())) {
      List<FrameworkMethod> methods = new ArrayList<>();
      for (FrameworkMethod method : entry.getValue()) {
        Method javaMethod = method.getMethod();
        if (javaMethod.getParameterTypes().length > 0) {
          methods.add(new BaratineFrameworkMethod(javaMethod));
        }
        else {
          methods.add(method);
        }
      }

      entry.setValue(methods);
    }
  }
}
 
源代码7 项目: ion-java   文件: Injected.java
private static PropertyDescriptor findDescriptor(TestClass testClass,
                                          PropertyDescriptor[] descriptors,
                                          FrameworkField field,
                                          String name)
throws Exception
{
    for (PropertyDescriptor d : descriptors)
    {
        if (d.getName().equals(name))
        {
            if (d.getWriteMethod() == null) break;  // To throw error
            return d;
        }
    }

    throw new Exception("@Inject value '" + name
                        + "' doesn't match a writeable property near "
                        + testClass.getName() + '.'
                        + field.getField().getName());
}
 
源代码8 项目: kurento-java   文件: KurentoTestListener.java
public KurentoTestListener(List<FrameworkField> services) {

    this.serviceFields = services;

    for (FrameworkField service : serviceFields) {
      TestService serviceRunner = null;
      try {
        serviceRunner = (TestService) service.getField().get(null);
        if (!serviceRunners.contains(serviceRunner)) {
          serviceRunners.add(serviceRunner);
          if (serviceRunner.getScope() == TESTSUITE) {
            serviceRunner.start();
          }
        }

      } catch (Throwable e) {
        log.warn("Exception instanting service in class {}", serviceRunner, e);
      }
    }

  }
 
源代码9 项目: wildfly-core   文件: WildflyTestRunner.java
private void doInject(TestClass klass, Object instance) {

        try {

            for (FrameworkField frameworkField : klass.getAnnotatedFields(Inject.class)) {
                Field field = frameworkField.getField();
                if ((instance == null && Modifier.isStatic(field.getModifiers()) ||
                        instance != null)) {//we want to do injection even on static fields before test run, so we make sure that client is correct for current state of server
                    field.setAccessible(true);
                    if (field.getType() == ManagementClient.class && controller.isStarted()) {
                        field.set(instance, controller.getClient());
                    } else if (field.getType() == ModelControllerClient.class && controller.isStarted()) {
                        field.set(instance, controller.getClient().getControllerClient());
                    } else if (field.getType() == ServerController.class) {
                        field.set(instance, controller);
                    }
                }
            }

        } catch (Exception e) {
            throw new RuntimeException("Failed to inject", e);
        }
    }
 
源代码10 项目: wildfly-core   文件: WildflyTestRunner.java
@Override
protected List<FrameworkMethod> getChildren() {
    final List<FrameworkMethod> result = new ArrayList<>();
    final TestClass testClass = getTestClass();
    final Collection<Object> parameters = resolveParameters(testClass);
    // If there are no resolved parameters we can just use the default methods
    if (parameters.isEmpty()) {
        result.addAll(super.getChildren());
    } else {
        final FrameworkField field = findParameterField(testClass);
        for (FrameworkMethod method : super.getChildren()) {
            for (Object value : parameters) {
                parameterDescriptions.add(method, field, value);
                // Add the same method for each parameter value
                result.add(method);
            }
        }
    }
    return result;
}
 
源代码11 项目: geowave   文件: GeoWaveITRunner.java
private static List<GeoWaveStoreRunnerConfig> addRunnerConfigsForField(
    final FrameworkField field,
    final List<GeoWaveStoreRunnerConfig> currentConfigs,
    final Set<GeoWaveStoreType> storeTypes) throws GeoWaveITException {
  final GeoWaveTestStore store = field.getField().getAnnotation(GeoWaveTestStore.class);
  final GeoWaveStoreType[] types = store.value();
  if ((types == null) || (types.length == 0)) {
    throw new GeoWaveITException(
        MessageFormat.format("{0} must have at least one GeoWaveStoreType", field.getName()));
  }
  final List<GeoWaveStoreRunnerConfig> newConfigs = new ArrayList<>();
  for (final GeoWaveStoreRunnerConfig config : currentConfigs) {
    for (final GeoWaveStoreType type : types) {
      newConfigs.add(new GeoWaveStoreRunnerConfig(config, field.getName(), type));

      storeTypes.add(type);
    }
  }
  return newConfigs;
}
 
源代码12 项目: buck   文件: BuckBlockJUnit4ClassRunner.java
/**
 * @return {@code true} if the test class has any fields annotated with {@code Rule} whose type is
 *     {@link Timeout}.
 */
static boolean hasTimeoutRule(TestClass testClass) {
  // Many protected convenience methods in BlockJUnit4ClassRunner that are available in JUnit 4.11
  // such as getTestRules(Object) were not public until
  // https://github.com/junit-team/junit/commit/8782efa08abf5d47afdc16740678661443706740,
  // which appears to be JUnit 4.9. Because we allow users to use JUnit 4.7, we need to include a
  // custom implementation that is backwards compatible to JUnit 4.7.
  List<FrameworkField> fields = testClass.getAnnotatedFields(Rule.class);
  for (FrameworkField field : fields) {
    if (field.getField().getType().equals(Timeout.class)) {
      return true;
    }
  }

  return false;
}
 
/**
 * {@inheritDoc}
 */
@Override
protected void validateFields(final List<Throwable> errors) {
    super.validateFields(errors);
    if (fieldsAreAnnotated()) {
        final List<FrameworkField> annotatedFieldsByParameter = getAnnotatedFieldsByParameter();
        final int[] usedIndices = new int[annotatedFieldsByParameter.size()];
        for (final FrameworkField each : annotatedFieldsByParameter) {
            final int index = each.getField().getAnnotation(Parameter.class)
                    .value();
            if (index < 0 || index > annotatedFieldsByParameter.size() - 1) {
                errors.add(new Exception("Invalid @Parameter value: "
                        + index + ". @Parameter fields counted: "
                        + annotatedFieldsByParameter.size()
                        + ". Please use an index between 0 and "
                        + (annotatedFieldsByParameter.size() - 1) + "."));
            }
            else {
                usedIndices[index]++;
            }
        }
        for (int index = 0; index < usedIndices.length; index++) {
            final int numberOfUse = usedIndices[index];
            if (numberOfUse == 0) {
                errors.add(new Exception("@Parameter(" + index
                        + ") is never used."));
            }
            else if (numberOfUse > 1) {
                errors.add(new Exception("@Parameter(" + index
                        + ") is used more than once (" + numberOfUse + ")."));
            }
        }
    }
}
 
源代码14 项目: htmlunit   文件: FrameworkMethodWithParameters.java
/**
 * {@inheritDoc}
 */
@Override
public Object invokeExplosively(final Object target, final Object... params)
    throws Throwable {
    if (!parameters_.isEmpty()) {
        final List<FrameworkField> annotatedFieldsByParameter = testClass_.getAnnotatedFields(Parameter.class);
        if (annotatedFieldsByParameter.size() != parameters_.size()) {
            throw new Exception(
                    "Wrong number of parameters and @Parameter fields."
                            + " @Parameter fields counted: "
                            + annotatedFieldsByParameter.size()
                            + ", available parameters: " + parameters_.size()
                            + ".");
        }
        for (final FrameworkField each : annotatedFieldsByParameter) {
            final Field field = each.getField();
            final Parameter annotation = field.getAnnotation(Parameter.class);
            final int index = annotation.value();
            try {
                field.set(target, parameters_.get(index));
            }
            catch (final IllegalArgumentException iare) {
                throw new Exception(testClass_.getName()
                        + ": Trying to set " + field.getName()
                        + " with the value " + parameters_.get(index)
                        + " that is not the right type ("
                        + parameters_.get(index).getClass().getSimpleName()
                        + " instead of " + field.getType().getSimpleName()
                        + ").", iare);
            }
        }
    }
    return super.invokeExplosively(target, params);
}
 
源代码15 项目: n4js   文件: XtextParametrizedRunner.java
/**
 * Implements behavior from: org.junit.runners.Parameterized$TestClassRunnerForParameters
 */
@Override
protected void validateFields(List<Throwable> errors) {
	super.validateFields(errors);
	if (fieldsAreAnnotated()) {
		List<FrameworkField> annotatedFieldsByParameter = getAnnotatedFieldsByParameter();
		int[] usedIndices = new int[annotatedFieldsByParameter.size()];
		for (FrameworkField each : annotatedFieldsByParameter) {
			int index = each.getField().getAnnotation(Parameter.class).value();
			if (index < 0 || index > annotatedFieldsByParameter.size() - 1) {
				errors.add(new Exception("Invalid @Parameter value: " + index + ". @Parameter fields counted: "
						+ annotatedFieldsByParameter.size() + ". Please use an index between 0 and "
						+ (annotatedFieldsByParameter.size() - 1) + "."));
			} else {
				usedIndices[index]++;
			}
		}
		for (int index = 0; index < usedIndices.length; index++) {
			int numberOfUse = usedIndices[index];
			if (numberOfUse == 0) {
				errors.add(new Exception("@Parameter(" + index + ") is never used."));
			} else if (numberOfUse > 1) {
				errors.add(new Exception("@Parameter(" + index + ") is used more than once (" + numberOfUse
						+ ")."));
			}
		}
	}
}
 
源代码16 项目: ArchUnit   文件: ArchUnitRunner.java
private Collection<ArchTestExecution> findArchRuleFields() {
    List<ArchTestExecution> result = new ArrayList<>();
    for (FrameworkField ruleField : getTestClass().getAnnotatedFields(ArchTest.class)) {
        result.addAll(findArchRulesIn(ruleField));
    }
    return result;
}
 
源代码17 项目: ArchUnit   文件: ArchUnitRunner.java
private Set<ArchTestExecution> findArchRulesIn(FrameworkField ruleField) {
    boolean ignore = elementShouldBeIgnored(ruleField.getField());
    if (ruleField.getType() == ArchRules.class) {
        return asTestExecutions(getArchRules(ruleField.getField()), ignore);
    }
    return Collections.<ArchTestExecution>singleton(new ArchRuleExecution(getTestClass().getJavaClass(), ruleField.getField(), ignore));
}
 
private Object createTestUsingFieldInjection() throws Exception {
    List<FrameworkField> annotatedFieldsByParameter = getAnnotatedFieldsByParameter();
    if (annotatedFieldsByParameter.size() != parameters.length) {
        throw new Exception(
                "Wrong number of parameters and @Parameter fields."
                        + " @Parameter fields counted: "
                        + annotatedFieldsByParameter.size()
                        + ", available parameters: " + parameters.length
                        + ".");
    }
    Object testClassInstance = getTestClass().getJavaClass().newInstance();
    for (FrameworkField each : annotatedFieldsByParameter) {
        Field field = each.getField();
        Parameter annotation = field.getAnnotation(Parameter.class);
        int index = annotation.value();
        try {
            field.set(testClassInstance, parameters[index]);
        } catch (IllegalArgumentException iare) {
            throw new Exception(getTestClass().getName()
                    + ": Trying to set " + field.getName()
                    + " with the value " + parameters[index]
                    + " that is not the right type ("
                    + parameters[index].getClass().getSimpleName()
                    + " instead of " + field.getType().getSimpleName()
                    + ").", iare);
        }
    }
    return testClassInstance;
}
 
@Override
protected void validateFields(List<Throwable> errors) {
    super.validateFields(errors);
    if (getInjectionType() == InjectionType.FIELD) {
        List<FrameworkField> annotatedFieldsByParameter = getAnnotatedFieldsByParameter();
        int[] usedIndices = new int[annotatedFieldsByParameter.size()];
        for (FrameworkField each : annotatedFieldsByParameter) {
            int index = each.getField().getAnnotation(Parameter.class)
                    .value();
            if (index < 0 || index > annotatedFieldsByParameter.size() - 1) {
                errors.add(new Exception("Invalid @Parameter value: "
                        + index + ". @Parameter fields counted: "
                        + annotatedFieldsByParameter.size()
                        + ". Please use an index between 0 and "
                        + (annotatedFieldsByParameter.size() - 1) + "."));
            } else {
                usedIndices[index]++;
            }
        }
        for (int index = 0; index < usedIndices.length; index++) {
            int numberOfUse = usedIndices[index];
            if (numberOfUse == 0) {
                errors.add(new Exception("@Parameter(" + index
                        + ") is never used."));
            } else if (numberOfUse > 1) {
                errors.add(new Exception("@Parameter(" + index
                        + ") is used more than once (" + numberOfUse + ")."));
            }
        }
    }
}
 
源代码20 项目: jpa-unit   文件: JpaUnitRunner.java
public JpaUnitRunner(final Class<?> clazz) throws InitializationError {
    super(clazz);
    executor = new DecoratorExecutor();

    final List<FrameworkField> ruleFields = getTestClass().getAnnotatedFields(Rule.class);
    if (ruleFields.stream().anyMatch(f -> f.getType().equals(JpaUnitRule.class))) {
        throw new InitializationError("JpaUnitRunner and JpaUnitRule exclude each other");
    }
}
 
源代码21 项目: FreeBuilder   文件: SharedBehaviorTesting.java
public SharedBehaviorTesting(
    Function<RunNotifier, Statement> superChildrenInvoker,
    BiConsumer<FrameworkMethod, RunNotifier> superChildRunner,
    TestSupplier superCreateTest,
    Supplier<Description> superDescription,
    Supplier<TestClass> testClass,
    BiFunction<Class<?>, String, Description> descriptionFactory,
    FeatureSet features)
        throws InitializationError {
  this.superChildrenInvoker = superChildrenInvoker;
  this.superChildRunner = superChildRunner;
  this.superCreateTest = superCreateTest;
  this.superDescription = superDescription;
  this.features = features;
  List<FrameworkField> testerFields = testClass.get().getAnnotatedFields(Shared.class);
  if (testerFields.isEmpty()) {
    throw new InitializationError("No public @Shared field found");
  } else if (testerFields.size() > 1) {
    throw new InitializationError("Multiple public @Shared fields found");
  }
  FrameworkField frameworkField = getOnlyElement(testerFields);
  if (!frameworkField.isPublic()) {
    throw new InitializationError("@Shared field " + frameworkField + " must be public");
  }
  if (!frameworkField.getType().isAssignableFrom(BehaviorTester.class)) {
    throw new InitializationError(String.format(
        "@Shared field %s must be of type %s",
        frameworkField,
        BehaviorTester.class.getSimpleName()));
  }
  testerField = frameworkField.getField();
  introspection = descriptionFactory.apply(testClass.get().getJavaClass(), "Introspect");
}
 
源代码22 项目: ion-java   文件: Injected.java
private static Dimension[] findDimensions(TestClass testClass)
throws Throwable
{
    List<FrameworkField> fields =
        testClass.getAnnotatedFields(Inject.class);
    if (fields.isEmpty())
    {
        throw new Exception("No fields of " + testClass.getName()
                            + " have the @Inject annotation");
    }

    BeanInfo beanInfo = Introspector.getBeanInfo(testClass.getJavaClass());
    PropertyDescriptor[] descriptors = beanInfo.getPropertyDescriptors();

    Dimension[] dimensions = new Dimension[fields.size()];

    int i = 0;
    for (FrameworkField field : fields)
    {
        int modifiers = field.getField().getModifiers();
        if (! Modifier.isPublic(modifiers) || ! Modifier.isStatic(modifiers))
        {
            throw new Exception("@Inject " + testClass.getName() + '.'
                                + field.getField().getName()
                                + " must be public static");
        }

        Dimension dim = new Dimension();
        dim.property = field.getField().getAnnotation(Inject.class).value();
        dim.descriptor = findDescriptor(testClass, descriptors, field, dim.property);
        dim.values = (Object[]) field.get(null);
        dimensions[i++] = dim;
    }

    return dimensions;
}
 
源代码23 项目: vertx-unit   文件: VertxUnitRunnerWithParameters.java
private Object createTestUsingFieldInjection() throws Exception {
  List<FrameworkField> annotatedFieldsByParameter = getAnnotatedFieldsByParameter();
  if (annotatedFieldsByParameter.size() != parameters.length) {
    throw new Exception(
        "Wrong number of parameters and @Parameter fields."
            + " @Parameter fields counted: "
            + annotatedFieldsByParameter.size()
            + ", available parameters: " + parameters.length
            + ".");
  }
  Object testClassInstance = getTestClass().getJavaClass().newInstance();
  for (FrameworkField each : annotatedFieldsByParameter) {
    Field field = each.getField();
    Parameterized.Parameter annotation = field.getAnnotation(Parameterized.Parameter.class);
    int index = annotation.value();
    try {
      field.set(testClassInstance, parameters[index]);
    } catch (IllegalArgumentException iare) {
      throw new Exception(getTestClass().getName()
          + ": Trying to set " + field.getName()
          + " with the value " + parameters[index]
          + " that is not the right type ("
          + parameters[index].getClass().getSimpleName()
          + " instead of " + field.getType().getSimpleName()
          + ").", iare);
    }
  }
  return testClassInstance;
}
 
源代码24 项目: vertx-unit   文件: VertxUnitRunnerWithParameters.java
@Override
protected void validateFields(List<Throwable> errors) {
  super.validateFields(errors);
  if (fieldsAreAnnotated()) {
    List<FrameworkField> annotatedFieldsByParameter = getAnnotatedFieldsByParameter();
    int[] usedIndices = new int[annotatedFieldsByParameter.size()];
    for (FrameworkField each : annotatedFieldsByParameter) {
      int index = each.getField().getAnnotation(Parameterized.Parameter.class)
          .value();
      if (index < 0 || index > annotatedFieldsByParameter.size() - 1) {
        errors.add(new Exception("Invalid @Parameter value: "
            + index + ". @Parameter fields counted: "
            + annotatedFieldsByParameter.size()
            + ". Please use an index between 0 and "
            + (annotatedFieldsByParameter.size() - 1) + "."));
      } else {
        usedIndices[index]++;
      }
    }
    for (int index = 0; index < usedIndices.length; index++) {
      int numberOfUse = usedIndices[index];
      if (numberOfUse == 0) {
        errors.add(new Exception("@Parameter(" + index
            + ") is never used."));
      } else if (numberOfUse > 1) {
        errors.add(new Exception("@Parameter(" + index
            + ") is used more than once (" + numberOfUse + ")."));
      }
    }
  }
}
 
/**
 * {@link ParameterizedClassRule}が設定されているフィールドまたはメソッドをチェックします。
 * 
 * @param errors エラーのリスト。チェックした結果エラーがあった場合、このリストに追加される
 */
protected void validateParameterizedClassRules(List<Throwable> errors) {
	for (FrameworkMethod method : getTestClass().getAnnotatedMethods(ParameterizedClassRule.class)) {
		if (!method.isStatic()) {
			errors.add(new Exception("Method " + method.getName() + "() should be static"));
		}
		if (!method.isPublic()) {
			errors.add(new Exception("Method " + method.getName() + "() should be public"));
		}
		if (method.getMethod().getParameterTypes().length != 0) {
			errors.add(new Exception("Method " + method.getName() + "() should have no parameters"));
		}
		if (!ParameterizedTestRule.class.isAssignableFrom(method.getType())) {
			errors.add(new Exception("Method " + method.getName()
					+ "() must return an implementation of ParameterizedTestRule"));
		}
	}

	for (FrameworkField field : getTestClass().getAnnotatedFields(ParameterizedClassRule.class)) {
		if (!field.isStatic()) {
			errors.add(new Exception("Field " + field.getName() + " should be static"));
		}
		if (!field.isPublic()) {
			errors.add(new Exception("Field " + field.getName() + " should be public"));
		}
		if (!ParameterizedTestRule.class.isAssignableFrom(field.getType())) {
			errors.add(new Exception("Field " + field.getName() + " must implement ParameterizedTestRule"));
		}
	}
}
 
源代码26 项目: kurento-java   文件: KurentoTestRunner.java
@Override
public void run(RunNotifier notifier) {

  if (listener != null) {
    notifier.removeListener(listener);
  }

  List<FrameworkField> services = this.getTestClass().getAnnotatedFields(Service.class);

  ArrayList<FrameworkField> sortedServices = new ArrayList<>(services);
  Collections.sort(sortedServices, new Comparator<FrameworkField>() {
    @Override
    public int compare(FrameworkField o1, FrameworkField o2) {
      return Integer.compare(o1.getAnnotation(Service.class).value(),
          o2.getAnnotation(Service.class).value());
    }
  });

  listener = new KurentoTestListener(sortedServices);
  notifier.addListener(listener);
  listener.testRunStarted(getDescription());

  if (!shutdownHook) {
    shutdownHook = true;
    Runtime.getRuntime().addShutdownHook(new Thread("app-shutdown-hook") {
      @Override
      public void run() {
        listener.testSuiteFinished();
      }
    });
  }

  // TODO Remove this if we change service management
  notifier = new KurentoRunNotifier(notifier);

  super.run(notifier);
}
 
源代码27 项目: wildfly-core   文件: WildflyTestRunner.java
private FrameworkField findParameterField(final TestClass testClass) {
    final List<FrameworkField> fields = testClass.getAnnotatedFields(Parameter.class);
    if (fields.size() > 1) {
        throw new RuntimeException(String.format("More than one field was annotated with @%s: %s",
                Parameter.class.getSimpleName(), fields));
    } else if (fields.isEmpty()) {
        throw new RuntimeException(String.format("If the @%s annotation is present on a method a field must be annotated with @%s",
                Parameters.class.getSimpleName(), Parameter.class.getSimpleName()));
    }
    return fields.get(0);
}
 
源代码28 项目: geowave   文件: GeoWaveITRunner.java
@Override
protected void validateFields(final List<Throwable> errors) {
  super.validateFields(errors);
  if (typeIsAnnotated()) {
    if (fieldsAreAnnotated()) {
      errors.add(
          new GeoWaveITException(
              "Only type or fields can be annotated with @GeoWaveTestStore, not both"));
    }
    try {
      getDataStoreOptionFieldsForTypeAnnotation();
    } catch (final Exception e) {
      errors.add(e);
    }
  } else if (fieldsAreAnnotated()) {
    final List<FrameworkField> annotatedFields = getStoreAnnotatedFields();
    for (final FrameworkField field : annotatedFields) {
      if (!field.getType().isAssignableFrom(DataStorePluginOptions.class)) {
        errors.add(
            new GeoWaveITException(
                "'"
                    + field.getName()
                    + "' must be of type '"
                    + DataStorePluginOptions.class.getName()
                    + "'"));
      }
    }
  }
}
 
private List<FrameworkField> getAnnotatedFieldsByParameter() {
    return getTestClass().getAnnotatedFields(Parameter.class);
}
 
源代码30 项目: n4js   文件: XtextParametrizedRunner.java
/**
 * Implements behavior from: org.junit.runners.Parameterized
 */
List<FrameworkField> getAnnotatedFieldsByParameter() {
	return getTestClass().getAnnotatedFields(Parameter.class);
}
 
 类所在包
 类方法
 同包方法