@Test(expectedExceptions = ConflictException.class) public void shouldNotSendEmailIfInvocationThrowsException() throws Throwable { when(invocation.proceed()).thenThrow(new ConflictException("conflict")); when(invocation.getArguments()).thenReturn(new Object[] {null, "token123"}); interceptor.invoke(invocation); verifyZeroInteractions(notificationSender); }
@Override public Object invoke(MethodInvocation invocation) throws Throwable, ApiException { final String email = (String) invocation.getArguments()[0]; try { userManager.getByEmail(email); return invocation.proceed(); } catch (NotFoundException e) { } final Object proceed = invocation.proceed(); try { final User createdUser = (User) proceed; notificationSender.sendNotification(createdUser.getName(), createdUser.getEmail(), false); } catch (Exception e) { LOG.warn("Unable to send creation notification email", e); } return proceed; }
UserCreatorInterceptor implements MethodInterceptor { @Override public Object invoke(MethodInvocation invocation) throws Throwable, ApiException { final String email = (String) invocation.getArguments()[0]; try { userManager.getByEmail(email); return invocation.proceed(); } catch (NotFoundException e) { } final Object proceed = invocation.proceed(); try { final User createdUser = (User) proceed; notificationSender.sendNotification(createdUser.getName(), createdUser.getEmail(), false); } catch (Exception e) { LOG.warn("Unable to send creation notification email", e); } return proceed; } }
UserCreatorInterceptor implements MethodInterceptor { @Override public Object invoke(MethodInvocation invocation) throws Throwable, ApiException { final String email = (String) invocation.getArguments()[0]; try { userManager.getByEmail(email); return invocation.proceed(); } catch (NotFoundException e) { } final Object proceed = invocation.proceed(); try { final User createdUser = (User) proceed; notificationSender.sendNotification(createdUser.getName(), createdUser.getEmail(), false); } catch (Exception e) { LOG.warn("Unable to send creation notification email", e); } return proceed; }  }
UserCreatorInterceptor implements MethodInterceptor { @Override public Object invoke(MethodInvocation invocation) throws Throwable, ApiException { final String email = (String) invocation.getArguments()[0]; try { userManager.getByEmail(email); return invocation.proceed(); } catch (NotFoundException e) { } final Object proceed = invocation.proceed(); try { final User createdUser = (User) proceed; notificationSender.sendNotification(createdUser.getName(), createdUser.getEmail(), false); } catch (Exception e) { LOG.warn("Unable to send creation notification email", e); } return proceed; }  @Override Object invoke(MethodInvocation invocation); }
UserCreatorInterceptor implements MethodInterceptor { @Override public Object invoke(MethodInvocation invocation) throws Throwable, ApiException { final String email = (String) invocation.getArguments()[0]; try { userManager.getByEmail(email); return invocation.proceed(); } catch (NotFoundException e) { } final Object proceed = invocation.proceed(); try { final User createdUser = (User) proceed; notificationSender.sendNotification(createdUser.getName(), createdUser.getEmail(), false); } catch (Exception e) { LOG.warn("Unable to send creation notification email", e); } return proceed; }  @Override Object invoke(MethodInvocation invocation);  }