@Test public void proxyingOccurs() { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); ctx.register(AsyncConfig.class); ctx.refresh(); AsyncBean asyncBean = ctx.getBean(AsyncBean.class); assertThat(AopUtils.isAopProxy(asyncBean), is(true)); asyncBean.work(); }
@Test public void customExecutorIsPropagated() throws InterruptedException { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); ctx.register(CustomExecutorAsyncConfig.class); ctx.refresh(); AsyncBean asyncBean = ctx.getBean(AsyncBean.class); asyncBean.work(); Thread.sleep(500); assertThat(asyncBean.getThreadOfExecution().getName(), startsWith("Custom-")); TestableAsyncUncaughtExceptionHandler exceptionHandler = (TestableAsyncUncaughtExceptionHandler) ctx.getBean("exceptionHandler"); assertFalse("handler should not have been called yet", exceptionHandler.isCalled()); asyncBean.fail(); Thread.sleep(500); Method m = ReflectionUtils.findMethod(AsyncBean.class, "fail"); exceptionHandler.assertCalledWith(m, UnsupportedOperationException.class); ctx.close(); }