当前位置: 首页>>代码示例>>Java>>正文


Java FrameworkField.getField方法代码示例

本文整理汇总了Java中org.junit.runners.model.FrameworkField.getField方法的典型用法代码示例。如果您正苦于以下问题:Java FrameworkField.getField方法的具体用法?Java FrameworkField.getField怎么用?Java FrameworkField.getField使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.junit.runners.model.FrameworkField的用法示例。


在下文中一共展示了FrameworkField.getField方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createTestUsingFieldInjection

import org.junit.runners.model.FrameworkField; //导入方法依赖的package包/类
/**
 * 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().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;
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:27,代码来源:XtextParametrizedRunner.java

示例2: evaluate

import org.junit.runners.model.FrameworkField; //导入方法依赖的package包/类
@Override
public void evaluate() throws Throwable {
    Injector injector = getInjector();
    for (FrameworkField frameworkField : fields) {
        Field field = frameworkField.getField();
        if (ReflectionUtils.getFieldValue(field, target) != null) {
            throw new IllegalStateException("Field with @InjectDelayed must be null on startup. "
                + "Field '" + field.getName() + "' is not null");
        }
        Object object = injector.getSingleton(field.getType());
        ReflectionUtils.setField(field, target, object);
    }

    this.testClass = null;
    this.target = null;
    this.fields = null;
    next.evaluate();
}
 
开发者ID:ljacqu,项目名称:DependencyInjector,代码行数:19,代码来源:RunDelayedInjects.java

示例3: getInjectionTestPoints

import org.junit.runners.model.FrameworkField; //导入方法依赖的package包/类
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;
}
 
开发者ID:baratine,项目名称:baratine,代码行数:25,代码来源:BaseRunner.java

示例4: createTestUsingFieldInjection

import org.junit.runners.model.FrameworkField; //导入方法依赖的package包/类
/**
 * @see BlockJUnit4ClassRunnerWithParameters#createTestUsingFieldInjection()
 */
private static Object createTestUsingFieldInjection(TestClass testClass, Object[] parameters) throws Exception {
    List<FrameworkField> annotatedFieldsByParameter = getAnnotatedFieldsByParameter(testClass);
    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 = testClass.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(
                    testClass.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;
}
 
开发者ID:PeterWippermann,项目名称:parameterized-suite,代码行数:26,代码来源:BlockJUnit4ClassRunnerWithParametersUtil.java

示例5: doInject

import org.junit.runners.model.FrameworkField; //导入方法依赖的package包/类
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);
        }
    }
 
开发者ID:wildfly,项目名称:wildfly-core,代码行数:24,代码来源:WildflyTestRunner.java

示例6: createTestUsingFieldInjection

import org.junit.runners.model.FrameworkField; //导入方法依赖的package包/类
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().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;
}
 
开发者ID:lcm-proj,项目名称:lcm,代码行数:23,代码来源:Parameterized.java

示例7: configure

import org.junit.runners.model.FrameworkField; //导入方法依赖的package包/类
@Override
protected void configure()
{
	final Errors errors = new Errors(testClass);

	for (FrameworkField field : fields)
	{
		try
		{
			final Field f = field.getField();
			final Key key = Annotations.getKey(TypeLiteral.get(f.getGenericType()), f, field.getAnnotations(), errors);

			bindMock(key, f.getType(), "Automock[" + field.getName() + "] " + key);
		}
		catch (ErrorsException e)
		{
			// Add it to the error list and hold them all until the end
			errors.merge(e.getErrors());
		}
	}

	errors.throwConfigurationExceptionIfErrorsExist();
}
 
开发者ID:petergeneric,项目名称:stdlib,代码行数:24,代码来源:AutomockAnnotatedMockModule.java

示例8: createTestUsingFieldInjection

import org.junit.runners.model.FrameworkField; //导入方法依赖的package包/类
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;
}
 
开发者ID:hortonworks,项目名称:registry,代码行数:30,代码来源:CustomParameterizedBlockJUnit4Runner.java

示例9: SharedBehaviorTesting

import org.junit.runners.model.FrameworkField; //导入方法依赖的package包/类
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");
}
 
