ResultMessagesLoggingInterceptor implements MethodInterceptor,
                                              InitializingBean { @Override public Object invoke( MethodInvocation invocation) throws Throwable, ResultMessagesNotificationException { if (startingPoint.get() == null) { startingPoint.set(invocation); } try { return invocation.proceed(); } catch (ResultMessagesNotificationException e) { if (isStartingPoint(invocation)) { logResultMessagesNotificationException(e); } throw e; } finally { if (isStartingPoint(invocation)) { startingPoint.remove(); } } }  void setExceptionLogger(ExceptionLogger exceptionLogger); @Override Object invoke(
            MethodInvocation invocation); @Override void afterPropertiesSet();  }
@Test public void testInvoke_not_occur_exception() throws Throwable { testTarget.invoke(mockMethodInvocation); verify(mockMethodInvocation, times(1)).proceed(); verify(mockExceptionLogger, never()).warn((Exception) any()); }
@Test public void testInvokeOccurBusinessexception01() throws Throwable { BusinessException occurException = new BusinessException("testing businessexception"); when(mockMethodInvocation.proceed()).thenThrow(occurException); try { testTarget.invoke(mockMethodInvocation); fail("didn't occured BusinessException."); } catch (BusinessException e) { assertThat(e, is(occurException)); verify(mockExceptionLogger, times(1)).warn(occurException); verify(mockExceptionLogger, times(1)).warn(any(Exception.class)); } }
@Test public void testInvokeOccurBusinessexception02() throws Throwable { BusinessException occurException = new BusinessException(ResultMessages .error().add("e.cm.xxx1", "args1", "args2")); when(mockMethodInvocation.proceed()).thenThrow(occurException); try { testTarget.invoke(mockMethodInvocation); fail("don't occur BusinessException."); } catch (BusinessException e) { assertThat(e, is(occurException)); verify(mockExceptionLogger, times(1)).warn(occurException); verify(mockExceptionLogger, times(1)).warn(any(Exception.class)); } }
@Test public void testInvokeOccurBusinessexception03() throws Throwable { BusinessException occurException = new BusinessException(ResultMessages .error().add("e.cm.xxx1", "args1", "args2"), null); when(mockMethodInvocation.proceed()).thenThrow(occurException); try { testTarget.invoke(mockMethodInvocation); fail("don't occur BusinessException."); } catch (BusinessException e) { assertThat(e, is(occurException)); verify(mockExceptionLogger, times(1)).warn(occurException); verify(mockExceptionLogger, times(1)).warn(any(Exception.class)); } }
@Test public void testInvoke_occur_other_exception() throws Throwable { NullPointerException occurException = new NullPointerException("testInvoke_occur_other_exception"); when(mockMethodInvocation.proceed()).thenThrow(occurException); try { testTarget.invoke(mockMethodInvocation); fail("don't occur NullPointerException."); } catch (NullPointerException e) { assertThat(e, is(occurException)); verify(mockExceptionLogger, never()).warn(any(Exception.class)); } }
@Test public void testInvoke_multi_times_on_same_thread() throws Throwable { BusinessException occurException = new BusinessException(ResultMessages .error().add("e.cm.xxx1", "args1", "args2")); when(mockMethodInvocation.proceed()).thenThrow(occurException); try { testTarget.invoke(mockMethodInvocation); fail("don't occur BusinessException."); } catch (BusinessException e) { assertThat(e, is(occurException)); } try { testTarget.invoke(mockMethodInvocation); fail("don't occur BusinessException."); } catch (BusinessException e) { assertThat(e, is(occurException)); } verify(mockExceptionLogger, times(2)).warn(occurException); verify(mockExceptionLogger, times(2)).warn(any(Exception.class)); }