當前位置: 首頁>>代碼示例>>Java>>正文


Java MethodRule類代碼示例

本文整理匯總了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;
}
 
開發者ID:awenblue,項目名稱:powermock,代碼行數:17,代碼來源:PowerMockJUnit49RunnerDelegateImpl.java

示例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;
}
 
開發者ID:dadrus,項目名稱:jpa-unit,代碼行數:11,代碼來源:JpaUnitRule.java

示例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;
}
 
開發者ID:JoeBeeton,項目名稱:FuzzUnit,代碼行數:8,代碼來源:FuzzUnitTestRunner.java

示例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;
}
 
開發者ID:JoeBeeton,項目名稱:FuzzUnit,代碼行數:13,代碼來源:FuzzUnitTestRunner.java

示例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?" );
        }
}
 
開發者ID:JoeBeeton,項目名稱:FuzzUnit,代碼行數:11,代碼來源:FuzzUnitTestRunner.java

示例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;
        }
    };
}
 
開發者ID:DIVERSIFY-project,項目名稱:sosiefier,代碼行數:10,代碼來源:RuleFieldValidatorTest.java

示例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;
}
 
開發者ID:DIVERSIFY-project,項目名稱:sosiefier,代碼行數:8,代碼來源:BlockJUnit4ClassRunnerOverrideTest.java

示例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;
   }
 
開發者ID:lucaspouzac,項目名稱:contiperf,代碼行數:13,代碼來源:BlockContiPerfClassRunner.java

示例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?");
}
   }
 
開發者ID:lucaspouzac,項目名稱:contiperf,代碼行數:13,代碼來源:BlockContiPerfClassRunner.java

示例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);

}
 
開發者ID:needle4j,項目名稱:needle4j,代碼行數:15,代碼來源:NeedleRule.java

示例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;
}
 
開發者ID:needle4j,項目名稱:needle4j,代碼行數:15,代碼來源:NeedleRule.java

示例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;
}
 
開發者ID:needle4j,項目名稱:needle4j,代碼行數:11,代碼來源:NeedleRuleBuilder.java

示例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;
}
 
開發者ID:pobrelkey,項目名稱:moxiemocks,代碼行數:10,代碼來源:MoxieRunner.java

示例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;
}
 
開發者ID:bechte,項目名稱:junit-hierarchicalcontextrunner,代碼行數:8,代碼來源:TestRuleDefinitions.java

示例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;
}
 
開發者ID:bechte,項目名稱:junit-hierarchicalcontextrunner,代碼行數:8,代碼來源:TestRuleDefinitions.java


注:本文中的org.junit.rules.MethodRule類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。