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


Java FrameworkField类代码示例

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


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

示例1: shouldInitializeInjectDelayedField

import org.junit.runners.model.FrameworkField; //导入依赖的package包/类
@Test
public void shouldInitializeInjectDelayedField() throws Throwable {
    // given - test class with initialized @Mock fields
    DelayedInjectionRunnerIntegrationTest runnerTest = new DelayedInjectionRunnerIntegrationTest();
    MockitoAnnotations.initMocks(runnerTest);

    TestClass testClass = new TestClass(runnerTest.getClass());
    Statement nextStatement = mock(Statement.class);
    List<FrameworkField> injectDelayedFields = testClass.getAnnotatedFields(InjectDelayed.class);
    assertThat(injectDelayedFields, hasSize(1)); // assumption
    RunDelayedInjects runDelayedInjects =
        new RunDelayedInjects(nextStatement, testClass, runnerTest, injectDelayedFields);

    // when
    runDelayedInjects.evaluate();

    // then
    assertThat(ReflectionUtils.getFieldValue(injectDelayedFields.get(0).getField(), runnerTest), not(nullValue()));
    verify(nextStatement).evaluate();
}
 
开发者ID:ljacqu,项目名称:DependencyInjector,代码行数:21,代码来源:RunDelayedInjectsTest.java

示例2: allPossible

import org.junit.runners.model.FrameworkField; //导入依赖的package包/类
Stream<Assignment> allPossible() throws Throwable {

        final List<FrameworkMethod> annotatedMethods = testClass.getAnnotatedMethods(DataProducer.class);


        Stream<Assignment> methodAssignments = Stream.empty();
        for (FrameworkMethod annotatedMethod : annotatedMethods) {
            final Type methodReturnType = getMethodGenericReturnType(annotatedMethod.getMethod());
            methodAssignments = Stream.concat(methodAssignments, methodToStreamOfResults(annotatedMethod)
                    .map(value -> new MethodResultAssignment(value, methodReturnType, annotatedMethod)));
        }

        final List<FrameworkField> annotatedFields = testClass.getAnnotatedFields(DataProducer.class);
        final Stream<Assignment> fieldsAssignments = annotatedFields.stream()
                .map(FieldAssignment::new);
        return Stream.concat(fieldsAssignments, methodAssignments);
    }
 
开发者ID:SeriyBg,项目名称:junit-easy-tools,代码行数:18,代码来源:PotentialAssignments.java

示例3: 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

示例4: injectAnnotatedFields

import org.junit.runners.model.FrameworkField; //导入依赖的package包/类
private Object injectAnnotatedFields(final Object testInstance) throws Exception {
    final List<FrameworkField> fields = getFieldsAnnotatedByRef();
    final Object[] fieldValues = tableRow.convertValues(fields, defaultValueConverter);
    for (int i = 0; i < fields.size(); i++) {
        final Field field = fields.get(i).getField();
        try {
            field.setAccessible(true);
            field.set(testInstance, fieldValues[i]);
        } catch (final Exception e) {
            throw new Exception(getTestClass().getName()
                    + ": Trying to set " + field.getName()
                    + " with the value " + fieldValues[i], e);
        }
    }
    return testInstance;
}
 
开发者ID:tools4j,项目名称:spockito,代码行数:17,代码来源:SingleRowMultiTestRunner.java

示例5: 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

示例6: shouldThrowForAlreadyInitializedField

import org.junit.runners.model.FrameworkField; //导入依赖的package包/类
@Test
public void shouldThrowForAlreadyInitializedField() throws Throwable {
    // given - test class with initialized @Mock fields
    DelayedInjectionRunnerIntegrationTest runnerTest = new DelayedInjectionRunnerIntegrationTest();
    MockitoAnnotations.initMocks(runnerTest);

    TestClass testClass = new TestClass(runnerTest.getClass());
    Statement nextStatement = mock(Statement.class);
    List<FrameworkField> injectDelayedFields = testClass.getAnnotatedFields(InjectDelayed.class);
    assertThat(injectDelayedFields, hasSize(1)); // assumption
    ReflectionUtils.setField(injectDelayedFields.get(0).getField(), runnerTest, mock(SampleInjectClass.class));
    RunDelayedInjects runDelayedInjects =
            new RunDelayedInjects(nextStatement, testClass, runnerTest, injectDelayedFields);

    // when
    try {
        runDelayedInjects.evaluate();
        fail("Expected exception to be thrown");
    } catch (Exception e) {
        assertThat(e.getMessage(), containsString("Field with @InjectDelayed must be null"));
    }
}
 
