Created
December 4, 2012 05:33
-
-
Save margusmartsepp/4200986 to your computer and use it in GitHub Desktop.
builder
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static class AccountBuilder { | |
| String firstName; | |
| String surname; | |
| String username; | |
| String password; | |
| String phone; | |
| @Override | |
| public String toString() { | |
| return "AccountBuilder [firstName=" + firstName + ", Surname=" | |
| + surname + ", username=" + username + ", password=" | |
| + password + ", phone=" + phone + "]"; | |
| } | |
| public static AccountBuilder Default() { | |
| return new AccountBuilder().FirstName("Laura").Surname("Laura") | |
| .Username("Username1").Password("mari-liis89") | |
| .Phone("55965555"); | |
| } | |
| public AccountBuilder FirstName(String firstName) { | |
| this.firstName = firstName; | |
| return this; | |
| } | |
| public AccountBuilder Surname(String surname) { | |
| this.surname = surname; | |
| return this; | |
| } | |
| public AccountBuilder Username(String username) { | |
| this.username = username; | |
| return this; | |
| } | |
| public AccountBuilder Password(String password) { | |
| this.password = password; | |
| return this; | |
| } | |
| public AccountBuilder Phone(String phone) { | |
| this.phone = phone; | |
| return this; | |
| } | |
| public CreateAccount build() { | |
| return new CreateAccount(firstName, surname, username, password, | |
| phone); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Test | |
| public void testCreateAccount_default() throws Exception { | |
| CreateAccount.AccountBuilder.Default().build(); | |
| } | |
| @Test | |
| public void testCreateAccount_FirstName_pass_0() throws Exception { | |
| CreateAccount.AccountBuilder.Default().FirstName(Firstnames_pass[0]).build(); | |
| } | |
| @Test(expected = Exception.class) | |
| public void testCreateAccount_FirstName_fail_0() throws Exception { | |
| CreateAccount.AccountBuilder.Default().FirstName(Firstnames_fail[0]).build(); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private CreateAccount(String firstName, String surname, String username, String password, String phone) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static String[] Firstnames_pass = new String[] { | |
| new String(new char[1]).replace('\0', 'x'), | |
| new String(new char[2]).replace('\0', 'x'), | |
| new String(new char[15]).replace('\0', 'x'), | |
| new String(new char[16]).replace('\0', 'x'), "Laura" }; | |
| public static String[] Firstnames_fail = new String[] { null, "", | |
| new String(new char[17]).replace('\0', 'x'), "Laura8", "Laura*" }; | |
| public static String[] Surnames_pass = Firstnames_pass; | |
| public static String[] Surnames_fail = Firstnames_fail; | |
| public static String[] Usernames_pass = new String[] { | |
| new String(new char[1]).replace('\0', 'x'), | |
| new String(new char[2]).replace('\0', 'x'), | |
| new String(new char[15]).replace('\0', 'x'), | |
| new String(new char[16]).replace('\0', 'x'), "1", "x1", "x*", "x*1" }; | |
| public static String[] Usernames_fail = new String[] { null, "", | |
| new String(new char[17]).replace('\0', 'x'), | |
| new String(new char[17]).replace('\0', '1'), "1*", "*" }; | |
| public static String[] Passwords_pass = new String[] { | |
| new String(new char[4]).replace('\0', 'x'), | |
| new String(new char[5]).replace('\0', 'x'), | |
| new String(new char[15]).replace('\0', 'x'), | |
| new String(new char[16]).replace('\0', 'x'), "1111", "x111", | |
| "x***", "x**1" }; | |
| public static String[] Passwords_fail = new String[] { null, "", | |
| new String(new char[3]).replace('\0', 'x'), | |
| new String(new char[17]).replace('\0', 'x'), | |
| new String(new char[17]).replace('\0', '1'), "1*", "*" }; | |
| public static String[] Phones_pass = new String[] { | |
| new String(new char[3]).replace('\0', '1'), | |
| new String(new char[4]).replace('\0', '1'), | |
| new String(new char[19]).replace('\0', '1'), | |
| new String(new char[20]).replace('\0', '1') }; | |
| public static String[] Phones_fail = new String[] { null, "", | |
| new String(new char[3]).replace('\0', '1') + "x", | |
| new String(new char[3]).replace('\0', '1') + "*", | |
| new String(new char[3]).replace('\0', '*'), | |
| new String(new char[3]).replace('\0', 'x') }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Assert.assertTrue(Pattern.compile("[a-zA-Z]{1,16}").matcher(firstName).matches()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment