Skip to content

Commit ff5cdf7

Browse files
enzozafraEnzo Zafra
authored andcommitted
add tests for Address and BankAccount models
1 parent 8889c3a commit ff5cdf7

File tree

2 files changed

+192
-4
lines changed

2 files changed

+192
-4
lines changed
Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
package com.intuit.payment.data;
22

3+
import org.apache.commons.lang.builder.ReflectionToStringBuilder;
34
import org.testng.Assert;
5+
import org.testng.annotations.BeforeMethod;
46
import org.testng.annotations.BeforeTest;
57
import org.testng.annotations.Test;
68

79
/**
8-
* @author k-arjun
10+
* @author k-arjun, enzozafra
911
*/
1012
public class AddressTest {
1113
private String streetAddress;
1214
private String city;
1315
private String region;
1416
private String country;
1517
private String postalCode;
18+
private Address address;
1619

1720
@BeforeTest
1821
public void init() {
@@ -23,20 +26,53 @@ public void init() {
2326
postalCode = "12345";
2427
}
2528

26-
@Test
27-
public void testAllGetters() {
28-
Address address = new Address.Builder()
29+
@BeforeMethod
30+
public void setUp() {
31+
address = new Address.Builder()
2932
.streetAddress(streetAddress)
3033
.city(city)
3134
.region(region)
3235
.country(country)
3336
.postalCode(postalCode)
3437
.build();
3538

39+
}
40+
41+
@Test
42+
public void testAllGetters() {
3643
Assert.assertEquals(address.getStreetAddress(), streetAddress);
3744
Assert.assertEquals(address.getCity(), city);
3845
Assert.assertEquals(address.getRegion(), region);
3946
Assert.assertEquals(address.getCountry(), country);
4047
Assert.assertEquals(address.getPostalCode(), postalCode);
4148
}
49+
50+
@Test
51+
public void testAllSetters() {
52+
String newStreetAddress = "321 New Street Address";
53+
String newCity = "New City";
54+
String newRegion = "New Region";
55+
String newCountry = "New Country";
56+
String newPostalCode = "54321";
57+
58+
address.setStreetAddress(newStreetAddress);
59+
address.setCity(newCity);
60+
address.setRegion(newRegion);
61+
address.setCountry(newCountry);
62+
address.setPostalCode(newPostalCode);
63+
64+
Assert.assertEquals(address.getStreetAddress(), newStreetAddress);
65+
Assert.assertEquals(address.getCity(), newCity);
66+
Assert.assertEquals(address.getRegion(), newRegion);
67+
Assert.assertEquals(address.getCountry(), newCountry);
68+
Assert.assertEquals(address.getPostalCode(), newPostalCode);
69+
}
70+
71+
@Test
72+
public void testToString() {
73+
// Since we cant mock ReflectionToStringBuilder without powermock, just check if it includes below
74+
String expectedResult = ReflectionToStringBuilder.toString(address);
75+
String actualResult = address.toString();
76+
Assert.assertTrue(actualResult.contains(expectedResult));
77+
}
4278
}
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
package com.intuit.payment.data;
2+
3+
import org.apache.commons.lang.builder.ReflectionToStringBuilder;
4+
import org.testng.Assert;
5+
import org.testng.annotations.BeforeMethod;
6+
import org.testng.annotations.BeforeTest;
7+
import org.testng.annotations.Test;
8+
9+
import java.util.Date;
10+
import com.intuit.payment.data.BankAccount.BankAccountInputTypeEnum;
11+
import com.intuit.payment.data.BankAccount.AccountType;
12+
13+
/**
14+
* @author enzozafra
15+
*/
16+
public class BankAccountTest {
17+
private String id;
18+
private String name;
19+
private Date created;
20+
private Date updated;
21+
private BankAccountInputTypeEnum inputType;
22+
private String routingNumber;
23+
private String accountNumber;
24+
private AccountType accountType;
25+
private String phone;
26+
private Boolean defaultValue;
27+
private String country;
28+
private String bankCode;
29+
private String entityId;
30+
private String entityType;
31+
private String entityVersion;
32+
33+
private BankAccount bankAccount;
34+
35+
@BeforeTest
36+
public void init() {
37+
id = "id";
38+
name = "name";
39+
created = new Date(1220227200);
40+
updated = new Date(1220832000);
41+
inputType = BankAccountInputTypeEnum.KEYED;
42+
routingNumber = "12311";
43+
accountNumber = "123123123";
44+
accountType = AccountType.PERSONAL_CHECKING;
45+
phone = "5871231234";
46+
defaultValue = true;
47+
country = "country";
48+
bankCode = "1221";
49+
entityId = "entityId";
50+
entityType = "entityType";
51+
entityVersion = "entityVersion";
52+
}
53+
54+
@BeforeMethod
55+
public void setUp() {
56+
bankAccount = new BankAccount.Builder()
57+
.id(id)
58+
.name(name)
59+
.created(created)
60+
.updated(updated)
61+
.inputType(inputType)
62+
.routingNumber(routingNumber)
63+
.accountNumber(accountNumber)
64+
.accountType(accountType)
65+
.phone(phone)
66+
.defaultValue(defaultValue)
67+
.country(country)
68+
.bankCode(bankCode)
69+
.entityId(entityId)
70+
.entityType(entityType)
71+
.entityVersion(entityVersion)
72+
.build();
73+
74+
}
75+
76+
@Test
77+
public void testAllGetters() {
78+
Assert.assertEquals(bankAccount.getId(), id);
79+
Assert.assertEquals(bankAccount.getName(), name);
80+
Assert.assertEquals(bankAccount.getCreated(), created);
81+
Assert.assertEquals(bankAccount.getUpdated(), updated);
82+
Assert.assertEquals(bankAccount.getInputType(), inputType);
83+
Assert.assertEquals(bankAccount.getRoutingNumber(), routingNumber);
84+
Assert.assertEquals(bankAccount.getAccountNumber(), accountNumber);
85+
Assert.assertEquals(bankAccount.getPhone(), phone);
86+
Assert.assertEquals(bankAccount.getDefaultValue(), defaultValue);
87+
Assert.assertEquals(bankAccount.getCountry(), country);
88+
Assert.assertEquals(bankAccount.getBankCode(), bankCode);
89+
Assert.assertEquals(bankAccount.getEntityId(), entityId);
90+
Assert.assertEquals(bankAccount.getEntityType(), entityType);
91+
Assert.assertEquals(bankAccount.getEntityVersion(), entityVersion);
92+
}
93+
94+
@Test
95+
public void testAllSetters() {
96+
String newId = "new id";
97+
String newName = "new name";
98+
Date newCreated = new Date(1220832000);
99+
Date newUpdated = new Date(1220227200);
100+
// set to null because there is no second option
101+
BankAccountInputTypeEnum newInputType = null;
102+
String newRoutingNumber = "11321";
103+
String newAccountNumber = "45655623";
104+
AccountType newAccountType = AccountType.PERSONAL_SAVINGS;
105+
String newPhone = "1231231231";
106+
Boolean newDefaultValue = false;
107+
String newCountry = "new country";
108+
String newBankCode = "1234";
109+
String newEntityId = "new entityId";
110+
String newEntityType = "new entityType";
111+
String newEntityVersion = "new entityVersion";
112+
113+
bankAccount.setId(newId);
114+
bankAccount.setName(newName);
115+
bankAccount.setCreated(newCreated);
116+
bankAccount.setUpdated(newUpdated);
117+
bankAccount.setInputType(newInputType);
118+
bankAccount.setRoutingNumber(newRoutingNumber);
119+
bankAccount.setAccountNumber(newAccountNumber);
120+
bankAccount.setAccountType(newAccountType);
121+
bankAccount.setPhone(newPhone);
122+
bankAccount.setDefaultValue(newDefaultValue);
123+
bankAccount.setCountry(newCountry);
124+
bankAccount.setBankCode(newBankCode);
125+
bankAccount.setEntityId(newEntityId);
126+
bankAccount.setEntityType(newEntityType);
127+
bankAccount.setEntityVersion(newEntityVersion);
128+
129+
Assert.assertEquals(bankAccount.getId(), newId);
130+
Assert.assertEquals(bankAccount.getName(), newName);
131+
Assert.assertEquals(bankAccount.getCreated(), newCreated);
132+
Assert.assertEquals(bankAccount.getUpdated(), newUpdated);
133+
Assert.assertEquals(bankAccount.getInputType(), newInputType);
134+
Assert.assertEquals(bankAccount.getRoutingNumber(), newRoutingNumber);
135+
Assert.assertEquals(bankAccount.getAccountNumber(), newAccountNumber);
136+
Assert.assertEquals(bankAccount.getPhone(), newPhone);
137+
Assert.assertEquals(bankAccount.getDefaultValue(), newDefaultValue);
138+
Assert.assertEquals(bankAccount.getCountry(), newCountry);
139+
Assert.assertEquals(bankAccount.getBankCode(), newBankCode);
140+
Assert.assertEquals(bankAccount.getEntityId(), newEntityId);
141+
Assert.assertEquals(bankAccount.getEntityType(), newEntityType);
142+
Assert.assertEquals(bankAccount.getEntityVersion(), newEntityVersion);
143+
}
144+
145+
@Test
146+
public void testToString() {
147+
// Since we cant mock ReflectionToStringBuilder without powermock
148+
String expectedResult = ReflectionToStringBuilder.toString(bankAccount);
149+
String actualResult = bankAccount.toString();
150+
Assert.assertTrue(actualResult.contains(expectedResult));
151+
}
152+
}

0 commit comments

Comments
 (0)