Created
October 24, 2011 18:52
-
-
Save RainerW/1309806 to your computer and use it in GitHub Desktop.
junit#351
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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