Skip to content

Instantly share code, notes, and snippets.

@RainerW
Created October 24, 2011 18:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RainerW/1309806 to your computer and use it in GitHub Desktop.
Save RainerW/1309806 to your computer and use it in GitHub Desktop.
junit#351
package rules.impl;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
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;
import org.springframework.core.annotation.AnnotationUtils;
import com.seitenbau.testing.rules.impl.SearchTest.MyAnnotation;
class RestApiTests
{
@Test
@MyAnnotation
public void test_WorkingCall()
{
Assert.fail();
}
}
public class SearchTest extends RestApiTests
{
@Rule public MyRule search = new MyRule();
@Rule public MyRuleOld old = new MyRuleOld();
@Test
public void test_WorkingCall()
{
Assert.assertNotNull(old.annotation);
Assert.assertNotNull(search.annotation);
}
class MyRule implements TestRule{
MyAnnotation annotation;
public Statement apply(final Statement base, Description description)
{
annotation = description.getAnnotation(MyAnnotation.class);
return new Statement(){@Override public void evaluate() throws Throwable {
base.evaluate();
}};
}
}
class MyRuleOld implements MethodRule {
MyAnnotation annotation;
public Statement apply(final Statement base, FrameworkMethod method, Object target)
{
annotation = AnnotationUtils.findAnnotation(method.getMethod(),MyAnnotation.class);
return new Statement(){@Override public void evaluate() throws Throwable {
base.evaluate();
}};
}
}
@Retention(RetentionPolicy.RUNTIME) @interface MyAnnotation { }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment