Search in sources :

Example 1 with EzyExceptionHandlerProxy

use of com.tvd12.ezyfoxserver.support.reflect.EzyExceptionHandlerProxy in project ezyfox-server by youngmonkeys.

the class EzyExceptionHandlersImplementer method implement.

public Map<Class<?>, EzyUncaughtExceptionHandler> implement(Object exceptionHandler) {
    Map<Class<?>, EzyUncaughtExceptionHandler> handlers = new HashMap<>();
    EzyExceptionHandlerProxy proxy = new EzyExceptionHandlerProxy(exceptionHandler);
    for (EzyExceptionHandlerMethod method : proxy.getExceptionHandlerMethods()) {
        EzyExceptionHandlerImplementer implementer = newImplementer(proxy, method);
        EzyUncaughtExceptionHandler handler = implementer.implement();
        for (Class<?> exceptionClass : method.getExceptionClasses()) {
            handlers.put(exceptionClass, handler);
        }
    }
    return handlers;
}
Also used : EzyExceptionHandlerProxy(com.tvd12.ezyfoxserver.support.reflect.EzyExceptionHandlerProxy) HashMap(java.util.HashMap) EzyExceptionHandlerMethod(com.tvd12.ezyfoxserver.support.reflect.EzyExceptionHandlerMethod) EzyUncaughtExceptionHandler(com.tvd12.ezyfoxserver.support.handler.EzyUncaughtExceptionHandler)

Example 2 with EzyExceptionHandlerProxy

use of com.tvd12.ezyfoxserver.support.reflect.EzyExceptionHandlerProxy in project ezyfox-server by youngmonkeys.

the class EzyExceptionHandlerImplementerTest method testFailedCase.

@Test(expectedExceptions = IllegalStateException.class)
public void testFailedCase() throws Exception {
    EzyExceptionHandlerProxy handlerProxy = new EzyExceptionHandlerProxy(new ExceptionHandlerFail());
    EzyExceptionHandlerMethod method = new EzyExceptionHandlerMethod(new EzyMethod(ExceptionHandlerFail.class.getDeclaredMethod("handle", Exception.class, int.class)));
    new EzyExceptionHandlerImplementer(handlerProxy, method) {

        @SuppressWarnings("rawtypes")
        @Override
        protected EzyUncaughtExceptionHandler doImplement() {
            throw new IllegalStateException("test");
        }
    }.implement();
}
Also used : EzyExceptionHandlerImplementer(com.tvd12.ezyfoxserver.support.asm.EzyExceptionHandlerImplementer) EzyExceptionHandlerProxy(com.tvd12.ezyfoxserver.support.reflect.EzyExceptionHandlerProxy) EzyExceptionHandlerMethod(com.tvd12.ezyfoxserver.support.reflect.EzyExceptionHandlerMethod) EzyUncaughtExceptionHandler(com.tvd12.ezyfoxserver.support.handler.EzyUncaughtExceptionHandler) EzyMethod(com.tvd12.ezyfox.reflect.EzyMethod) Test(org.testng.annotations.Test)

Example 3 with EzyExceptionHandlerProxy

use of com.tvd12.ezyfoxserver.support.reflect.EzyExceptionHandlerProxy in project ezyfox-server by youngmonkeys.

the class EzyExceptionHandlerProxyTest method test.

@Test
public void test() {
    EzyExceptionHandlerProxy proxy = new EzyExceptionHandlerProxy(new ExceptionHandlerEx());
    System.out.println(proxy);
}
Also used : EzyExceptionHandlerProxy(com.tvd12.ezyfoxserver.support.reflect.EzyExceptionHandlerProxy) Test(org.testng.annotations.Test)

Aggregations

EzyExceptionHandlerProxy (com.tvd12.ezyfoxserver.support.reflect.EzyExceptionHandlerProxy)3 EzyUncaughtExceptionHandler (com.tvd12.ezyfoxserver.support.handler.EzyUncaughtExceptionHandler)2 EzyExceptionHandlerMethod (com.tvd12.ezyfoxserver.support.reflect.EzyExceptionHandlerMethod)2 Test (org.testng.annotations.Test)2 EzyMethod (com.tvd12.ezyfox.reflect.EzyMethod)1 EzyExceptionHandlerImplementer (com.tvd12.ezyfoxserver.support.asm.EzyExceptionHandlerImplementer)1 HashMap (java.util.HashMap)1