类org.springframework.test.context.junit4.rules.SpringMethodRule源码实例Demo

下面列出了怎么用org.springframework.test.context.junit4.rules.SpringMethodRule的API类实例代码及写法,或者点击链接到github查看源代码。

private static void ensureSpringRulesAreNotPresent(Class<?> testClass) {
	for (Field field : testClass.getFields()) {
		Assert.state(!SpringClassRule.class.isAssignableFrom(field.getType()), () -> String.format(
				"Detected SpringClassRule field in test class [%s], " +
				"but SpringClassRule cannot be used with the SpringJUnit4ClassRunner.", testClass.getName()));
		Assert.state(!SpringMethodRule.class.isAssignableFrom(field.getType()), () -> String.format(
				"Detected SpringMethodRule field in test class [%s], " +
				"but SpringMethodRule cannot be used with the SpringJUnit4ClassRunner.", testClass.getName()));
	}
}
 
private static void ensureSpringRulesAreNotPresent(Class<?> testClass) {
	for (Field field : testClass.getFields()) {
		Assert.state(!SpringClassRule.class.isAssignableFrom(field.getType()), () -> String.format(
				"Detected SpringClassRule field in test class [%s], " +
				"but SpringClassRule cannot be used with the SpringJUnit4ClassRunner.", testClass.getName()));
		Assert.state(!SpringMethodRule.class.isAssignableFrom(field.getType()), () -> String.format(
				"Detected SpringMethodRule field in test class [%s], " +
				"but SpringMethodRule cannot be used with the SpringJUnit4ClassRunner.", testClass.getName()));
	}
}
 
private static void ensureSpringRulesAreNotPresent(Class<?> testClass) {
	for (Field field : testClass.getFields()) {
		if (SpringClassRule.class.isAssignableFrom(field.getType())) {
			throw new IllegalStateException(String.format("Detected SpringClassRule field in test class [%s], " +
					"but SpringClassRule cannot be used with the SpringJUnit4ClassRunner.", testClass.getName()));
		}
		if (SpringMethodRule.class.isAssignableFrom(field.getType())) {
			throw new IllegalStateException(String.format("Detected SpringMethodRule field in test class [%s], " +
					"but SpringMethodRule cannot be used with the SpringJUnit4ClassRunner.", testClass.getName()));
		}
	}
}
 
 类方法
 同包方法