Class TestContext
- java.lang.Object
-
- com.github.advisedtesting.core.internal.TestContext
-
public class TestContext extends Object
This is a context meant to be used with testing classes, which decouples the ability to add meaningful annotations to a test method from the test runner. There are some incidental couplings to be aware of however. First the annotation must specify aMethodInterceptorit wishes to advise a test. Second thatMethodInterceptormust have a zero argument constructor. Third any state theMethodInterceptorshould be done so in a thread safe way. Either all in the zero length argument constructor, or with synchronized logic. Fourth if aMethodInterceptorneeds to tear down state it has constructed, it should implementCloseableFifth the markingAnnotationshould have a single parameter implementedBy with a default value of the Class of theMethodInterceptorthe author wishes to use.- Author:
- rex
-
-
Constructor Summary
Constructors Constructor Description TestContext()When the context is constructed, it is registered for destruction.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Call all close methods implemented by anyMethodInterceptorinstances stored in local cache.org.aopalliance.intercept.MethodInterceptorgetAdviceFor(Annotation annotation, ClassLoader classLoader)Build and cache, or retrieve, aMethodInterceptorassociated with the annotationClass input, as specified, byTestContextclass documentation.booleanisAdviceAnnotation(Annotation annotation)
-
-
-
Method Detail
-
getAdviceFor
public org.aopalliance.intercept.MethodInterceptor getAdviceFor(Annotation annotation, ClassLoader classLoader)
Build and cache, or retrieve, aMethodInterceptorassociated with the annotationClass input, as specified, byTestContextclass documentation.- Parameters:
annotation- the annotation who's relatedMethodInterceptorinstance will be returned.classLoader- in which to load the MethodInterceptor.- Returns:
- an advice instance singleton from the annotationClass's implementedBy parameter if any, and is constructible, or null.
-
close
public void close()
Call all close methods implemented by anyMethodInterceptorinstances stored in local cache.
-
isAdviceAnnotation
public boolean isAdviceAnnotation(Annotation annotation)
-
-