本文整理匯總了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();
}
示例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"));
}
}
示例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);
}
}
示例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;
}
示例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");
}
示例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();
}