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


Java TestClass.getAnnotatedFields方法代码示例

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


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

示例1: shouldInitializeInjectDelayedField

import org.junit.runners.model.TestClass; //导入方法依赖的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: shouldThrowForAlreadyInitializedField

import org.junit.runners.model.TestClass; //导入方法依赖的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

示例3: doInject

import org.junit.runners.model.TestClass; //导入方法依赖的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

示例4: hasTimeoutRule

import org.junit.runners.model.TestClass; //导入方法依赖的package包/类
/**
 * @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;
}
 
开发者ID:saleehk,项目名称:buck-cutom,代码行数:20,代码来源:BuckBlockJUnit4ClassRunner.java

示例5: getAuthorizationRule

import org.junit.runners.model.TestClass; //导入方法依赖的package包/类
private AuthorizationRule getAuthorizationRule(TestClass testClass, Object target) throws IllegalAccessException {
    List<FrameworkField> ruleFields = testClass.getAnnotatedFields(Rule.class);

    for (FrameworkField ruleField : ruleFields) {
        if (ruleField.getType().isAssignableFrom(AuthorizationRule.class)) {
            return (AuthorizationRule) ruleField.get(target);
        }
    }

    throw new IllegalStateException("Test class must have AuthorizationRule set");
}
 
开发者ID:Vincit,项目名称:multi-user-test-runner,代码行数:12,代码来源:RunnerDelegate.java

示例6: getAnnotatedFieldsByParameter

import org.junit.runners.model.TestClass; //导入方法依赖的package包/类
/**
 * @see BlockJUnit4ClassRunnerWithParameters#getAnnotatedFieldsByParameter()
 */
public static List<FrameworkField> getAnnotatedFieldsByParameter(TestClass testClass) {
    return testClass.getAnnotatedFields(Parameterized.Parameter.class);
}
 
开发者ID:PeterWippermann,项目名称:parameterized-suite,代码行数:7,代码来源:BlockJUnit4ClassRunnerWithParametersUtil.java

示例7: getAnnotatablesForTestClass

import org.junit.runners.model.TestClass; //导入方法依赖的package包/类
@Override
Iterable<FrameworkField> getAnnotatablesForTestClass(TestClass testClass) {
    return testClass.getAnnotatedFields();
}
 
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:5,代码来源:AnnotationsValidator.java


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