Skip to content
This repository has been archived by the owner on Dec 12, 2020. It is now read-only.

Commit

Permalink
Fix APITest
Browse files Browse the repository at this point in the history
  • Loading branch information
Xerus committed Aug 26, 2018
1 parent 729925b commit a12a61d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion src/main/xerus/monstercat/api/API.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ 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

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() }
Expand Down
14 changes: 11 additions & 3 deletions src/test/xerus/monstercat/api/PlayerTest.kt
Original file line number Diff line number Diff line change
@@ -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 <T, U> check(value: T, expected: U, test: (T, U) -> Boolean = { v, e -> v == e }) {
Assertions.assertTrue(test(value, expected)) {
"$value did not match $expected"
}
}

}

0 comments on commit a12a61d

Please sign in to comment.