开发者ID:ljacqu,项目名称:DependencyInjector,代码行数:23,代码来源:RunDelayedInjectsTest.java

示例7: 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

示例8: scanAnnotatedMembers

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

示例9: 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

示例10: FuzzyRunner

import org.junit.runners.model.FrameworkField; //导入依赖的package包/类
/**
 * Default constructor, called by JUnit.
 * 
 * @param clazz
 *            The root class of the suite.
 * @throws InitializationError
 *             If there
 */
public FuzzyRunner(Class<?> clazz) throws InitializationError {
	super(clazz, Collections.<Runner> emptyList());
	dataProvider = getDataProvider();
	dataProvider.setTestClass(getTestClass());
	dataProvider.init();
	FrameworkField dataField = getDataField();
	FrameworkField utilField = getUtilField();
	FrameworkField optionsField = getOptionsField();
	org.eclipse.emf.emfstore.fuzzy.Util util = dataProvider.getUtil();
	for (int i = 0; i < dataProvider.size(); i++) {
		FuzzyTestClassRunner runner = new FuzzyTestClassRunner(clazz,
			dataProvider, dataField, utilField, optionsField, util,
			i + 1);
		if (runner.getChildren().size() > 0) {
			runners.add(runner);
		}
	}
}
 
开发者ID:edgarmueller,项目名称:emfstore-rest,代码行数:27,代码来源:FuzzyRunner.java

示例11: getSingleStaticFrameworkField

import org.junit.runners.model.FrameworkField; //导入依赖的package包/类
private FrameworkField getSingleStaticFrameworkField(
	Class<? extends Annotation> annotation) {
	List<FrameworkField> fields = getTestClass().getAnnotatedFields(
		annotation);

	// Check if there are more than one Data field in the class
	if (fields.size() > 1) {
		throw new RuntimeException("Only one field annotated with "
			+ annotation.getSimpleName() + " permitted: "
			+ getTestClass().getName() + " contains " + fields.size());
	}

	// get the field and check modifiers
	for (FrameworkField field : fields) {
		int modifiers = field.getField().getModifiers();
		if (!Modifier.isStatic(modifiers)) {
			return field;
		}
	}

	return null;
}
 
开发者ID:edgarmueller,项目名称:emfstore-rest,代码行数:23,代码来源:FuzzyRunner.java

示例12: KurentoTestListener

import org.junit.runners.model.FrameworkField; //导入依赖的package包/类
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);
      }
    }

  }
 
开发者ID:Kurento,项目名称:kurento-java,代码行数:22,代码来源:KurentoTestListener.java

示例13: 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

示例14: 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

示例15: createTest

import org.junit.runners.model.FrameworkField; //导入依赖的package包/类
@Override
protected Object createTest() throws Exception {
    if (fieldAnnotated()) {
        Object testInstance = getTestClass().getOnlyConstructor().newInstance();
        List<FrameworkField> configFields = getFieldsAnnotatedByKiWiConfig();
        for (FrameworkField field : configFields) {
            try {
                field.getField().set(testInstance, config);
            } catch (IllegalArgumentException iae) {
                throw new Exception(getTestClass().getName() + ": Trying to set " + field.getName() + " that has a wrong type.");
            }
        }
        return testInstance;
    }
    return getTestClass().getOnlyConstructor().newInstance(config);
}
 
开发者ID:apache,项目名称:marmotta,代码行数:17,代码来源:KiWiDatabaseRunner.java


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