BLogicExecutorImpl implements BLogicExecutor { @SuppressWarnings("deprecation") @Override public BLogicResult execute(ApplicationContext applicationContext, BLogic blogic, BLogicParam blogicParam, ExceptionHandler exceptionHandler) { BLogicResult result = new BLogicResult(); try { LOGGER.debug(LogId.DAL025044, blogic.getClass().getName(), blogicParam); ThreadGroupApplicationContextHolder.setApplicationContext(applicationContext); int blogicStatus = blogic.execute(blogicParam); result.setBlogicStatus(blogicStatus); } catch (Throwable th) { result.setBlogicThrowable(th); if (exceptionHandler != null) { result.setBlogicStatus(exceptionHandler .handleThrowableException(th)); } else { LOGGER.error(LogId.EAL025057, th); } } finally { ThreadGroupApplicationContextHolder.removeApplicationContext(); } return result; }  @SuppressWarnings("deprecation") @Override BLogicResult execute(ApplicationContext applicationContext,
            BLogic blogic, BLogicParam blogicParam,
            ExceptionHandler exceptionHandler);  }
@Test public void testExecute01() throws Exception { when(blogic.execute(blogicParam)).thenReturn(0); BLogicResult result = target.execute(applicationContext, blogic, blogicParam, exceptionHandler); assertEquals(0, result.getBlogicStatus()); assertNull(result.getBlogicThrowable()); assertEquals(0, tga.size()); assertThat(logger.getLoggingEvents(), is(asList(debug( "[DAL025044] The BLogic detail is as follow. BLogic-class:" + blogic.getClass().getName() + ", " + blogicParam .toString())))); }
@Test public void testExecute02() throws Exception { RuntimeException re = new RuntimeException("test"); when(blogic.execute(blogicParam)).thenThrow(re); when(exceptionHandler.handleThrowableException(re)).thenReturn(100); BLogicResult result = target.execute(applicationContext, blogic, blogicParam, exceptionHandler); assertEquals(100, result.getBlogicStatus()); assertEquals(re, result.getBlogicThrowable()); assertEquals(0, tga.size()); assertThat(logger.getLoggingEvents(), is(asList(debug( "[DAL025044] The BLogic detail is as follow. BLogic-class:" + blogic.getClass().getName() + ", " + blogicParam .toString())))); }
@Test public void testExecute03() throws Exception { RuntimeException re = new RuntimeException("test"); when(blogic.execute(blogicParam)).thenThrow(re); BLogicResult result = target.execute(applicationContext, blogic, blogicParam, null); assertEquals(255, result.getBlogicStatus()); assertEquals(re, result.getBlogicThrowable()); assertEquals(0, tga.size()); assertThat(logger.getLoggingEvents(), is(asList( debug("[DAL025044] The BLogic detail is as follow. BLogic-class:" + blogic.getClass().getName() + ", " + blogicParam.toString()), error(re, "[EAL025057] An exception occurred at BLogic execution. This error log should be logged by the exception-handler, but the handler is not set.")))); }
@Test public void testExecute04() throws Exception { Error er = new Error("test"); when(blogic.execute(blogicParam)).thenThrow(er); BLogicResult result = target.execute(applicationContext, blogic, blogicParam, null); assertEquals(255, result.getBlogicStatus()); assertEquals(er, result.getBlogicThrowable()); assertEquals(0, tga.size()); assertThat(logger.getLoggingEvents(), is(asList( debug("[DAL025044] The BLogic detail is as follow. BLogic-class:" + blogic.getClass().getName() + ", " + blogicParam.toString()), error(er, "[EAL025057] An exception occurred at BLogic execution. This error log should be logged by the exception-handler, but the handler is not set.")))); }