code: private void validate(Entity entity) {
      MailSettingsImpl mailSettings = new MailSettingsImpl(entity);
      if (mailSettings.isTestConnection()
          && mailSettings.getUsername() != null
          && mailSettings.getPassword() != null) {
        mailSenderFactory.validateConnection(mailSettings);
      }
    }
docs: Validates MailSettings.
  
  @param entity the MailSettings to validate