Class 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 a MethodInterceptor it wishes to advise a test. Second that MethodInterceptor must have a zero argument constructor. Third any state the MethodInterceptor should be done so in a thread safe way. Either all in the zero length argument constructor, or with synchronized logic. Fourth if a MethodInterceptor needs to tear down state it has constructed, it should implement Closeable Fifth the marking Annotation should have a single parameter implementedBy with a default value of the Class of the MethodInterceptor the author wishes to use.
    Author:
    rex
    • Constructor Detail

      • TestContext

        public TestContext()
        When the context is constructed, it is registered for destruction.
    • Method Detail

      • getAdviceFor

        public org.aopalliance.intercept.MethodInterceptor getAdviceFor​(Annotation annotation,
                                                                        ClassLoader classLoader)
        Build and cache, or retrieve, a MethodInterceptor associated with the annotationClass input, as specified, by TestContext class documentation.
        Parameters:
        annotation - the annotation who's related MethodInterceptor instance 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 any MethodInterceptor instances stored in local cache.
      • isAdviceAnnotation

        public boolean isAdviceAnnotation​(Annotation annotation)