當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。