Added tests for apiCall()
This commit is contained in:
parent
b4e37a5877
commit
1e5f058ed4
1 changed files with 22 additions and 0 deletions
|
@ -1,5 +1,6 @@
|
|||
package net.thauvin.erik.crypto
|
||||
|
||||
import net.thauvin.erik.crypto.CryptoPrice.Companion.apiCall
|
||||
import net.thauvin.erik.crypto.CryptoPrice.Companion.marketPrice
|
||||
import net.thauvin.erik.crypto.CryptoPrice.Companion.toPrice
|
||||
import java.time.LocalDate
|
||||
|
@ -48,6 +49,15 @@ class CryptoPriceTest {
|
|||
assertTrue(price.amount > 0.00, "BCH > 0")
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(CryptoException::class)
|
||||
fun testApiCall() {
|
||||
val price = apiCall(listOf("prices", "BTC-USD", "buy"), emptyMap()).toPrice()
|
||||
assertEquals(price.base, "BTC", "buy BTC")
|
||||
assertEquals(price.currency, "USD", "buy BTC is USD")
|
||||
assertTrue(price.amount > 0.00, "buy BTC > 0")
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(CryptoException::class)
|
||||
fun testMarketPriceExceptions() {
|
||||
|
@ -85,5 +95,17 @@ class CryptoPriceTest {
|
|||
exceptionClass = CryptoException::class,
|
||||
block = { json.replace("5", "a").toPrice() }
|
||||
)
|
||||
|
||||
assertFailsWith(
|
||||
message = "empty did not fail",
|
||||
exceptionClass = CryptoException::class,
|
||||
block = { "{}".toPrice() }
|
||||
)
|
||||
|
||||
assertFailsWith(
|
||||
message = "no base did not fail",
|
||||
exceptionClass = CryptoException::class,
|
||||
block = { json.replace("base","food").toPrice() }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue