Skip to content

Commit

Permalink
replacing deprecated JUnit MethodRule with TestRule
Browse files Browse the repository at this point in the history
  • Loading branch information
toby-weston-db committed Jan 21, 2014
1 parent 221ca95 commit e6107cc
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,23 @@

package com.google.code.tempusfugit.concurrency;

import org.junit.rules.MethodRule;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.Statement;

public class ConcurrentRule implements MethodRule {
import java.lang.reflect.Method;

public Statement apply(Statement base, final FrameworkMethod method, final Object target) {
return new RunConcurrently(method, base);
}
import static com.google.code.tempusfugit.ExceptionWrapper.wrapAsRuntimeException;

public class ConcurrentRule implements TestRule {

@Override
public Statement apply(Statement base, Description description) {
return wrapAsRuntimeException(() -> {
Class<?> test = description.getTestClass();
Method method = test.getMethod(description.getMethodName());
return new RunConcurrently(new FrameworkMethod(method), base);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,23 @@

package com.google.code.tempusfugit.concurrency;

import org.junit.rules.MethodRule;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.Statement;

public class RepeatingRule implements MethodRule {
import java.lang.reflect.Method;

public Statement apply(Statement base, final FrameworkMethod method, final Object target) {
return new RunRepeatedly(method, base);
}
import static com.google.code.tempusfugit.ExceptionWrapper.wrapAsRuntimeException;

public class RepeatingRule implements TestRule {

@Override
public Statement apply(Statement base, Description description) {
return wrapAsRuntimeException(() -> {
Class<?> test = description.getTestClass();
Method method = test.getMethod(description.getMethodName());
return new RunRepeatedly(new FrameworkMethod(method), base);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ public class ExceptionWrapperTest {
private final Mockery context = new JUnit4Mockery();
private final Callable<String> callable = context.mock(Callable.class);

public void exampleLambdaSyntax() throws SomeOtherCheckedException {
wrapAnyException(() -> null, with(SomeOtherCheckedException.class));
}

@Test
public void shouldDelegateCallReflectiveException() throws Exception {
callWill(returnValue("value"));
Expand Down

0 comments on commit e6107cc

Please sign in to comment.