Updated dependencies and copyright.

This commit is contained in:
Erik C. Thauvin 2022-01-03 11:52:09 -08:00
parent bbf28ad692
commit 39251ca967
18 changed files with 102 additions and 134 deletions

View file

@ -1,7 +1,7 @@
/*
* CryptoException.kt
*
* Copyright (c) 2021, Erik C. Thauvin (erik@thauvin.net)
* Copyright (c) 2021-2022, Erik C. Thauvin (erik@thauvin.net)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without

View file

@ -1,7 +1,7 @@
/*
* CryptoPrice.kt
*
* Copyright (c) 2021, Erik C. Thauvin (erik@thauvin.net)
* Copyright (c) 2021-2022, Erik C. Thauvin (erik@thauvin.net)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without

View file

@ -1,8 +1,41 @@
/*
* CryptoPriceTest.kt
*
* Copyright (c) 2021-2022, Erik C. Thauvin (erik@thauvin.net)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of this project nor the names of its contributors may be
* used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.thauvin.erik.crypto
import net.thauvin.erik.crypto.CryptoPrice.Companion.apiCall
import net.thauvin.erik.crypto.CryptoPrice.Companion.spotPrice
import net.thauvin.erik.crypto.CryptoPrice.Companion.toPrice
import org.json.JSONObject
import java.time.LocalDate
import java.util.Locale
import kotlin.test.Test
@ -61,6 +94,10 @@ class CryptoPriceTest {
assertEquals("BTC", price.base, "buy BTC")
assertEquals("USD", price.currency, "buy BTC is USD")
assertTrue(price.amount.signum() > 0, "buy BTC > 0")
val response = apiCall(listOf("exchange-rates"), mapOf("currency" to "usd"))
val rates = JSONObject(response).getJSONObject("data").getJSONObject("rates")
assertEquals("1.0", rates.getString("USD"), "usd rate")
}
@Test
@ -81,7 +118,7 @@ class CryptoPriceTest {
try {
spotPrice("FOOBAR")
} catch (e: CryptoException) {
assertTrue(e.statusCode != 400, "FOOBAR status code is not 400")
assertNotEquals(400, e.statusCode, "FOOBAR status code is not 400")
}
}