Java 类org.junit.rules.MethodRule 实例源码

项目:powermock    文件:PowerMockJUnit49RunnerDelegateImpl.java   
@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;
}
项目:jpa-unit    文件:JpaUnitRule.java   
@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;
}
项目:FuzzUnit    文件:FuzzUnitTestRunner.java   
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;
}
项目:FuzzUnit    文件:FuzzUnitTestRunner.java   
/**
 * @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;
}
项目:FuzzUnit    文件:FuzzUnitTestRunner.java   
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?" );
        }
}
项目:sosiefier    文件:RuleFieldValidatorTest.java   
@Rule
public MethodRule getTemporaryFolder() {
    return new MethodRule() {
        public Statement apply(Statement base, FrameworkMethod method,
                Object target) {
            return null;
        }
    };
}
项目:sosiefier    文件:BlockJUnit4ClassRunnerOverrideTest.java   
@Override
protected List<MethodRule> rules(Object test) {
    final LinkedList<MethodRule> methodRules = new LinkedList<MethodRule>(
            super.rules(test));
    methodRules.add(new FlipBitRule());
    return methodRules;
}
项目:contiperf    文件:BlockContiPerfClassRunner.java   
/**
    * 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;
   }
项目:contiperf    文件:BlockContiPerfClassRunner.java   
/**
    * 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?");
}
   }
项目:needle4j    文件:NeedleRule.java   
/**
 * {@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);

}
项目:needle4j    文件:NeedleRule.java   
/**
 * 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;
}
项目:needle4j    文件:NeedleRuleBuilder.java   
@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;
}
项目:moxiemocks    文件:MoxieRunner.java   
/**
 * 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;
}
项目:junit-hierarchicalcontextrunner    文件:TestRuleDefinitions.java   
public boolean contains(MethodRule methodRule) {
    for (TestRuleInTestHierarchy t : testRulePositionInTestHierarchies) {
        if (t.getTestRule().equals(methodRule))
            return true;
    }
    return false;
}
项目:junit-hierarchicalcontextrunner    文件:TestRuleDefinitions.java   
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;
}
项目:junit    文件:RuleFieldValidatorTest.java   
@Rule
public MethodRule getTemporaryFolder() {
    return new MethodRule() {
        public Statement apply(Statement base, FrameworkMethod method,
                Object target) {
            return null;
        }
    };
}
项目:junit    文件:BlockJUnit4ClassRunnerOverrideTest.java   
@Override
protected List<MethodRule> rules(Object test) {
    final LinkedList<MethodRule> methodRules = new LinkedList<MethodRule>(
            super.rules(test));
    methodRules.add(new FlipBitRule());
    return methodRules;
}
项目:health-and-care-developer-network    文件:RuleFieldValidatorTest.java   
@Rule
public MethodRule getTemporaryFolder() {
    return new MethodRule() {
        public Statement apply(Statement base, FrameworkMethod method,
                Object target) {
            return null;
        }
    };
}
项目:health-and-care-developer-network    文件:BlockJUnit4ClassRunnerOverrideTest.java   
@Override
protected List<MethodRule> rules(Object test) {
    final LinkedList<MethodRule> methodRules = new LinkedList<MethodRule>(
            super.rules(test));
    methodRules.add(new FlipBitRule());
    return methodRules;
}
项目:confit    文件:FeatureTestsRunner.java   
/**
 * Simply copied from BlockJUnit4ClassRunner, since its not accessible.
 */
private Statement withRules(FrameworkMethod method, Object target, Statement statement) {
    Statement result = statement;
    for (MethodRule each : getTestClass().getAnnotatedFieldValues(target, Rule.class,
            MethodRule.class))
        result = each.apply(result, method, target);
    return result;
}
项目:jpa-unit    文件:JpaUnitRunner.java   
@Override
protected List<MethodRule> rules(final Object target) {
    return registerRules(super.rules(target), executor, JpaUnitContext.getInstance(getTestClass().getJavaClass()));
}
项目:jpa-unit    文件:JpaUnitRule.java   
private List<MethodRule> getRules() {
    return registerRules(new ArrayList<>(), executor, ctx);
}
项目:jpa-unit    文件:MethodRuleRegistrar.java   
public static List<MethodRule> registerRules(final List<MethodRule> rules, final DecoratorExecutor executor,
        final ExecutionContext ctx) {
    rules.add((base, method, target) -> new TestMethodStatement(ctx, executor, base, method, target));
    rules.add((base, method, target) -> new TestClassStatement(ctx, executor, base, target));
    return rules;
}
项目:powermock    文件:PowerMockJUnit47RunnerDelegateImpl.java   
protected Statement applyRuleToLastStatement(final Method method, final Object testInstance, Field field,
                                             final LastRuleTestExecutorStatement lastStatement) throws IllegalAccessException {
    MethodRule rule = (MethodRule) field.get(testInstance);
    Statement statement = rule.apply(lastStatement, new FrameworkMethod(method), testInstance);
    return statement;
}
项目:needle4j    文件:NeedleRuleBuilder.java   
public AbstractNeedleRuleBuilder<NeedleRuleBuilder, NeedleRule> withOuter(final MethodRule rule) {
    methodRuleChain.add(0, rule);
    return this;
}
项目:kalibro    文件:FieldReflectorTest.java   
@Test
public void shouldGetFieldType() {
    assertEquals(MethodRule.class, reflector.getFieldType("testTimeout"));
    assertEquals(FieldReflector.class, reflector.getFieldType("reflector"));
}
项目:kalibro    文件:TypeMemberFilterTest.java   
@Before
public void setUp() {
    filter = new TypeMemberFilter(MethodRule.class);
}
项目:junit-hierarchicalcontextrunner    文件:TestRuleDefinitions.java   
public void addMethodRules(List<MethodRule> annotatedFieldValues, Object instance) {
    for (MethodRule methodRule : annotatedFieldValues)
        methodRulePositionInTestHierarchies.add(new MethodRuleInTestHierarchy(methodRule, instance));
}
项目:junit-hierarchicalcontextrunner    文件:MethodRuleInTestHierarchy.java   
public MethodRuleInTestHierarchy(MethodRule methodRule, Object instance) {
    this.methodRule = methodRule;
    this.instance = instance;
}
项目:junit-hierarchicalcontextrunner    文件:MethodRuleInTestHierarchy.java   
public MethodRule getMethodRule() {
    return methodRule;
}