#65 Added AccountBuilder.addEmail method

pull/66/head
Dmitriy Dumanskiy 2018-07-29 17:34:08 +03:00
parent a0e481eedc
commit cbc202ea14
3 changed files with 39 additions and 0 deletions

View File

@ -303,6 +303,21 @@ public class Account extends AcmeJsonResource {
return this; return this;
} }
/**
* Adds a new Contact email to the account.
* <p>
* This is a convenience call for {@link #addContact(String)} hat doesn't
* require from you attach "mailto" scheme before email address.
*
* @param email
* Contact email without "mailto" scheme (e.g. test@gmail.com)
* @return itself
*/
public EditableAccount addEmail(String email) {
addContact("mailto:" + email);
return this;
}
/** /**
* Commits the changes and updates the account. * Commits the changes and updates the account.
*/ */

View File

@ -84,6 +84,23 @@ public class AccountBuilder {
return this; return this;
} }
/**
* Add a email address to the list of contacts.
* <p>
* This is a convenience call for {@link #addContact(String)} that doesn't
* require from you attach "mailto" scheme before email address.
*
* @param email
* Contact email without "mailto" scheme (e.g. test@gmail.com)
* @throws IllegalArgumentException
* if there is a syntax error in the URI string
* @return itself
*/
public AccountBuilder addEmail(String email) {
addContact("mailto:" + email);
return this;
}
/** /**
* Signals that the user agrees to the terms of service. * Signals that the user agrees to the terms of service.
* *

View File

@ -28,6 +28,7 @@ import org.jose4j.jws.JsonWebSignature;
import org.jose4j.jwx.CompactSerializer; import org.jose4j.jwx.CompactSerializer;
import org.jose4j.lang.JoseException; import org.jose4j.lang.JoseException;
import org.junit.Test; import org.junit.Test;
import org.mockito.Mockito;
import org.shredzone.acme4j.connector.Resource; import org.shredzone.acme4j.connector.Resource;
import org.shredzone.acme4j.provider.TestableConnectionProvider; import org.shredzone.acme4j.provider.TestableConnectionProvider;
import org.shredzone.acme4j.toolbox.AcmeUtils; import org.shredzone.acme4j.toolbox.AcmeUtils;
@ -220,4 +221,10 @@ public class AccountBuilderTest {
provider.close(); provider.close();
} }
@Test
public void testEmailAddresses() {
AccountBuilder builder = Mockito.spy(AccountBuilder.class);
builder.addEmail("foo@example.com");
Mockito.verify(builder).addContact(Mockito.eq("mailto:foo@example.com"));
}
} }