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


Java ClassRule类代码示例

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


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

示例1: validateSpringClassRuleConfiguration

import org.junit.ClassRule; //导入依赖的package包/类
/**
 * Throw an {@link IllegalStateException} if the supplied {@code testClass}
 * does not declare a {@code public static final SpringClassRule} field
 * that is annotated with {@code @ClassRule}.
 */
private static SpringClassRule validateSpringClassRuleConfiguration(Class<?> testClass) {
	Field ruleField = null;

	for (Field field : testClass.getFields()) {
		if (ReflectionUtils.isPublicStaticFinal(field) && SpringClassRule.class.isAssignableFrom(field.getType())) {
			ruleField = field;
			break;
		}
	}

	if (ruleField == null) {
		throw new IllegalStateException(String.format(
				"Failed to find 'public static final SpringClassRule' field in test class [%s]. " +
				"Consult the javadoc for SpringClassRule for details.", testClass.getName()));
	}

	if (!ruleField.isAnnotationPresent(ClassRule.class)) {
		throw new IllegalStateException(String.format(
				"SpringClassRule field [%s] must be annotated with JUnit's @ClassRule annotation. " +
				"Consult the javadoc for SpringClassRule for details.", ruleField));
	}

	return (SpringClassRule) ReflectionUtils.getField(ruleField, null);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:30,代码来源:SpringMethodRule.java

示例2: classRules

import org.junit.ClassRule; //导入依赖的package包/类
/**
 * @return the {@code ClassRule}s that can transform the block that runs
 *         each method in the tested class.
 */
protected List<TestRule> classRules() {
    List<TestRule> result = getTestClass().getAnnotatedMethodValues(null, ClassRule.class, TestRule.class);

    result.addAll(getTestClass().getAnnotatedFieldValues(null, ClassRule.class, TestRule.class));

    return result;
}
 
开发者ID:kuali,项目名称:kc-rice,代码行数:12,代码来源:LoadTimeWeavableTestRunner.java

示例3: getClassRule

import org.junit.ClassRule; //导入依赖的package包/类
/**
 * Create a RuleChain containing a RepositoryFixture for each of the repositories we are testing against
 *
 * @return a RuleChain
 */
@ClassRule
public static TestRule getClassRule() {
    // Put all the fixtures into one chain rule because we want to set up all the repositories at the start of the test, test with them and tear them down at the end
    RuleChain chain = RuleChain.emptyRuleChain();
    for (RepoData repoData : getRepoDataList()) {
        chain = chain.around(repoData.fixture);
    }
    return chain;
}
 
开发者ID:WASdev,项目名称:tool.lars,代码行数:15,代码来源:ResourceFilteringTest.java

示例4: validateRuleAnnotations

import org.junit.ClassRule; //导入依赖的package包/类
/**
 * Validates the annotation of the rule field in the test class.
 * 
 * @param description
 */
private void validateRuleAnnotations(Description description) {

    // If the first run is a @ClassRule run, check if @Rule is annotated
    if (firstRun && !description.isTest()) {

        /*
         * Get the fields of the test class and check if there is only one
         * coverage rule and if the coverage rule field is annotation with
         * both @ClassRule and @Rule.
         */

        int numberOfCoverageRules = 0;
        for (Field field : description.getTestClass().getFields()) {

            final Class<?> fieldType = field.getType();
            if (getClass().isAssignableFrom(fieldType)) {

                ++numberOfCoverageRules;

                final boolean isClassRule = field.isAnnotationPresent(ClassRule.class);
                final boolean isRule = field.isAnnotationPresent(Rule.class);
                if (isClassRule && !isRule) {

                    throw new RuntimeException(getClass().getCanonicalName()
                            + " can only be used as a @ClassRule if it is also a @Rule!");
                }
            }
        }

        // TODO if they really want to have multiple runs, let them?
        if (numberOfCoverageRules > 1) {
            throw new RuntimeException("Only one coverage rule can be used per test class!");
        }
    }
}
 
开发者ID:camunda,项目名称:camunda-bpm-process-test-coverage,代码行数:41,代码来源:TestCoverageProcessEngineRule.java

示例5: testStarted

import org.junit.ClassRule; //导入依赖的package包/类
@Override
public void testStarted(Description description) throws Exception {
  for (Field field : description.getTestClass().getFields()) {
    if (Modifier.isStatic(field.getModifiers()) && field.getType() == HBaseClassTestRule.class &&
      field.isAnnotationPresent(ClassRule.class)) {
      HBaseClassTestRule timeout = (HBaseClassTestRule) field.get(null);
      assertEquals(
        "The HBaseClassTestRule ClassRule in " + description.getTestClass().getName() +
          " is for " + timeout.getClazz().getName(),
        description.getTestClass(), timeout.getClazz());
      return;
    }
  }
  fail("No HBaseClassTestRule ClassRule for " + description.getTestClass().getName());
}
 
开发者ID:apache,项目名称:hbase,代码行数:16,代码来源:HBaseClassTestRuleChecker.java

示例6: classRules

import org.junit.ClassRule; //导入依赖的package包/类
/**
 * @return the {@code ClassRule}s that can transform the block that runs
 *         each method in the tested class.
 */
protected List<TestRule> classRules() {
    List<TestRule> result = fTestClass.getAnnotatedMethodValues(null, ClassRule.class, TestRule.class);

    result.addAll(fTestClass.getAnnotatedFieldValues(null, ClassRule.class, TestRule.class));

    return result;
}
 
开发者ID:lcm-proj,项目名称:lcm,代码行数:12,代码来源:ParentRunner.java

示例7: createStatement

import org.junit.ClassRule; //导入依赖的package包/类
public Statement createStatement(final TestClass testClass, final Statement next,
                                 final Description description, final RunNotifier notifier) {
    final List<TestRule> classRules = new ArrayList<TestRule>();
    classRules.addAll(testClass.getAnnotatedMethodValues(null, ClassRule.class, TestRule.class));
    classRules.addAll(testClass.getAnnotatedFieldValues(null, ClassRule.class, TestRule.class));
    return classRules.isEmpty() ? next : new RunRules(next, classRules, description);
}
 
开发者ID:bechte,项目名称:junit-hierarchicalcontextrunner,代码行数:8,代码来源:ClassRuleStatementBuilder.java

示例8: givenTestClassWithoutRuleAnnotations_returnsNextStatement

import org.junit.ClassRule; //导入依赖的package包/类
@Test
public void givenTestClassWithoutRuleAnnotations_returnsNextStatement() throws Exception {
    when(testClass.getAnnotatedMethodValues(null, ClassRule.class, TestRule.class)).thenReturn(Collections.EMPTY_LIST);
    when(testClass.getAnnotatedFieldValues(null, ClassRule.class, TestRule.class)).thenReturn(Collections.EMPTY_LIST);

    Statement statement = builder.createStatement(testClass, next, description, notifier);
    assertThat(statement, is(equalTo(next)));
}
 
开发者ID:bechte,项目名称:junit-hierarchicalcontextrunner,代码行数:9,代码来源:ClassRuleStatementBuilderTest.java

示例9: givenTestClassWithRuleAnnotatedMethods_returnsRunRulesStatement

import org.junit.ClassRule; //导入依赖的package包/类
@Test
public void givenTestClassWithRuleAnnotatedMethods_returnsRunRulesStatement() throws Exception {
    List<TestRule> methods = Arrays.asList(rule1, rule2);
    when(testClass.getAnnotatedMethodValues(null, ClassRule.class, TestRule.class)).thenReturn(methods);
    when(testClass.getAnnotatedFieldValues(null, ClassRule.class, TestRule.class)).thenReturn(Collections.EMPTY_LIST);

    Statement actual = builder.createStatement(testClass, next, description, notifier);
    assertThat(actual, is(instanceOf(RunRules.class)));
}
 
开发者ID:bechte,项目名称:junit-hierarchicalcontextrunner,代码行数:10,代码来源:ClassRuleStatementBuilderTest.java

示例10: givenTestClassWithRuleAnnotatedFields_returnsRunRulesStatement

import org.junit.ClassRule; //导入依赖的package包/类
@Test
public void givenTestClassWithRuleAnnotatedFields_returnsRunRulesStatement() throws Exception {
    List<TestRule> fields = Arrays.asList(rule1, rule2);
    when(testClass.getAnnotatedMethodValues(null, ClassRule.class, TestRule.class)).thenReturn(Collections.EMPTY_LIST);
    when(testClass.getAnnotatedFieldValues(null, ClassRule.class, TestRule.class)).thenReturn(fields);

    Statement actual = builder.createStatement(testClass, next, description, notifier);
    assertThat(actual, is(instanceOf(RunRules.class)));
}
 
开发者ID:bechte,项目名称:junit-hierarchicalcontextrunner,代码行数:10,代码来源:ClassRuleStatementBuilderTest.java

示例11: givenTestClassWithRuleAnnotatedMethodsAndFields_returnsRunRulesStatement

import org.junit.ClassRule; //导入依赖的package包/类
@Test
public void givenTestClassWithRuleAnnotatedMethodsAndFields_returnsRunRulesStatement() throws Exception {
    List<TestRule> methods = Arrays.asList(rule1);
    List<TestRule> fields = Arrays.asList(rule2);
    when(testClass.getAnnotatedMethodValues(null, ClassRule.class, TestRule.class)).thenReturn(methods);
    when(testClass.getAnnotatedFieldValues(null, ClassRule.class, TestRule.class)).thenReturn(fields);

    Statement actual = builder.createStatement(testClass, next, description, notifier);
    assertThat(actual, is(instanceOf(RunRules.class)));
}
 
开发者ID:bechte,项目名称:junit-hierarchicalcontextrunner,代码行数:11,代码来源:ClassRuleStatementBuilderTest.java

示例12: methodBlock

import org.junit.ClassRule; //导入依赖的package包/类
@Override
@SuppressWarnings("deprecation")
protected Statement methodBlock(FrameworkMethod method) {
  Object test;
  try {
    test = new ReflectiveCallable() {
      @Override
      protected Object runReflectiveCall() throws Throwable {
        return createTest();
      }
    }.run();
  } catch (Throwable e) {
    return new Fail(e);
  }
  boolean validated = true;
  for (CdhServer cdhServer : getTestClass().getAnnotatedFieldValues(test, ClassRule.class, CdhServer.class)) {
    validated = validated && cdhServer.isValid();
    if (validated) {
      for (CdhServer cdhServerDependency : cdhServer.getDependencies()) {
        validated = validated && cdhServerDependency.isValid();
      }
    }
  }
  Statement statement;
  if (validated) {
    statement = methodInvoker(method, test);
    statement = withLogging(method, test, statement);
    statement = possiblyExpectingExceptions(method, test, statement);
    statement = withPotentialTimeout(method, test, statement);
    statement = withBefores(method, test, statement);
    statement = withAfters(method, test, statement);
    statement = withServerRules(method, test, statement);
    statement = withRules(method, test, statement);
  } else {
    statement = new Statement() {
      @Override
      public void evaluate() throws Throwable {
        if (LOG.isWarnEnabled()) {
          LOG.warn("Skipping [" + method.getDeclaringClass().getCanonicalName() + "." + method.getName() + "], invalid classpath");
        }
      }
    };
  }
  return statement;
}
 
开发者ID:ggear,项目名称:cloudera-framework,代码行数:46,代码来源:TestRunner.java

示例13: classRules

import org.junit.ClassRule; //导入依赖的package包/类
/**
 * @return the {@code ClassRule}s that can transform the block that runs
 *         each method in the tested class.
 */
protected List<TestRule> classRules() {
    List<TestRule> result = fTestClass.getAnnotatedMethodValues(null, ClassRule.class, TestRule.class);
    result.addAll(fTestClass.getAnnotatedFieldValues(null, ClassRule.class, TestRule.class));
    return result;
}
 
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:10,代码来源:ParentRunner.java

示例14: orderMethod

import org.junit.ClassRule; //导入依赖的package包/类
@ClassRule
public static OrderTestRule orderMethod() {
    return new OrderTestRule("orderMethod");
}
 
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:5,代码来源:ClassRulesTest.java

示例15: getCounter

import org.junit.ClassRule; //导入依赖的package包/类
@ClassRule
public static Counter getCounter() {
    return counter;
}
 
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:5,代码来源:ClassRulesTest.java


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