开发者ID:google,项目名称:FreeBuilder,代码行数:34,代码来源:SharedBehaviorTesting.java

示例10: createTestUsingFieldInjection

import org.junit.runners.model.FrameworkField; //导入方法依赖的package包/类
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;
}
 
开发者ID:vert-x3,项目名称:vertx-unit,代码行数:30,代码来源:VertxUnitRunnerWithParameters.java

示例11: createTestUsingFieldInjection

import org.junit.runners.model.FrameworkField; //导入方法依赖的package包/类
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().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;
}
 
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:30,代码来源:BlockJUnit4ClassRunnerWithParameters.java

示例12: createTestUsingFieldInjection

import org.junit.runners.model.FrameworkField; //导入方法依赖的package包/类
private Object createTestUsingFieldInjection() throws Exception {
	List<FrameworkField> annotatedFieldsByParameter = getAnnotatedFieldsByParameter();
	if (annotatedFieldsByParameter.size() != fParameters.length) {
		throw new Exception(String.format(
				"Wrong number of parameters and @Parameter fields. @Parameter fields counted: %s, available parameters: %s.",
				annotatedFieldsByParameter.size(), fParameters.length));
	}
	Object testClassInstance = getTestClass().getJavaClass().newInstance();
	if (getTestClass().getJavaClass() == JExUnitBase.class) {
		((JExUnitBase) testClassInstance).setTestType(testType);
	}
	for (FrameworkField each : annotatedFieldsByParameter) {
		Field field = each.getField();
		Parameter annotation = field.getAnnotation(Parameter.class);
		int index = annotation.value();
		try {
			if (field.isAccessible()) {
				field.set(testClassInstance, fParameters[index]);
			} else {
				field.setAccessible(true);
				field.set(testClassInstance, fParameters[index]);
				field.setAccessible(false);
			}
		} catch (IllegalArgumentException iare) {
			throw new Exception(
					String.format(
							"%s: Trying to set %s with the value %s that is not the right type (%s instead of %s).",
							getTestClass().getName(), field.getName(), fParameters[index],
							fParameters[index].getClass().getSimpleName(), field.getType().getSimpleName()),
					iare);
		}
	}
	return testClassInstance;
}
 
开发者ID:fhm84,项目名称:jexunit,代码行数:35,代码来源:Parameterized.java

示例13: before

import org.junit.runners.model.FrameworkField; //导入方法依赖的package包/类
@Override
protected void before() throws Throwable {
  Assert.assertNotNull(this.testInstance);
  final TestClass testClass = this.getTestClass();
  Assert.assertNotNull(testClass);
  final Collection<FrameworkField> annotatedFields = testClass.getAnnotatedFields(H2Connection.class);
  if (annotatedFields != null && !annotatedFields.isEmpty()) {
    for (final FrameworkField ff : annotatedFields) {
      if (ff != null) {
        final Field f = ff.getField();
        if (f != null && Connection.class.isAssignableFrom(f.getType())) {
          final H2Connection h2Connection = f.getAnnotation(H2Connection.class);
          Assert.assertNotNull(h2Connection);
          final Connection connection = new H2ConnectionDescriptor(h2Connection, this.description).getConnection();
          if (this.connections == null) {
            this.connections = new ArrayList<Connection>(annotatedFields.size());
          }
          this.connections.add(connection);
          final boolean accessible = f.isAccessible();
          f.setAccessible(true);
          try {
            f.set(this.testInstance, connection);
          } finally {
            f.setAccessible(accessible);
          }
        }
      }
    }
  }
}
 
开发者ID:ljnelson,项目名称:h2unit,代码行数:31,代码来源:H2Rule.java

示例14: FieldAssignment

import org.junit.runners.model.FrameworkField; //导入方法依赖的package包/类
FieldAssignment(FrameworkField field) {
    super(field.getField());
    this.field = field;
}
 
开发者ID:SeriyBg,项目名称:junit-easy-tools,代码行数:5,代码来源:FieldAssignment.java


注:本文中的org.junit.runners.model.FrameworkField.getField方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。