Created
October 25, 2013 15:16
-
-
Save rmannibucau/7156354 to your computer and use it in GitHub Desktop.
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
/* | |
* Licensed to the Apache Software Foundation (ASF) under one | |
* or more contributor license agreements. See the NOTICE file | |
* distributed with this work for additional information | |
* regarding copyright ownership. The ASF licenses this file | |
* to you under the Apache License, Version 2.0 (the | |
* "License"); you may not use this file except in compliance | |
* with the License. You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, | |
* software distributed under the License is distributed on an | |
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
* KIND, either express or implied. See the License for the | |
* specific language governing permissions and limitations | |
* under the License. | |
*/ | |
package org.apache.webbeans.newtests.proxy; | |
import org.apache.webbeans.config.WebBeansContext; | |
import org.apache.webbeans.proxy.ProxyGenerationException; | |
import org.apache.webbeans.proxy.SubclassProxyFactory; | |
import org.apache.xbean.asm4.ClassWriter; | |
import org.junit.Test; | |
import java.lang.reflect.Method; | |
import static org.junit.Assert.assertNotNull; | |
public class InnerClassProxyTest { | |
@Test | |
public void proxy() throws IllegalAccessException, InstantiationException { | |
final SubclassProxyFactory proxyFactory = new SubclassProxyFactory(new WebBeansContext()) { | |
@Override | |
protected void delegateInterceptedMethods(ClassLoader classLoader, ClassWriter cw, String proxyClassFileName, Class<?> classToProxy, | |
Method[] interceptedMethods) throws ProxyGenerationException { | |
super.delegateNonInterceptedMethods(classLoader, cw, proxyClassFileName, classToProxy, interceptedMethods); | |
} | |
}; | |
final Foo foo = proxyFactory.createSubClass(Foo.class.getClassLoader(), Foo.class).newInstance(); | |
assertNotNull(foo); | |
// next line will throw an exception if any issue | |
proxyFactory.createSubClass(Foo.Inner.class.getClassLoader(), Foo.Inner.class).newInstance(); | |
} | |
public static class Foo { | |
public String bar(final boolean b) throws Inner { | |
if (b) { | |
throw new Inner("fail"); | |
} | |
return "ok"; | |
} | |
public static class Inner extends Exception { | |
public Inner() { | |
// no-op | |
} | |
public Inner(final String message) { | |
super(message); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment