-
Notifications
You must be signed in to change notification settings - Fork 39
/
RefundTest.java
98 lines (79 loc) · 3.47 KB
/
RefundTest.java
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
package com.shippo.model;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import java.util.HashMap;
import java.util.Map;
import com.shippo.Shippo;
import com.shippo.exception.APIConnectionException;
import com.shippo.exception.APIException;
import com.shippo.exception.AuthenticationException;
import com.shippo.exception.DuplicateRefundRequestException;
import com.shippo.exception.InvalidRequestException;
import com.shippo.exception.ShippoException;
import org.junit.Test;
public class RefundTest extends ShippoTest {
@Test
public void testValidCreate() {
Refund testObject = createRefundFixture();
assertEquals("QUEUED", testObject.getStatus());
assertEquals(Shippo.apiKeyIsTest, testObject.isTest());
}
@Test(expected = DuplicateRefundRequestException.class)
public void testDoubleRefundRequest() throws ShippoException {
// GIVEN a transaction
Transaction transaction = TransactionTest.createTransactionFixture();
// AND a refund has already been requested for that transaction
Map<String, Object> objectMap = new HashMap<String, Object>();
objectMap.put("transaction", transaction.getObjectId());
Refund refund1 = Refund.create(objectMap);
// WHEN request another refund for same transaction
Refund refund2 = Refund.create(objectMap);
// THEN should get informative exception
}
@Test(expected = InvalidRequestException.class)
public void testInvalidCreate() throws AuthenticationException, InvalidRequestException, APIConnectionException,
APIException {
Refund.create(getInvalidObjectMap());
}
@Test
public void testRetrieve() throws AuthenticationException,
InvalidRequestException, APIConnectionException,
APIException {
Refund testObject = createRefundFixture();
Refund retrievedObject;
retrievedObject = Refund.retrieve((String) testObject.object_id);
assertEquals(testObject.object_id, retrievedObject.object_id);
}
@Test(expected = InvalidRequestException.class)
public void testInvalidRetrieve() throws AuthenticationException, InvalidRequestException, APIConnectionException,
APIException {
Refund.retrieve("invalid_id");
}
@Test
public void testListAll() throws AuthenticationException, InvalidRequestException, APIConnectionException,
APIException {
RefundCollection objectCollection = Refund.all(null);
assertNotNull(objectCollection.getData());
}
@Test
public void testListPageSize() throws AuthenticationException,
InvalidRequestException, APIConnectionException,
APIException {
Map<String, Object> objectMap = new HashMap<String, Object>();
objectMap.put("results", "1"); // one result per page
objectMap.put("page", "1"); // the first page of results
RefundCollection RefundCollection = Refund.all(objectMap);
assertEquals(RefundCollection.getData().size(), 1);
}
public static Refund createRefundFixture() {
Map<String, Object> objectMap = new HashMap<String, Object>();
Transaction transaction = TransactionTest.createTransactionFixture();
objectMap.put("transaction", transaction.getObjectId());
try {
return Refund.create(objectMap);
} catch (ShippoException e) {
e.printStackTrace();
}
return null;
}
}