@@ -0,0 +1,3465 @@
+/*%0A * Copyright 2014 - 2021 Blazebit.%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *      http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0Apackage com.blazebit.persistence.integration.view.spring;%0A%0Aimport com.blazebit.persistence.integration.view.spring.views.sub1.TestView1;%0Aimport com.blazebit.persistence.integration.view.spring.views.sub2.TestView2;%0Aimport com.blazebit.persistence.view.spi.EntityViewConfiguration;%0Aimport org.junit.AfterClass;%0Aimport org.junit.Assert;%0Aimport org.junit.Test;%0Aimport org.junit.runner.RunWith;%0Aimport org.springframework.cglib.proxy.Enhancer;%0Aimport org.springframework.cglib.proxy.MethodInterceptor;%0Aimport org.springframework.cglib.proxy.MethodProxy;%0Aimport org.springframework.context.annotation.Configuration;%0Aimport org.springframework.test.context.ContextConfiguration;%0Aimport org.springframework.test.context.junit4.SpringJUnit4ClassRunner;%0A%0Aimport javax.inject.Inject;%0Aimport java.lang.reflect.Method;%0Aimport java.util.Objects;%0Aimport java.util.Set;%0Aimport java.util.concurrent.atomic.AtomicInteger;%0A%0A/**%0A * @author Moritz Becker%0A * @since 1.2.0%0A */%0A@RunWith(SpringJUnit4ClassRunner.class)%0A@ContextConfiguration(classes = AnnotationClassLoaderTest.TestConfig.class%0A)%0Apublic class AnnotationClassLoaderTest %7B%0A%0A    static final AtomicInteger trackedClassLoaderViews = new AtomicInteger();%0A    static final ClassLoader previousClassLoader = Thread.currentThread().getContextClassLoader();%0A%0A    static %7B%0A        Enhancer enhancer = new Enhancer();%0A        enhancer.setSuperclass(ClassLoader.class);%0A        enhancer.setCallback(new MethodInterceptor() %7B%0A            @Override%0A            public Object intercept(Object object, Method method, Object%5B%5D args, MethodProxy proxy) throws Throwable %7B%0A                if (method.getName().contains(%22loadClass%22) && args.length == 1) %7B%0A                    if (Objects.equals(TestView1.class.getName(), args%5B0%5D) %7C%7C Objects.equals(TestView2.class.getName(), args%5B0%5D)) %7B%0A                        trackedClassLoaderViews.incrementAndGet();%0A                    %7D%0A                %7D%0A                return proxy.invokeSuper(object, args);%0A            %7D%0A        %7D);%0A        ClassLoader proxy = (ClassLoader) enhancer.create();%0A        Thread.currentThread().setContextClassLoader(proxy);%0A    %7D%0A%0A    @AfterClass%0A    public static void verify() %7B%0A        Thread.currentThread().setContextClassLoader(previousClassLoader);%0A    %7D%0A%0A    @Inject%0A    private EntityViewConfiguration entityViewConfiguration;%0A%0A    @Test%0A    public void testInjectionWithCustomLoader() %7B%0A        Set%3CClass%3C?%3E%3E entityViews = entityViewConfiguration.getEntityViews();%0A        Assert.assertEquals(2, entityViews.size());%0A        Assert.assertEquals(2, trackedClassLoaderViews.get());%0A        Assert.assertTrue(entityViewConfiguration.getEntityViews().contains(TestView1.class));%0A        Assert.assertTrue(entityViewConfiguration.getEntityViews().contains(TestView2.class));%0A    %7D%0A%0A    @Configuration%0A    @EnableEntityViews%0A    static class TestConfig %7B%0A    %7D%0A%7D%0A

Test for #1247