本文整理匯總了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;
}