Skip to content

Commit 57cf887

Browse files
committed
Merge branch 'unit-test-cleanup' into main
2 parents 64f8d54 + 0d3619c commit 57cf887

File tree

10 files changed

+1191
-248
lines changed

10 files changed

+1191
-248
lines changed

app/src/main/java/dev/shorthouse/coinwatch/domain/GetCoinsUseCase.kt

-29
This file was deleted.

app/src/test/java/dev/shorthouse/coinwatch/data/mapper/CoinChartMapperTest.kt

+91-9
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class CoinChartMapperTest {
1717
// Class under test
1818
private val coinChartMapper = CoinChartMapper()
1919

20-
private val currency = Currency.USD
20+
private val defaultCurrency = Currency.USD
2121

2222
@Test
2323
fun `When coin chart data is null should return default values`() {
@@ -36,7 +36,7 @@ class CoinChartMapperTest {
3636
// Act
3737
val coinChart = coinChartMapper.mapApiModelToModel(
3838
apiModel = apiModel,
39-
currency = currency
39+
currency = defaultCurrency
4040
)
4141

4242
// Assert
@@ -63,7 +63,7 @@ class CoinChartMapperTest {
6363
// Act
6464
val coinChart = coinChartMapper.mapApiModelToModel(
6565
apiModel = apiModel,
66-
currency = currency
66+
currency = defaultCurrency
6767
)
6868

6969
// Assert
@@ -90,7 +90,7 @@ class CoinChartMapperTest {
9090
// Act
9191
val coinChart = coinChartMapper.mapApiModelToModel(
9292
apiModel = apiModel,
93-
currency = currency
93+
currency = defaultCurrency
9494
)
9595

9696
// Assert
@@ -117,7 +117,7 @@ class CoinChartMapperTest {
117117
// Act
118118
val coinChart = coinChartMapper.mapApiModelToModel(
119119
apiModel = apiModel,
120-
currency = currency
120+
currency = defaultCurrency
121121
)
122122

123123
// Assert
@@ -151,7 +151,7 @@ class CoinChartMapperTest {
151151
// Act
152152
val coinChart = coinChartMapper.mapApiModelToModel(
153153
apiModel = apiModel,
154-
currency = currency
154+
currency = defaultCurrency
155155
)
156156

157157
// Assert
@@ -184,7 +184,7 @@ class CoinChartMapperTest {
184184
// Act
185185
val coinChart = coinChartMapper.mapApiModelToModel(
186186
apiModel = apiModel,
187-
currency = currency
187+
currency = defaultCurrency
188188
)
189189

190190
// Assert
@@ -220,7 +220,7 @@ class CoinChartMapperTest {
220220
// Act
221221
val coinChart = coinChartMapper.mapApiModelToModel(
222222
apiModel = apiModel,
223-
currency = currency
223+
currency = defaultCurrency
224224
)
225225

226226
// Assert
@@ -259,7 +259,7 @@ class CoinChartMapperTest {
259259
// Act
260260
val coinChart = coinChartMapper.mapApiModelToModel(
261261
apiModel = apiModel,
262-
currency = currency
262+
currency = defaultCurrency
263263
)
264264

265265
// Assert
@@ -295,6 +295,88 @@ class CoinChartMapperTest {
295295
periodPriceChangePercentage = Percentage("2.92")
296296
)
297297

298+
// Act
299+
val coinChart = coinChartMapper.mapApiModelToModel(
300+
apiModel = apiModel,
301+
currency = defaultCurrency
302+
)
303+
304+
// Assert
305+
assertThat(coinChart).isEqualTo(expectedCoinChart)
306+
}
307+
308+
@Test
309+
fun `When coin chart has gbp currency with valid values should return expected coin chart`() {
310+
// Arrange
311+
val currency = Currency.GBP
312+
313+
val apiModel = CoinChartApiModel(
314+
coinChartData = CoinChartData(
315+
priceChangePercentage = "2.92",
316+
pastPrices = listOf(
317+
PastPrice("123.45"),
318+
PastPrice("123.46"),
319+
PastPrice("123.47"),
320+
PastPrice("123.48"),
321+
PastPrice("123.49")
322+
)
323+
)
324+
)
325+
326+
val expectedCoinChart = CoinChart(
327+
prices = persistentListOf(
328+
BigDecimal("123.49"),
329+
BigDecimal("123.48"),
330+
BigDecimal("123.47"),
331+
BigDecimal("123.46"),
332+
BigDecimal("123.45")
333+
),
334+
minPrice = Price("123.45", currency = currency),
335+
maxPrice = Price("123.49", currency = currency),
336+
periodPriceChangePercentage = Percentage("2.92")
337+
)
338+
339+
// Act
340+
val coinChart = coinChartMapper.mapApiModelToModel(
341+
apiModel = apiModel,
342+
currency = currency
343+
)
344+
345+
// Assert
346+
assertThat(coinChart).isEqualTo(expectedCoinChart)
347+
}
348+
349+
@Test
350+
fun `When coin chart has eur currency with valid values should return expected coin chart`() {
351+
// Arrange
352+
val currency = Currency.EUR
353+
354+
val apiModel = CoinChartApiModel(
355+
coinChartData = CoinChartData(
356+
priceChangePercentage = "2.92",
357+
pastPrices = listOf(
358+
PastPrice("123.45"),
359+
PastPrice("123.46"),
360+
PastPrice("123.47"),
361+
PastPrice("123.48"),
362+
PastPrice("123.49")
363+
)
364+
)
365+
)
366+
367+
val expectedCoinChart = CoinChart(
368+
prices = persistentListOf(
369+
BigDecimal("123.49"),
370+
BigDecimal("123.48"),
371+
BigDecimal("123.47"),
372+
BigDecimal("123.46"),
373+
BigDecimal("123.45")
374+
),
375+
minPrice = Price("123.45", currency = currency),
376+
maxPrice = Price("123.49", currency = currency),
377+
periodPriceChangePercentage = Percentage("2.92")
378+
)
379+
298380
// Act
299381
val coinChart = coinChartMapper.mapApiModelToModel(
300382
apiModel = apiModel,

app/src/test/java/dev/shorthouse/coinwatch/data/mapper/CoinDetailsMapperTest.kt

+112-6
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class CoinDetailsMapperTest {
1616
// Class under test
1717
private val coinDetailsMapper = CoinDetailsMapper()
1818

19-
private val currency = Currency.USD
19+
private val defaultCurrency = Currency.USD
2020

2121
@Test
2222
fun `When coin details data holder is null should return default values`() {
@@ -43,7 +43,7 @@ class CoinDetailsMapperTest {
4343
// Act
4444
val coinDetails = coinDetailsMapper.mapApiModelToModel(
4545
apiModel = coinDetailsApiModel,
46-
currency = currency
46+
currency = defaultCurrency
4747
)
4848

4949
// Assert
@@ -77,7 +77,7 @@ class CoinDetailsMapperTest {
7777
// Act
7878
val coinDetails = coinDetailsMapper.mapApiModelToModel(
7979
apiModel = coinDetailsApiModel,
80-
currency = currency
80+
currency = defaultCurrency
8181
)
8282

8383
// Assert
@@ -123,7 +123,7 @@ class CoinDetailsMapperTest {
123123
// Act
124124
val coinDetails = coinDetailsMapper.mapApiModelToModel(
125125
apiModel = coinDetailsApiModel,
126-
currency = currency
126+
currency = defaultCurrency
127127
)
128128

129129
// Assert
@@ -174,7 +174,7 @@ class CoinDetailsMapperTest {
174174
// Act
175175
val coinDetails = coinDetailsMapper.mapApiModelToModel(
176176
apiModel = coinDetailsApiModel,
177-
currency = currency
177+
currency = defaultCurrency
178178
)
179179

180180
// Assert
@@ -225,7 +225,7 @@ class CoinDetailsMapperTest {
225225
// Act
226226
val coinDetails = coinDetailsMapper.mapApiModelToModel(
227227
apiModel = coinDetailsApiModel,
228-
currency = currency
228+
currency = defaultCurrency
229229
)
230230

231231
// Assert
@@ -273,6 +273,112 @@ class CoinDetailsMapperTest {
273273
listedDate = "26 Feb 2012"
274274
)
275275

276+
// Act
277+
val coinDetails = coinDetailsMapper.mapApiModelToModel(
278+
coinDetailsApiModel,
279+
currency = defaultCurrency
280+
)
281+
282+
// Assert
283+
assertThat(coinDetails).isEqualTo(expectedCoinDetails)
284+
}
285+
286+
@Test
287+
fun `When coin details has gbp currency with valid values should map expected coin details`() {
288+
// Arrange
289+
val currency = Currency.GBP
290+
291+
val coinDetailsApiModel = CoinDetailsApiModel(
292+
coinDetailsDataHolder = CoinDetailsDataHolder(
293+
coinDetailsData = CoinDetailsData(
294+
id = "Qwsogvtv82FCd",
295+
name = "Bitcoin",
296+
symbol = "BTC",
297+
imageUrl = "https://cdn.coinranking.com/bOabBYkcX/bitcoin_btc.svg",
298+
currentPrice = "29490.954785191607",
299+
marketCap = "515076089546.27606",
300+
marketCapRank = "1",
301+
volume24h = "9294621082.273935",
302+
supply = Supply(
303+
circulatingSupply = "19508368"
304+
),
305+
allTimeHigh = AllTimeHigh(
306+
price = "68763.41083248306",
307+
timestamp = 1636502400
308+
),
309+
listedAt = 1330214400
310+
)
311+
)
312+
)
313+
314+
val expectedCoinDetails = CoinDetails(
315+
id = "Qwsogvtv82FCd",
316+
name = "Bitcoin",
317+
symbol = "BTC",
318+
imageUrl = "https://cdn.coinranking.com/bOabBYkcX/bitcoin_btc.svg",
319+
currentPrice = Price("29490.954785191607", currency = currency),
320+
marketCap = Price("515076089546.27606", currency = currency),
321+
marketCapRank = "1",
322+
volume24h = "9,294,621,082.274",
323+
circulatingSupply = "19,508,368",
324+
allTimeHigh = Price("68763.41083248306", currency = currency),
325+
allTimeHighDate = "10 Nov 2021",
326+
listedDate = "26 Feb 2012"
327+
)
328+
329+
// Act
330+
val coinDetails = coinDetailsMapper.mapApiModelToModel(
331+
coinDetailsApiModel,
332+
currency = currency
333+
)
334+
335+
// Assert
336+
assertThat(coinDetails).isEqualTo(expectedCoinDetails)
337+
}
338+
339+
@Test
340+
fun `When coin details has eur currency with valid values should map expected coin details`() {
341+
// Arrange
342+
val currency = Currency.EUR
343+
344+
val coinDetailsApiModel = CoinDetailsApiModel(
345+
coinDetailsDataHolder = CoinDetailsDataHolder(
346+
coinDetailsData = CoinDetailsData(
347+
id = "Qwsogvtv82FCd",
348+
name = "Bitcoin",
349+
symbol = "BTC",
350+
imageUrl = "https://cdn.coinranking.com/bOabBYkcX/bitcoin_btc.svg",
351+
currentPrice = "29490.954785191607",
352+
marketCap = "515076089546.27606",
353+
marketCapRank = "1",
354+
volume24h = "9294621082.273935",
355+
supply = Supply(
356+
circulatingSupply = "19508368"
357+
),
358+
allTimeHigh = AllTimeHigh(
359+
price = "68763.41083248306",
360+
timestamp = 1636502400
361+
),
362+
listedAt = 1330214400
363+
)
364+
)
365+
)
366+
367+
val expectedCoinDetails = CoinDetails(
368+
id = "Qwsogvtv82FCd",
369+
name = "Bitcoin",
370+
symbol = "BTC",
371+
imageUrl = "https://cdn.coinranking.com/bOabBYkcX/bitcoin_btc.svg",
372+
currentPrice = Price("29490.954785191607", currency = currency),
373+
marketCap = Price("515076089546.27606", currency = currency),
374+
marketCapRank = "1",
375+
volume24h = "9,294,621,082.274",
376+
circulatingSupply = "19,508,368",
377+
allTimeHigh = Price("68763.41083248306", currency = currency),
378+
allTimeHighDate = "10 Nov 2021",
379+
listedDate = "26 Feb 2012"
380+
)
381+
276382
// Act
277383
val coinDetails = coinDetailsMapper.mapApiModelToModel(
278384
coinDetailsApiModel,

0 commit comments

Comments
 (0)