-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathBetaRateTest.java
More file actions
72 lines (56 loc) · 2.3 KB
/
BetaRateTest.java
File metadata and controls
72 lines (56 loc) · 2.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
package com.easypost;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import com.easypost.exception.EasyPostException;
import com.easypost.model.StatelessRate;
import com.easypost.utils.Utilities;
public class BetaRateTest {
private static TestUtils.VCR vcr;
/**
* Set up the testing environment for this file.
*
* @throws EasyPostException when the request fails.
*/
@BeforeAll
public static void setup() throws EasyPostException {
vcr = new TestUtils.VCR("beta_stateless_rate", TestUtils.ApiKey.TEST);
}
/**
* Test retrieving stateless rates.
*
* @throws EasyPostException when the request fails.
*/
@Test
public void testRetrieveStatelessRates() throws EasyPostException {
vcr.setUpTest("retrieve_stateless_rates");
HashMap<String, Object> shipment = Fixtures.basicShipment();
List<StatelessRate> rates = vcr.client.betaRate.retrieveStatelessRates(shipment);
// Test that deserialization worked by accessing a field with an underscore
for (StatelessRate rate : rates) {
assertTrue(rate.getListRate() != null);
}
}
/**
* Test retrieving the lowest rate of stateless rate.
*
* @throws EasyPostException when the request fails.
*/
@Test
public void testRetrieveLowestStatelessRate() throws EasyPostException {
vcr.setUpTest("retrieve_lowest_stateless_rate");
HashMap<String, Object> shipment = Fixtures.basicShipment();
List<StatelessRate> rates = vcr.client.betaRate.retrieveStatelessRates(shipment);
StatelessRate lowestRate = Utilities.getLowestStatelessRate(rates, null, null);
assertEquals("GroundAdvantage", lowestRate.getService());
List<String> carriers = Arrays.asList("invalidCarrierName");
EasyPostException exception = assertThrows(EasyPostException.class,
() -> Utilities.getLowestStatelessRate(rates, carriers, null));
assertEquals("No rates found.", exception.getMessage());
}
}