@Test
  public void doResolveWhenNotUsingFastResolution() throws Exception {

    final MailAddressResolver resolver = mockResolver();
    PowerMockito.when(resolver.findMailAddressFor(user)).thenReturn("[email protected]");

    configure(resolver);

    final String address = MailAddressResolver.resolve(user);

    verify(resolver, times(1)).findMailAddressFor(user);

    assertEquals("[email protected]", address);
  }
Пример #2
0
    @Exported
    public String getAddress() {
      if (emailAddress != null) return emailAddress;

      // try the inference logic
      return MailAddressResolver.resolve(user);
    }
  /**
   * Try to resolve email address using resolvers.
   *
   * @return User address or null if resolution failed
   */
  public static String resolve(User u) {
    if (LOGGER.isLoggable(Level.FINE)) {
      LOGGER.fine("Resolving e-mail address for \"" + u + "\" ID=" + u.getId());
    }

    for (MailAddressResolver r : all()) {
      String email = r.findMailAddressFor(u);
      if (email != null) {
        if (LOGGER.isLoggable(Level.FINE)) {
          LOGGER.fine(r + " resolved " + u.getId() + " to " + email);
        }
        return email;
      }
    }

    // fall back logic
    return resolveFast(u);
  }
  @Test
  public void doResolveWhenUsingExplicitlUserEmail() {
    final String testEmail = "*****@*****.**";

    when(user.getProperty(Mailer.UserProperty.class))
        .thenReturn(new Mailer.UserProperty(testEmail));

    final String address = MailAddressResolver.resolveFast(user);
    assertEquals(testEmail, address);
  }
  @Test
  public void doNotResolveWhenUsingFastResolution() throws Exception {

    final MailAddressResolver resolver = mockResolver();

    configure(resolver);

    final String address = MailAddressResolver.resolveFast(user);

    verify(resolver, never()).findMailAddressFor(user);

    assertNull(address);
  }