-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathExchangeRateTest.java
153 lines (133 loc) · 5.09 KB
/
ExchangeRateTest.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
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
package ni.jug.exchangerate;
import ni.jug.exchangerate.bank.Bank;
import ni.jug.exchangerate.bank.BankExchangeRateSummary;
import ni.jug.exchangerate.bank.BankScraper;
import ni.jug.exchangerate.bank.ExchangeRateTrade;
import ni.jug.exchangerate.centralbank.MonthlyExchangeRate;
import org.junit.jupiter.api.Test;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.Month;
import java.time.YearMonth;
import java.util.List;
import java.util.Map;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
/**
* @author aalaniz
*/
public class ExchangeRateTest {
@Test
void testExchangeRateAtSpecificDate() throws ExchangeRateException {
assertEquals(new BigDecimal("31.9396"), ExchangeRateClient.INSTANCE
.centralBankQuery()
.getExchangeRate(LocalDate.of(2018, 10, 1)));
assertEquals(new BigDecimal("32.0679"), ExchangeRateClient.INSTANCE
.centralBankQuery()
.getExchangeRate(LocalDate.of(2018, 10, 31)));
}
@Test
void testMonthlyExchangeRateAtSpecificDate() throws ExchangeRateException {
MonthlyExchangeRate monthlyExchangeRate = ExchangeRateClient.INSTANCE
.centralBankQuery()
.getMonthlyExchangeRate(YearMonth.of(2018, 10));
assertEquals(31, monthlyExchangeRate.size());
assertEquals(new BigDecimal("31.9396"), monthlyExchangeRate.getFirstExchangeRate());
assertEquals(new BigDecimal("32.0679"), monthlyExchangeRate.getLastExchangeRate());
assertEquals(new BigDecimal("31.9994"), monthlyExchangeRate.getExchangeRate(LocalDate.of(2018, 10, 15)));
assertEquals(BigDecimal.ZERO, monthlyExchangeRate.getExchangeRate(LocalDate.of(2018, 9, 30)));
assertFalse(monthlyExchangeRate.isHasGaps());
LocalDate date1 = LocalDate.of(2018, 10, 1);
LocalDate date2 = LocalDate.of(2018, 10, 15);
Map<LocalDate, BigDecimal> rangeOfValues = monthlyExchangeRate.getExchangeRateBetween(date1, date2);
assertEquals(15, rangeOfValues.size());
assertEquals(new BigDecimal("31.9396"), rangeOfValues.get(date1));
assertEquals(new BigDecimal("31.9994"), rangeOfValues.get(date2));
}
@Test
void testExchangeRateAtSpecificDateUsingRetry() throws ExchangeRateException {
assertEquals(new BigDecimal("31.9396"), ExchangeRateClient.INSTANCE
.centralBankQuery(5)
.getExchangeRate(LocalDate.of(2018, 10, 1)));
assertEquals(new BigDecimal("32.0679"), ExchangeRateClient.INSTANCE
.centralBankQuery(5)
.getExchangeRate(LocalDate.of(2018, 10, 31)));
}
@Test
void testValidationOfYear() {
assertThrows(ExchangeRateException.class, () -> {
ExchangeRateClient.INSTANCE
.centralBankQuery()
.getExchangeRate(LocalDate.of(2011, 12, 31));
});
assertThrows(ExchangeRateException.class, () -> {
ExchangeRateClient.INSTANCE
.centralBankQuery()
.getMonthlyExchangeRate(YearMonth.of(2011, Month.DECEMBER));
});
assertThrows(ExchangeRateException.class, () -> {
ExchangeRateClient.INSTANCE
.centralBankQuery()
.getMonthlyExchangeRate(YearMonth.of(2011, 10));
});
}
@Test
void testBANPRO() {
assertDoesNotThrow(() -> {
BankScraper scraper = BankScraper.BANPRO;
scraper.fetchData();
});
}
@Test
void testFICOHSA() {
assertDoesNotThrow(() -> {
BankScraper scraper = BankScraper.FICOHSA;
scraper.fetchData();
});
}
@Test
void testAVANZ() {
assertDoesNotThrow(() -> {
BankScraper scraper = BankScraper.AVANZ;
scraper.fetchData();
});
}
@Test
void testBAC() {
assertDoesNotThrow(() -> {
BankScraper scraper = BankScraper.BAC;
scraper.fetchData();
});
}
@Test
void testBDF() {
assertDoesNotThrow(() -> {
BankScraper scraper = BankScraper.BDF;
scraper.fetchData();
});
}
@Test
void testLAFISE() {
assertDoesNotThrow(() -> {
BankScraper scraper = BankScraper.LAFISE;
scraper.fetchData();
});
}
@Test
void testBanks() {
List<Bank> banks = ExchangeRateClient.INSTANCE.bankQuery().banks();
assertEquals(BankScraper.count(), banks.size());
}
@Test
void testBankSummary() {
BankExchangeRateSummary bankExchangeRateSummary = ExchangeRateClient.INSTANCE.bankQuery().bankSummary();
assertFalse(bankExchangeRateSummary.trades().isEmpty());
}
@Test
void testBankTrades() {
List<ExchangeRateTrade> bankTrades = ExchangeRateClient.INSTANCE.bankQuery().bankTrades();
assertFalse(bankTrades.isEmpty());
}
}