本文整理汇总了Java中org.junit.rules.MethodRule类的典型用法代码示例。如果您正苦于以下问题:Java MethodRule类的具体用法?Java MethodRule怎么用?Java MethodRule使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MethodRule类属于org.junit.rules包,在下文中一共展示了MethodRule类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: applyRuleToLastStatement
import org.junit.rules.MethodRule; //导入依赖的package包/类
@Override
protected Statement applyRuleToLastStatement(final Method method, final Object testInstance, Field field,
final LastRuleTestExecutorStatement lastStatement) throws IllegalAccessException {
final Object fieldValue = field.get(testInstance);
final Statement statement;
if (fieldValue instanceof MethodRule) {
// the MethodRule is known by junit 4.9 -> delegate to super-class
statement = super.applyRuleToLastStatement(method, testInstance, field, lastStatement);
} else if (fieldValue instanceof TestRule){
TestRule rule = (TestRule) fieldValue;
statement = rule.apply(lastStatement, description);
} else {
throw new IllegalStateException("Can only handle MethodRule and TestRule");
}
return statement;
}
示例2: apply
import org.junit.rules.MethodRule; //导入依赖的package包/类
@Override
public Statement apply(final Statement result, final FrameworkMethod method, final Object target) {
Statement lastResult = result;
for (final MethodRule rule : getRules()) {
lastResult = rule.apply(lastResult, method, target);
}
return lastResult;
}
示例3: withRules
import org.junit.rules.MethodRule; //导入依赖的package包/类
private Statement withRules( FrameworkMethod method, Object target, Statement statement )
{
Statement result = statement;
for( MethodRule each : rules( target ) )
result = each.apply( result, method, target );
return result;
}
示例4: rules
import org.junit.rules.MethodRule; //导入依赖的package包/类
/**
* @param test the test class
* @return the MethodRules that can transform the block
* that runs each method in the tested class.
*/
protected List<MethodRule> rules( Object test )
{
List<MethodRule> results = new ArrayList<MethodRule>();
for( FrameworkField each : ruleFields() )
results.add( createRule( test, each ) );
return results;
}
示例5: createRule
import org.junit.rules.MethodRule; //导入依赖的package包/类
private MethodRule createRule( Object test, FrameworkField each )
{
try {
return (MethodRule) each.get( test );
} catch( IllegalAccessException e ) {
throw new RuntimeException( "How did getFields return a field we couldn't access?" );
} catch( IllegalArgumentException ex ) {
throw new RuntimeException( "How did getFields return a field we couldn't access?" );
}
}
示例6: getTemporaryFolder
import org.junit.rules.MethodRule; //导入依赖的package包/类
@Rule
public MethodRule getTemporaryFolder() {
return new MethodRule() {
public Statement apply(Statement base, FrameworkMethod method,
Object target) {
return null;
}
};
}
示例7: rules
import org.junit.rules.MethodRule; //导入依赖的package包/类
@Override
protected List<MethodRule> rules(Object test) {
final LinkedList<MethodRule> methodRules = new LinkedList<MethodRule>(
super.rules(test));
methodRules.add(new FlipBitRule());
return methodRules;
}
示例8: withRules
import org.junit.rules.MethodRule; //导入依赖的package包/类
/**
* method taken as is from BlockJUnit4ClassRunner 4.7 in order to preserve
* its functionality over following versions
*/
private Statement withRules(FrameworkMethod method, Object target,
Statement statement) {
Statement result = statement;
for (MethodRule each : rules(target)) {
result = each.apply(result, method, target);
}
return result;
}
示例9: createRule
import org.junit.rules.MethodRule; //导入依赖的package包/类
/**
* method taken as is from BlockJUnit4ClassRunner 4.7 in order to preserve
* its functionality over following versions
*/
private MethodRule createRule(Object test, FrameworkField each) {
try {
return (MethodRule) each.get(test);
} catch (IllegalAccessException e) {
throw new RuntimeException(
"How did getFields return a field we couldn't access?");
}
}
示例10: apply
import org.junit.rules.MethodRule; //导入依赖的package包/类
/**
* {@inheritDoc} Before evaluation of the base statement, the test instance
* will initialized.
*/
@Override
public Statement apply(final Statement base, final FrameworkMethod method, final Object target) {
Statement appliedStatement = base;
for (MethodRule rule : methodRuleChain) {
appliedStatement = rule.apply(appliedStatement, method, target);
}
return statement(appliedStatement, target);
}
示例11: withOuter
import org.junit.rules.MethodRule; //导入依赖的package包/类
/**
* Encloses the added rule.
*
* @param rule
* - outer method rule
* @return {@link NeedleRule}
*/
public NeedleRule withOuter(final MethodRule rule) {
if (rule instanceof InjectionProvider) {
addInjectionProvider((InjectionProvider<?>) rule);
}
methodRuleChain.add(0, rule);
return this;
}
示例12: build
import org.junit.rules.MethodRule; //导入依赖的package包/类
@Override
protected NeedleRule build(final InjectionConfiguration injectionConfiguration,
final InjectionProvider<?>... injectionProvider) {
final NeedleRule needleRule = new NeedleRule(injectionConfiguration, injectionProvider);
for (final MethodRule rule : methodRuleChain) {
needleRule.withOuter(rule);
}
return needleRule;
}
示例13: rules
import org.junit.rules.MethodRule; //导入依赖的package包/类
/**
* Internal JUnit method - overridden to add a {@link MoxieRule} to all tests.
*/
@Override
protected List<MethodRule> rules(Object test) {
ArrayList<MethodRule> result = new ArrayList<MethodRule>(super.rules(test));
result.add(new MoxieRule());
return result;
}
示例14: contains
import org.junit.rules.MethodRule; //导入依赖的package包/类
public boolean contains(MethodRule methodRule) {
for (TestRuleInTestHierarchy t : testRulePositionInTestHierarchies) {
if (t.getTestRule().equals(methodRule))
return true;
}
return false;
}
示例15: getMethodRulesDefinedForThisHierarchyLevel
import org.junit.rules.MethodRule; //导入依赖的package包/类
public List<MethodRule> getMethodRulesDefinedForThisHierarchyLevel(Object hierarchyContext) {
List<MethodRule> result = new ArrayList<MethodRule>();
for (MethodRuleInTestHierarchy testRulePosition : methodRulePositionInTestHierarchies)
if (hierarchyOfTestsFromLowestToHighest.indexOf(testRulePosition.getObjectRepresentingHierarchyLevel()) >= hierarchyOfTestsFromLowestToHighest.indexOf(hierarchyContext))
result.add(testRulePosition.getMethodRule());
return result;
}