本文整理汇总了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();
}