1. kubek2k
  2. Springockito
Issue #35 new

Mocks stop working if @ContextConfiguration declared on a base class

Anonymous created an issue

SHould look for annotations recursively,

Comments (2)

  1. Sam Brannen

    That's simply not true.

    This is in fact a bug in the Springockito implementation which I just explained on Stack Overflow.

    The following is the proper implementation of SpringockitoContextLoader:

    import org.kubek2k.springockito.annotations.internal.Loader;
    
    import org.springframework.context.ConfigurableApplicationContext;
    import org.springframework.context.support.GenericApplicationContext;
    import org.springframework.test.context.MergedContextConfiguration;
    import org.springframework.test.context.support.GenericXmlContextLoader;
    
    public class SpringockitoContextLoader extends GenericXmlContextLoader {
    
        private final Loader loader = new Loader();
    
        @Override
        protected void prepareContext(ConfigurableApplicationContext context, MergedContextConfiguration mergedConfig) {
            super.prepareContext(context, mergedConfig);
            this.loader.defineMocksAndSpies(mergedConfig.getTestClass());
        }
    
        @Override
        protected void customizeContext(GenericApplicationContext context) {
            super.customizeContext(context);
            this.loader.registerMocksAndSpies(context);
        }
    
    }
    

    Regards,

    Sam (author of the Spring TestContext Framework)

  2. Log in to comment