From a12a61d5a5884a0f31275816309820f4de6e2eba Mon Sep 17 00:00:00 2001 From: Xerus <27jf@web.de> Date: Sun, 26 Aug 2018 16:13:21 +0200 Subject: [PATCH] Fix APITest --- build.gradle.kts | 2 +- src/main/xerus/monstercat/api/API.kt | 3 ++- src/test/xerus/monstercat/api/PlayerTest.kt | 14 +++++++++++--- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index aa350f6..79250dc 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -12,7 +12,7 @@ version = "dev" + Scanner(Runtime.getRuntime().exec("git rev-list --count HEAD") file("src/resources/version").writeText(version as String) plugins { - kotlin("jvm") version "1.2.51" + kotlin("jvm") version "1.2.61" application id("com.github.johnrengelman.shadow") version "2.0.4" id("com.github.ben-manes.versions") version "0.19.0" diff --git a/src/main/xerus/monstercat/api/API.kt b/src/main/xerus/monstercat/api/API.kt index 30966a6..fbfffaf 100644 --- a/src/main/xerus/monstercat/api/API.kt +++ b/src/main/xerus/monstercat/api/API.kt @@ -3,6 +3,7 @@ package xerus.monstercat.api import xerus.ktutil.to import xerus.ktutil.toInt import xerus.monstercat.api.response.Track +import xerus.monstercat.api.response.declaredKeys import java.net.URLEncoder import java.util.regex.Pattern @@ -10,7 +11,7 @@ object API { /** Finds the best match for the given [title] and [artists] */ fun find(title: String, artists: String): Track? { - val connection = APIConnection("catalog", "track").addQuery("fields", "artists", "artistsTitle", "title") + val connection = APIConnection("catalog", "track").addQuery("fields", *Track::class.declaredKeys.toTypedArray()) URLEncoder.encode(title, "UTF-8") .split(Pattern.compile("%..")) .filter { it.isNotBlank() } diff --git a/src/test/xerus/monstercat/api/PlayerTest.kt b/src/test/xerus/monstercat/api/PlayerTest.kt index 9901838..b309d53 100644 --- a/src/test/xerus/monstercat/api/PlayerTest.kt +++ b/src/test/xerus/monstercat/api/PlayerTest.kt @@ -1,13 +1,21 @@ package xerus.monstercat.api +import org.junit.jupiter.api.Assertions +import org.junit.jupiter.api.Test import xerus.monstercat.api.response.Artist internal class APITest { - @org.junit.jupiter.api.Test + @Test fun find() { - assert(API.find("Edge Of The World", "Razihel & Xilent")!!.artists.contains(Artist("Razihel"))) - assert(API.find("Edge Of The World", "Karma Fields")!!.artistsTitle == "Karma Fields") + check(API.find("Edge Of The World", "Razihel & Xilent")!!.artists, Artist("Razihel")) { v, e -> v.contains(e) } + check(API.find("Edge Of The World", "Karma Fields")!!.artistsTitle, "Karma Fields") + } + + fun check(value: T, expected: U, test: (T, U) -> Boolean = { v, e -> v == e }) { + Assertions.assertTrue(test(value, expected)) { + "$value did not match $expected" + } } } \ No newline at end of file