@Test public void shouldNotSendEmailWhenUserCreatorProvideExistingUser() throws Throwable { final Method method = UserCreator.class.getMethod( "createUser", String.class, String.class, String.class, String.class); when(invocation.getMethod()).thenReturn(method); when(invocation.proceed()).thenReturn(user); when(user.getEmail()).thenReturn(recipient); when(user.getName()).thenReturn("user123"); when(invocation.getArguments()).thenReturn(new Object[] {recipient}); interceptor.invoke(invocation); verify(notificationSender, never()).sendNotification(any(), anyString(), anyBoolean()); }
@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);  }