Skip to content

Instantly share code, notes, and snippets.

@rmannibucau
Created October 25, 2013 15:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rmannibucau/7156354 to your computer and use it in GitHub Desktop.
Save rmannibucau/7156354 to your computer and use it in GitHub Desktop.
/*
* 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