-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathBankAccountsApiTest.java
More file actions
executable file
·227 lines (171 loc) · 10.3 KB
/
Copy pathBankAccountsApiTest.java
File metadata and controls
executable file
·227 lines (171 loc) · 10.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
package Api;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.time.OffsetDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import com.lob.api.ApiException;
import com.lob.api.client.BankAccountsApi;
import com.lob.model.BankAccount;
import com.lob.model.BankAccountDeletion;
import com.lob.model.BankAccountList;
import com.lob.model.BankAccountVerify;
import com.lob.model.BankAccountWritable;
import org.testng.Assert;
import org.testng.annotations.Test;
@Test(enabled=true, groups={"Unit", "Billing", "Bank Account"})
public class BankAccountsApiTest {
@Test(enabled=true, groups={"Unit", "Create", "Bank Account", "Valid"})
public void bankAccountCreateTest() throws ApiException {
BankAccountsApi bankAccountsApiMock = mock(BankAccountsApi.class);
BankAccount fakeAccount = new BankAccount();
BankAccountWritable bankAccountWritable = new BankAccountWritable();
fakeAccount.setId("bank_fakeId");
when(bankAccountsApiMock.create(bankAccountWritable)).thenReturn(fakeAccount);
BankAccount response = bankAccountsApiMock.create(bankAccountWritable);
Assert.assertEquals(fakeAccount.getId(), response.getId());
}
@Test(enabled=true, groups={"Unit", "Create", "Bank Account", "Invalid"}, expectedExceptions = {ApiException.class}, expectedExceptionsMessageRegExp = "error reported by API")
public void bankAccountCreateTestCatchesException() throws ApiException {
BankAccountsApi bankAccountsApiMock = mock(BankAccountsApi.class);
ApiException error = new ApiException("error reported by API");
when(bankAccountsApiMock.create(null)).thenThrow(error);
bankAccountsApiMock.create(null);
Assert.fail("This should not happen");
}
@Test(enabled=true, groups={"Unit", "Create", "Bank Account", "Invalid"}, expectedExceptions = {ApiException.class})
public void bankAccountCreateTestCatchesExceptionWithResponseBody() throws ApiException {
BankAccountsApi bankAccountsApiMock = mock(BankAccountsApi.class);
ApiException error = new ApiException("error", null, 500, null, "error reported by API");
when(bankAccountsApiMock.create(null)).thenThrow(error);
bankAccountsApiMock.create(null);
Assert.fail("This should not happen");
}
@Test(enabled=true, groups={"Unit", "Delete", "Bank Account", "Valid"})
public void bankAccountDeleteTest() throws ApiException {
BankAccountsApi bankAccountsApiMock = mock(BankAccountsApi.class);
BankAccountDeletion fakeAccount = new BankAccountDeletion();
fakeAccount.setId("bank_fakeId");
when(bankAccountsApiMock.delete("bank_fakeId")).thenReturn(fakeAccount);
BankAccountDeletion response = bankAccountsApiMock.delete("bank_fakeId");
Assert.assertEquals(fakeAccount.getId(), response.getId());
}
@Test(enabled=true, groups={"Unit", "Delete", "Bank Account", "Invalid"}, expectedExceptions = {ApiException.class}, expectedExceptionsMessageRegExp = "error reported by API")
public void bankAccountDeleteTestCatchesException() throws ApiException {
BankAccountsApi bankAccountsApiMock = mock(BankAccountsApi.class);
ApiException error = new ApiException("error reported by API");
when(bankAccountsApiMock.delete(null)).thenThrow(error);
bankAccountsApiMock.delete(null);
Assert.fail("This should not happen");
}
@Test(enabled=true, groups={"Unit", "Delete", "Bank Account", "Invalid"}, expectedExceptions = {ApiException.class})
public void bankAccountDeleteTestCatchesExceptionWithResponseBody() throws ApiException {
BankAccountsApi bankAccountsApiMock = mock(BankAccountsApi.class);
ApiException error = new ApiException("error", null, 500, null, "error reported by API");
when(bankAccountsApiMock.delete(null)).thenThrow(error);
bankAccountsApiMock.delete(null);
Assert.fail("This should not happen");
}
@Test(enabled=true, groups={"Unit", "Get", "Bank Account", "Valid"})
public void BankAccountGetTest() throws ApiException {
BankAccountsApi BankAccountApiMock = mock(BankAccountsApi.class);
BankAccount fakeBankAccount = new BankAccount();
fakeBankAccount.setId("bank_Id");
when(BankAccountApiMock.get("bank_Id")).thenReturn(fakeBankAccount);
BankAccount response = BankAccountApiMock.get("bank_Id");
Assert.assertEquals(fakeBankAccount.getId(), response.getId());
}
@Test(enabled=true, groups={"Unit", "Get", "Bank Account", "Invalid"}, expectedExceptions = {ApiException.class}, expectedExceptionsMessageRegExp = "error reported by API")
public void bankAccountGetTestCatchesException() throws ApiException {
BankAccountsApi BankAccountApiMock = mock(BankAccountsApi.class);
ApiException error = new ApiException("error reported by API");
when(BankAccountApiMock.get(null)).thenThrow(error);
BankAccountApiMock.get(null);
Assert.fail("This should not happen");
}
@Test(enabled=true, groups={"Unit", "Get", "Bank Account", "Invalid"}, expectedExceptions = {ApiException.class})
public void bankAccountGetTestCatchesExceptionWithResponseBody() throws ApiException {
BankAccountsApi BankAccountApiMock = mock(BankAccountsApi.class);
ApiException error = new ApiException("error", null, 500, null, "error reported by API");
when(BankAccountApiMock.get(null)).thenThrow(error);
BankAccountApiMock.get(null);
Assert.fail("This should not happen");
}
@Test(enabled=false, groups={"Unit", "Verify", "Bank Account", "Valid"})
public void bankAccountVerifyTest() throws ApiException {
BankAccountsApi bankAccountsApiMock = mock(BankAccountsApi.class);
BankAccount FakeBankAccount = new BankAccount();
BankAccountVerify bankAccountVerify = new BankAccountVerify();
List<Integer> amounts = new ArrayList<Integer>();
FakeBankAccount.setId("bank_fakeId");
amounts.add(1);
amounts.add(2);
bankAccountVerify.setAmounts(amounts);
when(bankAccountsApiMock.verify("bank_fakeId", bankAccountVerify)).thenReturn(FakeBankAccount);
BankAccount response = bankAccountsApiMock.verify("bank_fakeId", bankAccountVerify);
Assert.assertEquals(FakeBankAccount.getId(), response.getId());
}
@Test(enabled=true, groups={"Unit", "Verify", "Bank Account", "Valid"})
public void bankAccountVerifyWithDescriptorCodeTest() throws ApiException {
BankAccountsApi bankAccountsApiMock = mock(BankAccountsApi.class);
BankAccount fakeBankAccount = new BankAccount();
BankAccountVerify bankAccountVerify = new BankAccountVerify();
fakeBankAccount.setId("bank_fakeId");
bankAccountVerify.setDescriptorCode("SM11AA");
when(bankAccountsApiMock.verify("bank_fakeId", bankAccountVerify)).thenReturn(fakeBankAccount);
BankAccount response = bankAccountsApiMock.verify("bank_fakeId", bankAccountVerify);
Assert.assertEquals(fakeBankAccount.getId(), response.getId());
}
@Test(enabled=true, groups={"Unit", "Bank Account", "Valid"})
public void bankAccountHasMicrodepositTypeTest() throws ApiException {
BankAccount account = new BankAccount();
account.setId("bank_fakeId");
account.setMicrodepositType("amounts");
Assert.assertEquals(account.getMicrodepositType(), "amounts");
account.setMicrodepositType("descriptor_code");
Assert.assertEquals(account.getMicrodepositType(), "descriptor_code");
account.setMicrodepositType(null);
Assert.assertNull(account.getMicrodepositType());
}
@Test(enabled=true, groups={"Unit", "List", "Bank Account", "Valid"})
public void bankAccountsListTest() throws ApiException {
Integer limit = 2;
String before = null;
String after = null;
List<String> include = null;
Map<String, OffsetDateTime> dateCreated = null;
Map<String, String> metadata = null;
BankAccountsApi bankAccountsApiMock = mock(BankAccountsApi.class);
BankAccountList fakeBankAccount = new BankAccountList();
BankAccount data1 = new BankAccount();
BankAccount data2 = new BankAccount();
List<BankAccount> data = new ArrayList<BankAccount>();
data1.setId("bank_Id");
data2.setId("bank_Id2");
data.add(data1);
data.add(data2);
fakeBankAccount.setData(data);
fakeBankAccount.setObject("list");
fakeBankAccount.setCount(data.size());
when(bankAccountsApiMock.list(limit, before, after, include, dateCreated, metadata)).thenReturn(fakeBankAccount);
BankAccountList response = bankAccountsApiMock.list(limit, before, after, include, dateCreated, metadata);
Assert.assertEquals(fakeBankAccount.getCount(), response.getCount());
}
@Test(enabled=true, groups={"Unit", "List", "Bank Account", "Invalid"}, expectedExceptions = {ApiException.class}, expectedExceptionsMessageRegExp = "error reported by API")
public void bankAccountListTestCatchesException() throws ApiException {
BankAccountsApi bankAccountsApiMock = mock(BankAccountsApi.class);
ApiException error = new ApiException("error reported by API");
when(bankAccountsApiMock.list(null, null, null, null, null, null)).thenThrow(error);
bankAccountsApiMock.list(null, null, null, null, null, null);
Assert.fail("This should not happen");
}
@Test(enabled=true, groups={"Unit", "List", "Bank Account", "Invalid"}, expectedExceptions = {ApiException.class})
public void bankAccountListTestCatchesExceptionWithResponseBody() throws ApiException {
BankAccountsApi bankAccountsApiMock = mock(BankAccountsApi.class);
ApiException error = new ApiException("error", null, 500, null, "error reported by API");
when(bankAccountsApiMock.list(null, null, null, null, null, null)).thenThrow(error);
bankAccountsApiMock.list(null, null, null, null, null, null);
Assert.fail("This should not happen");
}
}