diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000..26d3352
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,3 @@
+# Default ignored files
+/shelf/
+/workspace.xml
diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml
new file mode 100644
index 0000000..8dc4293
--- /dev/null
+++ b/.idea/codeStyles/Project.xml
@@ -0,0 +1,18 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml
new file mode 100644
index 0000000..79ee123
--- /dev/null
+++ b/.idea/codeStyles/codeStyleConfig.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
new file mode 100644
index 0000000..fb7f4a8
--- /dev/null
+++ b/.idea/compiler.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml
new file mode 100644
index 0000000..cfd3ca8
--- /dev/null
+++ b/.idea/jarRepositories.xml
@@ -0,0 +1,25 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries-with-intellij-classes.xml b/.idea/libraries-with-intellij-classes.xml
new file mode 100644
index 0000000..9fa3156
--- /dev/null
+++ b/.idea/libraries-with-intellij-classes.xml
@@ -0,0 +1,65 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..0474152
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..35eb1dd
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/build.gradle.kts b/build.gradle.kts
index 9266330..6292bb8 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -41,7 +41,7 @@ dependencies {
}
application {
- mainClassName = "net.thauvin.erik.crypto.CryptoPrice"
+ mainClass.set("net.thauvin.erik.crypto.CryptoPrice")
}
java {
@@ -133,7 +133,7 @@ publishing {
scm {
connection.set("scm:git:git://github.com/$gitHub.git")
developerConnection.set("scm:git:git@github.com:$gitHub.git")
- url.set("$mavenUrl")
+ url.set(mavenUrl)
}
issueManagement {
system.set("GitHub")
diff --git a/examples/build.gradle.kts b/examples/build.gradle.kts
index a2b3e3b..fe0f360 100644
--- a/examples/build.gradle.kts
+++ b/examples/build.gradle.kts
@@ -19,7 +19,7 @@ dependencies {
}
application {
- mainClassName = "com.example.CryptoPriceExampleKt"
+ mainClass.set("com.example.CryptoPriceExampleKt")
}
tasks {
diff --git a/src/main/kotlin/net/thauvin/erik/crypto/CryptoException.kt b/src/main/kotlin/net/thauvin/erik/crypto/CryptoException.kt
index bf13c0a..02e60c6 100644
--- a/src/main/kotlin/net/thauvin/erik/crypto/CryptoException.kt
+++ b/src/main/kotlin/net/thauvin/erik/crypto/CryptoException.kt
@@ -32,11 +32,11 @@
package net.thauvin.erik.crypto
-@Suppress("EmptySecondaryConstructor")
+@Suppress("EmptySecondaryConstructor", "unused")
class CryptoException : Exception {
- constructor(message: String, cause: Throwable) : super(message, cause) {}
- constructor(message: String) : super(message) {}
- constructor(cause: Throwable) : super(cause) {}
+ constructor(message: String, cause: Throwable) : super(message, cause)
+ constructor(message: String) : super(message)
+ constructor(cause: Throwable) : super(cause)
companion object {
private const val serialVersionUID = 1L
diff --git a/src/main/kotlin/net/thauvin/erik/crypto/CryptoPrice.kt b/src/main/kotlin/net/thauvin/erik/crypto/CryptoPrice.kt
index d0eda9f..b3cf1d6 100644
--- a/src/main/kotlin/net/thauvin/erik/crypto/CryptoPrice.kt
+++ b/src/main/kotlin/net/thauvin/erik/crypto/CryptoPrice.kt
@@ -36,8 +36,6 @@ import okhttp3.HttpUrl.Companion.toHttpUrl
import okhttp3.OkHttpClient
import okhttp3.Request
import org.json.JSONObject
-import java.io.IOException
-import java.net.URL
import java.time.LocalDate
/**
@@ -54,9 +52,10 @@ open class CryptoPrice(val base: String, val currency: String, val amount: Doubl
val json = JSONObject(this)
if (json.has("data")) {
with(json.getJSONObject("data")) {
- return CryptoPrice(getString("base"), getString("currency"), getString("amount").toDouble()
- )
- }
+ return CryptoPrice(
+ getString("base"), getString("currency"), getString("amount").toDouble()
+ )
+ }
} else {
throw CryptoException("Missing JSON data.")
}
diff --git a/src/test/kotlin/net/thauvin/erik/crypto/CryptoPriceTest.kt b/src/test/kotlin/net/thauvin/erik/crypto/CryptoPriceTest.kt
index 8e82149..32a59de 100644
--- a/src/test/kotlin/net/thauvin/erik/crypto/CryptoPriceTest.kt
+++ b/src/test/kotlin/net/thauvin/erik/crypto/CryptoPriceTest.kt
@@ -2,11 +2,11 @@ package net.thauvin.erik.crypto
import net.thauvin.erik.crypto.CryptoPrice.Companion.marketPrice
import net.thauvin.erik.crypto.CryptoPrice.Companion.toPrice
+import java.time.LocalDate
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFailsWith
import kotlin.test.assertTrue
-import java.time.LocalDate
/**
* The `CryptoPriceTest` class.
@@ -52,24 +52,25 @@ class CryptoPriceTest {
@Throws(CryptoException::class)
fun testMarketPriceExceptions() {
assertFailsWith(
- message = "FOO did not fail",
- exceptionClass = CryptoException::class,
- block = { marketPrice("FOO") }
+ message = "FOO did not fail",
+ exceptionClass = CryptoException::class,
+ block = { marketPrice("FOO") }
)
assertFailsWith(
- message = "BAR did not fail",
- exceptionClass = CryptoException::class,
- block = { marketPrice("BTC", "BAR") }
+ message = "BAR did not fail",
+ exceptionClass = CryptoException::class,
+ block = { marketPrice("BTC", "BAR") }
)
}
@Test
@Throws(CryptoException::class)
fun testToPrice() {
- val price = "{\"data\":{\"base\":\"BTC\",\"currency\":\"USD\",\"amount\":\"57515.69\"}}".toPrice()
+ val d = 57515.69
+ val price = "{\"data\":{\"base\":\"BTC\",\"currency\":\"USD\",\"amount\":\"$d\"}}".toPrice()
assertEquals(price.base, "BTC", "base is BTC")
assertEquals(price.currency, "USD", "currency is USD")
- assertEquals(price.amount, "57515.69".toDouble(), "amount is 57515.69")
+ assertEquals(price.amount, d, "amount is 57515.69")
}
}