diff --git a/.idea/copyright/Erik_s_Copyright_Notice.xml b/.idea/copyright/Erik_s_Copyright_Notice.xml
index 08660a1..08333f5 100644
--- a/.idea/copyright/Erik_s_Copyright_Notice.xml
+++ b/.idea/copyright/Erik_s_Copyright_Notice.xml
@@ -1,6 +1,6 @@
-
+
\ No newline at end of file
diff --git a/.idea/kotlinc.xml b/.idea/kotlinc.xml
index e1eea1d..2b8a50f 100644
--- a/.idea/kotlinc.xml
+++ b/.idea/kotlinc.xml
@@ -1,6 +1,6 @@
-
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
index 2dbd526..77113c7 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -1,7 +1,10 @@
-
+
+
+
+
\ No newline at end of file
diff --git a/LICENSE.txt b/LICENSE.txt
index 09e222b..4331a4d 100644
--- a/LICENSE.txt
+++ b/LICENSE.txt
@@ -1,5 +1,4 @@
-Copyright (c) 2022, Erik C. Thauvin (erik@thauvin.net)
-All rights reserved.
+Copyright 2022-2023 Erik C. Thauvin (erik@thauvin.net)
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
diff --git a/README.md b/README.md
index 6eaed1c..ed90877 100644
--- a/README.md
+++ b/README.md
@@ -1,10 +1,16 @@
-[](https://opensource.org/licenses/BSD-3-Clause) [](https://oss.sonatype.org/content/repositories/snapshots/net/thauvin/erik/jokeapi/)
+[](https://opensource.org/licenses/BSD-3-Clause)
+[](https://kotlinlang.org/)
+[](https://oss.sonatype.org/content/repositories/snapshots/net/thauvin/erik/jokeapi/)
+[](https://github.com/ethauvin/jokeapi/releases/latest)
+[](https://maven-badges.herokuapp.com/maven-central/net.thauvin.erik/jokeapi)
-[](https://sonarcloud.io/dashboard?id=ethauvin_jokeapi) [](https://github.com/ethauvin/jokeapi/actions/workflows/gradle.yml) [](https://circleci.com/gh/ethauvin/jokeapi/tree/master)
+[](https://sonarcloud.io/dashboard?id=ethauvin_jokeapi)
+[](https://github.com/ethauvin/jokeapi/actions/workflows/gradle.yml)
+[](https://circleci.com/gh/ethauvin/jokeapi/tree/master)
-# JokeAPI for Kotlin/Java
+# JokeAPI for Kotlin, Java and Android
-A simple Kotlin/Java library to retrieve jokes from [Sv443's JokeAPI](https://v2.jokeapi.dev/).
+A simple library to retrieve jokes from [Sv443's JokeAPI](https://v2.jokeapi.dev/).
## Examples (TL;DR)
@@ -17,7 +23,7 @@ val pun = getJoke(categories = setOf(Category.PUN))
```
The parameters match the [joke endpoint](https://v2.jokeapi.dev/#joke-endpoint).
-A `Joke` class instance is returned:
+A `Joke` class instance is returned, matching the [response](https://v2.jokeapi.dev/joke/Any?type=single):
```kotlin
data class Joke(
@@ -45,7 +51,7 @@ frenchJokes.forEach {
- View more [examples](https://github.com/ethauvin/jokeapi/blob/master/src/test/kotlin/net/thauvin/erik/jokeapi/GetJokesTest.kt)...
-If an error occurs, a `JokeException` is thrown:
+If an error occurs, a `JokeException` is thrown, matching the [JokeAPI errors](https://sv443.net/jokeapi/v2/#errors):
```kotlin
class JokeException(
@@ -88,7 +94,7 @@ To use with [Gradle](https://gradle.org/), include the following dependency in y
```gradle
repositories {
mavenCentral()
- maven { url = uri("https://oss.sonatype.org/content/repositories/snapshots") }
+ maven { url = uri("https://oss.sonatype.org/content/repositories/snapshots") } // only needed for SNAPSHOT
}
dependencies {
diff --git a/build.gradle.kts b/build.gradle.kts
index 8317052..9808282 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -4,18 +4,18 @@ import org.jetbrains.dokka.gradle.DokkaTask
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
- id("com.github.ben-manes.versions") version "0.42.0"
- id("io.gitlab.arturbosch.detekt") version "1.21.0"
+ id("com.github.ben-manes.versions") version "0.44.0"
+ id("io.gitlab.arturbosch.detekt") version "1.22.0"
id("java")
id("maven-publish")
id("org.jetbrains.dokka") version "1.7.20"
id("org.jetbrains.kotlinx.kover") version "0.6.1"
- id("org.sonarqube") version "3.4.0.2513"
+ id("org.sonarqube") version "3.5.0.2730"
id("signing")
- kotlin("jvm") version "1.7.20"
+ kotlin("jvm") version "1.8.0"
}
-description = "Kotlin/Java Wrapper for Sv443's JokeAPI"
+description = "Wrapper for Sv443's JokeAPI"
group = "net.thauvin.erik"
version = "0.9-SNAPSHOT"
@@ -35,14 +35,10 @@ dependencies {
implementation("org.json:json:20220924")
testImplementation(kotlin("test"))
- testImplementation("org.junit.jupiter:junit-jupiter:5.9.1")
+ testImplementation("org.junit.jupiter:junit-jupiter:5.9.2")
testImplementation("com.willowtreeapps.assertk:assertk-jvm:0.25")
}
-tasks.test {
- useJUnitPlatform()
-}
-
java {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
@@ -66,6 +62,10 @@ val javadocJar by tasks.creating(Jar::class) {
}
tasks {
+ test {
+ useJUnitPlatform()
+ }
+
withType().configureEach {
kotlinOptions.jvmTarget = java.targetCompatibility.toString()
}
@@ -141,8 +141,8 @@ publishing {
}
}
scm {
- connection.set("scm:git:git://github.com/$gitHub.git")
- developerConnection.set("scm:git:git@github.com:$gitHub.git")
+ connection.set("scm:git://github.com/$gitHub.git")
+ developerConnection.set("scm:git@github.com:$gitHub.git")
url.set(mavenUrl)
}
issueManagement {
diff --git a/detekt-baseline.xml b/detekt-baseline.xml
index 8ca446d..4e59bad 100644
--- a/detekt-baseline.xml
+++ b/detekt-baseline.xml
@@ -2,7 +2,6 @@
- ComplexMethod:JokeApi.kt$fun getRawJokes( categories: Set<Category> = setOf(Category.ANY), lang: Language = Language.EN, blacklistFlags: Set<Flag> = emptySet(), type: Type = Type.ALL, format: Format = Format.JSON, contains: String = "", idRange: IdRange = IdRange(), amount: Int = 1, safe: Boolean = false, auth: String = "" ): StringLongParameterList:JokeApi.kt$( amount: Int, categories: Set<Category> = setOf(Category.ANY), lang: Language = Language.EN, blacklistFlags: Set<Flag> = emptySet(), type: Type = Type.ALL, contains: String = "", idRange: IdRange = IdRange(), safe: Boolean = false, auth: String = "", splitNewLine: Boolean = false )LongParameterList:JokeApi.kt$( categories: Set<Category> = setOf(Category.ANY), lang: Language = Language.EN, blacklistFlags: Set<Flag> = emptySet(), type: Type = Type.ALL, contains: String = "", idRange: IdRange = IdRange(), safe: Boolean = false, auth: String = "", splitNewLine: Boolean = false )LongParameterList:JokeApi.kt$( categories: Set<Category> = setOf(Category.ANY), lang: Language = Language.EN, blacklistFlags: Set<Flag> = emptySet(), type: Type = Type.ALL, format: Format = Format.JSON, contains: String = "", idRange: IdRange = IdRange(), amount: Int = 1, safe: Boolean = false, auth: String = "" )
@@ -19,6 +18,5 @@
MagicNumber:util.kt$500MagicNumber:util.kt$523TooManyFunctions:JokeConfig.kt$JokeConfig$Builder
- UnusedPrivateMember:JokeConfig.kt$JokeConfig.Builder$search: String
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index ae04661..070cb70 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
diff --git a/src/main/kotlin/net/thauvin/erik/jokeapi/JokeApi.kt b/src/main/kotlin/net/thauvin/erik/jokeapi/JokeApi.kt
index 849acbb..a5cfb3f 100644
--- a/src/main/kotlin/net/thauvin/erik/jokeapi/JokeApi.kt
+++ b/src/main/kotlin/net/thauvin/erik/jokeapi/JokeApi.kt
@@ -1,8 +1,7 @@
/*
* JokeApi.kt
*
- * Copyright (c) 2022, Erik C. Thauvin (erik@thauvin.net)
- * All rights reserved.
+ * Copyright 2022-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@@ -311,18 +310,16 @@ fun getRawJokes(
if (idRange.start >= 0) {
if (idRange.end == -1 || idRange.start == idRange.end) {
params[Parameter.RANGE] = idRange.start.toString()
- } else if (idRange.end > idRange.start) {
- params[Parameter.RANGE] = "${idRange.start}-${idRange.end}"
} else {
- throw IllegalArgumentException("Invalid ID Range: ${idRange.start}, ${idRange.end}")
+ require(idRange.end > idRange.start) { "Invalid ID Range: ${idRange.start}, ${idRange.end}" }
+ params[Parameter.RANGE] = "${idRange.start}-${idRange.end}"
}
}
// Amount
+ require(amount > 0) { "Invalid Amount: $amount" }
if (amount > 1) {
params[Parameter.AMOUNT] = amount.toString()
- } else if (amount <= 0) {
- throw IllegalArgumentException("Invalid Amount: $amount")
}
// Safe
diff --git a/src/main/kotlin/net/thauvin/erik/jokeapi/JokeConfig.kt b/src/main/kotlin/net/thauvin/erik/jokeapi/JokeConfig.kt
index cf1a7d8..8378e23 100644
--- a/src/main/kotlin/net/thauvin/erik/jokeapi/JokeConfig.kt
+++ b/src/main/kotlin/net/thauvin/erik/jokeapi/JokeConfig.kt
@@ -1,8 +1,7 @@
/*
- * Configuration.kt
+ * JokeConfig.kt
*
- * Copyright (c) 2022, Erik C. Thauvin (erik@thauvin.net)
- * All rights reserved.
+ * Copyright 2022-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@@ -77,7 +76,7 @@ class JokeConfig private constructor(
var safe: Boolean = false,
var auth: String = "",
var splitNewLine: Boolean = false
- ) {
+ ) {
fun categories(categories: Set) = apply { this.categories = categories }
fun lang(language: Language) = apply { lang = language }
fun blacklistFlags(flags: Set) = apply { blacklistFlags = flags }
diff --git a/src/main/kotlin/net/thauvin/erik/jokeapi/exceptions/HttpErrorException.kt b/src/main/kotlin/net/thauvin/erik/jokeapi/exceptions/HttpErrorException.kt
index 9f3b58b..cd17ca8 100644
--- a/src/main/kotlin/net/thauvin/erik/jokeapi/exceptions/HttpErrorException.kt
+++ b/src/main/kotlin/net/thauvin/erik/jokeapi/exceptions/HttpErrorException.kt
@@ -1,8 +1,7 @@
/*
* HttpErrorException.kt
*
- * Copyright (c) 2022, Erik C. Thauvin (erik@thauvin.net)
- * All rights reserved.
+ * Copyright 2022-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
diff --git a/src/main/kotlin/net/thauvin/erik/jokeapi/exceptions/JokeException.kt b/src/main/kotlin/net/thauvin/erik/jokeapi/exceptions/JokeException.kt
index 84b37fc..919216e 100644
--- a/src/main/kotlin/net/thauvin/erik/jokeapi/exceptions/JokeException.kt
+++ b/src/main/kotlin/net/thauvin/erik/jokeapi/exceptions/JokeException.kt
@@ -1,8 +1,7 @@
/*
* JokeException.kt
*
- * Copyright (c) 2022, Erik C. Thauvin (erik@thauvin.net)
- * All rights reserved.
+ * Copyright 2022-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
diff --git a/src/main/kotlin/net/thauvin/erik/jokeapi/models/Category.kt b/src/main/kotlin/net/thauvin/erik/jokeapi/models/Category.kt
index 9861c08..4951d4a 100644
--- a/src/main/kotlin/net/thauvin/erik/jokeapi/models/Category.kt
+++ b/src/main/kotlin/net/thauvin/erik/jokeapi/models/Category.kt
@@ -1,8 +1,7 @@
/*
* Category.kt
*
- * Copyright (c) 2022, Erik C. Thauvin (erik@thauvin.net)
- * All rights reserved.
+ * Copyright 2022-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
diff --git a/src/main/kotlin/net/thauvin/erik/jokeapi/models/Flag.kt b/src/main/kotlin/net/thauvin/erik/jokeapi/models/Flag.kt
index 1321817..af92e90 100644
--- a/src/main/kotlin/net/thauvin/erik/jokeapi/models/Flag.kt
+++ b/src/main/kotlin/net/thauvin/erik/jokeapi/models/Flag.kt
@@ -1,8 +1,7 @@
/*
* Flag.kt
*
- * Copyright (c) 2022, Erik C. Thauvin (erik@thauvin.net)
- * All rights reserved.
+ * Copyright 2022-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
diff --git a/src/main/kotlin/net/thauvin/erik/jokeapi/models/Format.kt b/src/main/kotlin/net/thauvin/erik/jokeapi/models/Format.kt
index fd1984c..2678a21 100644
--- a/src/main/kotlin/net/thauvin/erik/jokeapi/models/Format.kt
+++ b/src/main/kotlin/net/thauvin/erik/jokeapi/models/Format.kt
@@ -1,8 +1,7 @@
/*
* Format.kt
*
- * Copyright (c) 2022, Erik C. Thauvin (erik@thauvin.net)
- * All rights reserved.
+ * Copyright 2022-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
diff --git a/src/main/kotlin/net/thauvin/erik/jokeapi/models/IdRange.kt b/src/main/kotlin/net/thauvin/erik/jokeapi/models/IdRange.kt
index bb6da9c..62a6eb6 100644
--- a/src/main/kotlin/net/thauvin/erik/jokeapi/models/IdRange.kt
+++ b/src/main/kotlin/net/thauvin/erik/jokeapi/models/IdRange.kt
@@ -1,8 +1,7 @@
/*
* IdRange.kt
*
- * Copyright (c) 2022, Erik C. Thauvin (erik@thauvin.net)
- * All rights reserved.
+ * Copyright 2022-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
diff --git a/src/main/kotlin/net/thauvin/erik/jokeapi/models/Joke.kt b/src/main/kotlin/net/thauvin/erik/jokeapi/models/Joke.kt
index ed5a2b9..0309977 100644
--- a/src/main/kotlin/net/thauvin/erik/jokeapi/models/Joke.kt
+++ b/src/main/kotlin/net/thauvin/erik/jokeapi/models/Joke.kt
@@ -1,8 +1,7 @@
/*
* Joke.kt
*
- * Copyright (c) 2022, Erik C. Thauvin (erik@thauvin.net)
- * All rights reserved.
+ * Copyright 2022-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
diff --git a/src/main/kotlin/net/thauvin/erik/jokeapi/models/Language.kt b/src/main/kotlin/net/thauvin/erik/jokeapi/models/Language.kt
index 34fa9bd..10c00fb 100644
--- a/src/main/kotlin/net/thauvin/erik/jokeapi/models/Language.kt
+++ b/src/main/kotlin/net/thauvin/erik/jokeapi/models/Language.kt
@@ -1,8 +1,7 @@
/*
* Language.kt
*
- * Copyright (c) 2022, Erik C. Thauvin (erik@thauvin.net)
- * All rights reserved.
+ * Copyright 2022-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
diff --git a/src/main/kotlin/net/thauvin/erik/jokeapi/models/Parameter.kt b/src/main/kotlin/net/thauvin/erik/jokeapi/models/Parameter.kt
index 128c3ea..b9e1106 100644
--- a/src/main/kotlin/net/thauvin/erik/jokeapi/models/Parameter.kt
+++ b/src/main/kotlin/net/thauvin/erik/jokeapi/models/Parameter.kt
@@ -1,8 +1,7 @@
/*
* Parameter.kt
*
- * Copyright (c) 2022, Erik C. Thauvin (erik@thauvin.net)
- * All rights reserved.
+ * Copyright 2022-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
diff --git a/src/main/kotlin/net/thauvin/erik/jokeapi/models/Type.kt b/src/main/kotlin/net/thauvin/erik/jokeapi/models/Type.kt
index 9e28284..59126b4 100644
--- a/src/main/kotlin/net/thauvin/erik/jokeapi/models/Type.kt
+++ b/src/main/kotlin/net/thauvin/erik/jokeapi/models/Type.kt
@@ -1,8 +1,7 @@
/*
* Type.kt
*
- * Copyright (c) 2022, Erik C. Thauvin (erik@thauvin.net)
- * All rights reserved.
+ * Copyright 2022-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
diff --git a/src/main/kotlin/net/thauvin/erik/jokeapi/util.kt b/src/main/kotlin/net/thauvin/erik/jokeapi/util.kt
index a076985..fb4c06a 100644
--- a/src/main/kotlin/net/thauvin/erik/jokeapi/util.kt
+++ b/src/main/kotlin/net/thauvin/erik/jokeapi/util.kt
@@ -1,8 +1,7 @@
/*
* util.kt
*
- * Copyright (c) 2022, Erik C. Thauvin (erik@thauvin.net)
- * All rights reserved.
+ * Copyright 2022-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
diff --git a/src/test/kotlin/net/thauvin/erik/jokeapi/ApiCallTest.kt b/src/test/kotlin/net/thauvin/erik/jokeapi/ApiCallTest.kt
index 057f4f9..ed62699 100644
--- a/src/test/kotlin/net/thauvin/erik/jokeapi/ApiCallTest.kt
+++ b/src/test/kotlin/net/thauvin/erik/jokeapi/ApiCallTest.kt
@@ -1,8 +1,7 @@
/*
* ApiCallTest.kt
*
- * Copyright (c) 2022, Erik C. Thauvin (erik@thauvin.net)
- * All rights reserved.
+ * Copyright 2022-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@@ -36,18 +35,16 @@ import assertk.assertThat
import assertk.assertions.isGreaterThan
import assertk.assertions.startsWith
import net.thauvin.erik.jokeapi.JokeApi.Companion.apiCall
-import net.thauvin.erik.jokeapi.JokeApi.Companion.logger
import net.thauvin.erik.jokeapi.models.Format
import net.thauvin.erik.jokeapi.models.Parameter
import org.json.JSONObject
import org.junit.jupiter.api.Assertions.assertFalse
-import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertAll
-import java.util.logging.ConsoleHandler
-import java.util.logging.Level
+import org.junit.jupiter.api.extension.ExtendWith
import kotlin.test.assertContains
+@ExtendWith(BeforeAllTests::class)
internal class ApiCallTest {
@Test
fun `Get Flags`() {
@@ -76,15 +73,4 @@ internal class ApiCallTest {
val ping = apiCall(endPoint = "ping", params = mapOf(Parameter.FORMAT to Format.TXT.value))
assertThat(ping, "apiCall(ping, txt)").startsWith("Pong!")
}
-
- companion object {
- @JvmStatic
- @BeforeAll
- fun beforeAll() {
- with(logger) {
- addHandler(ConsoleHandler().apply { level = Level.FINE })
- level = Level.FINE
- }
- }
- }
}
diff --git a/src/test/kotlin/net/thauvin/erik/jokeapi/BeforeAllTests.kt b/src/test/kotlin/net/thauvin/erik/jokeapi/BeforeAllTests.kt
new file mode 100644
index 0000000..de9d48a
--- /dev/null
+++ b/src/test/kotlin/net/thauvin/erik/jokeapi/BeforeAllTests.kt
@@ -0,0 +1,47 @@
+/*
+ * BeforeAllTests.kt
+ *
+ * Copyright 2022-2023 Erik C. Thauvin (erik@thauvin.net)
+ *
+ * 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.jokeapi
+
+import org.junit.jupiter.api.extension.BeforeAllCallback
+import org.junit.jupiter.api.extension.ExtensionContext
+import java.util.logging.ConsoleHandler
+import java.util.logging.Level
+
+class BeforeAllTests : BeforeAllCallback {
+ override fun beforeAll(context: ExtensionContext?) {
+ with(JokeApi.logger) {
+ addHandler(ConsoleHandler().apply { level = Level.FINE })
+ level = Level.FINE
+ }
+ }
+}
+
diff --git a/src/test/kotlin/net/thauvin/erik/jokeapi/ExceptionsTest.kt b/src/test/kotlin/net/thauvin/erik/jokeapi/ExceptionsTest.kt
index baf9e7f..7481011 100644
--- a/src/test/kotlin/net/thauvin/erik/jokeapi/ExceptionsTest.kt
+++ b/src/test/kotlin/net/thauvin/erik/jokeapi/ExceptionsTest.kt
@@ -1,8 +1,7 @@
/*
* ExceptionsTest.kt
*
- * Copyright (c) 2022, Erik C. Thauvin (erik@thauvin.net)
- * All rights reserved.
+ * Copyright 2022-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@@ -48,14 +47,13 @@ import net.thauvin.erik.jokeapi.JokeApi.Companion.logger
import net.thauvin.erik.jokeapi.exceptions.HttpErrorException
import net.thauvin.erik.jokeapi.exceptions.JokeException
import net.thauvin.erik.jokeapi.models.Category
-import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows
+import org.junit.jupiter.api.extension.ExtendWith
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.ValueSource
-import java.util.logging.ConsoleHandler
-import java.util.logging.Level
+@ExtendWith(BeforeAllTests::class)
internal class ExceptionsTest {
@Test
fun `Validate Joke Exception`() {
@@ -89,15 +87,4 @@ internal class ExceptionsTest {
prop(HttpErrorException::cause).isNull()
}
}
-
- companion object {
- @JvmStatic
- @BeforeAll
- fun beforeAll() {
- with(logger) {
- addHandler(ConsoleHandler().apply { level = Level.FINE })
- level = Level.FINE
- }
- }
- }
}
diff --git a/src/test/kotlin/net/thauvin/erik/jokeapi/GetJokeTest.kt b/src/test/kotlin/net/thauvin/erik/jokeapi/GetJokeTest.kt
index a8e7b23..636aa60 100644
--- a/src/test/kotlin/net/thauvin/erik/jokeapi/GetJokeTest.kt
+++ b/src/test/kotlin/net/thauvin/erik/jokeapi/GetJokeTest.kt
@@ -1,8 +1,7 @@
/*
* GetJokeTest.kt
*
- * Copyright (c) 2022, Erik C. Thauvin (erik@thauvin.net)
- * All rights reserved.
+ * Copyright 2022-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@@ -57,12 +56,11 @@ import net.thauvin.erik.jokeapi.models.IdRange
import net.thauvin.erik.jokeapi.models.Joke
import net.thauvin.erik.jokeapi.models.Language
import net.thauvin.erik.jokeapi.models.Type
-import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows
-import java.util.logging.ConsoleHandler
-import java.util.logging.Level
+import org.junit.jupiter.api.extension.ExtendWith
+@ExtendWith(BeforeAllTests::class)
internal class GetJokeTest {
@Test
fun `Get Joke`() {
@@ -176,7 +174,6 @@ internal class GetJokeTest {
logger.fine(joke.toString())
assertThat(joke, "getJoke(safe)").all {
prop(Joke::safe).isTrue()
- prop(Joke::flags).isEmpty()
}
}
@@ -211,15 +208,4 @@ internal class GetJokeTest {
}
}
}
-
- companion object {
- @JvmStatic
- @BeforeAll
- fun beforeAll() {
- with(logger) {
- addHandler(ConsoleHandler().apply { level = Level.FINE })
- level = Level.FINE
- }
- }
- }
}
diff --git a/src/test/kotlin/net/thauvin/erik/jokeapi/GetJokesTest.kt b/src/test/kotlin/net/thauvin/erik/jokeapi/GetJokesTest.kt
index 3646eb0..ffaa73d 100644
--- a/src/test/kotlin/net/thauvin/erik/jokeapi/GetJokesTest.kt
+++ b/src/test/kotlin/net/thauvin/erik/jokeapi/GetJokesTest.kt
@@ -1,8 +1,7 @@
/*
- * GetJokeTests.kt
+ * GetJokesTest.kt
*
- * Copyright (c) 2022, Erik C. Thauvin (erik@thauvin.net)
- * All rights reserved.
+ * Copyright 2022-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@@ -37,22 +36,19 @@ import assertk.assertThat
import assertk.assertions.contains
import assertk.assertions.each
import assertk.assertions.index
-import assertk.assertions.isEmpty
import assertk.assertions.isEqualTo
import assertk.assertions.isGreaterThanOrEqualTo
import assertk.assertions.isNotNull
import assertk.assertions.isTrue
import assertk.assertions.prop
import assertk.assertions.size
-import net.thauvin.erik.jokeapi.JokeApi.Companion.logger
import net.thauvin.erik.jokeapi.models.Joke
import net.thauvin.erik.jokeapi.models.Language
-import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows
-import java.util.logging.ConsoleHandler
-import java.util.logging.Level
+import org.junit.jupiter.api.extension.ExtendWith
+@ExtendWith(BeforeAllTests::class)
internal class GetJokesTest {
@Test
fun `Get Multiple Jokes`() {
@@ -63,7 +59,6 @@ internal class GetJokesTest {
each {
it.prop(Joke::id).isGreaterThanOrEqualTo(0)
it.prop(Joke::safe).isTrue()
- it.prop(Joke::flags).isEmpty()
it.prop(Joke::lang).isEqualTo(Language.FR)
}
}
@@ -82,20 +77,8 @@ internal class GetJokesTest {
size().isEqualTo(1)
index(0).all {
prop(Joke::id).isGreaterThanOrEqualTo(0)
- prop(Joke::flags).isEmpty()
prop(Joke::safe).isTrue()
}
}
}
-
- companion object {
- @JvmStatic
- @BeforeAll
- fun beforeAll() {
- with(logger) {
- addHandler(ConsoleHandler().apply { level = Level.FINE })
- level = Level.FINE
- }
- }
- }
}
diff --git a/src/test/kotlin/net/thauvin/erik/jokeapi/GetRawJokesTest.kt b/src/test/kotlin/net/thauvin/erik/jokeapi/GetRawJokesTest.kt
index 868c296..0c110ce 100644
--- a/src/test/kotlin/net/thauvin/erik/jokeapi/GetRawJokesTest.kt
+++ b/src/test/kotlin/net/thauvin/erik/jokeapi/GetRawJokesTest.kt
@@ -1,8 +1,7 @@
/*
* GetRawJokesTest.kt
*
- * Copyright (c) 2022, Erik C. Thauvin (erik@thauvin.net)
- * All rights reserved.
+ * Copyright 2022-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@@ -37,15 +36,13 @@ import assertk.assertThat
import assertk.assertions.doesNotContain
import assertk.assertions.isNotEmpty
import assertk.assertions.startsWith
-import net.thauvin.erik.jokeapi.JokeApi.Companion.logger
import net.thauvin.erik.jokeapi.models.Format
import net.thauvin.erik.jokeapi.models.IdRange
-import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.Test
-import java.util.logging.ConsoleHandler
-import java.util.logging.Level
+import org.junit.jupiter.api.extension.ExtendWith
import kotlin.test.assertContains
+@ExtendWith(BeforeAllTests::class)
internal class GetRawJokesTest {
@Test
fun `Get Raw Joke with TXT`() {
@@ -79,15 +76,4 @@ internal class GetRawJokesTest {
val response = getRawJokes(contains = "foo", safe = true, amount = 2, idRange = IdRange(160, 161))
assertContains(response, "\"error\": true", false, "getRawJokes(foo)")
}
-
- companion object {
- @JvmStatic
- @BeforeAll
- fun beforeAll() {
- with(logger) {
- addHandler(ConsoleHandler().apply { level = Level.FINE })
- level = Level.FINE
- }
- }
- }
}
diff --git a/src/test/kotlin/net/thauvin/erik/jokeapi/JokeConfigTest.kt b/src/test/kotlin/net/thauvin/erik/jokeapi/JokeConfigTest.kt
index 2110474..4ac0237 100644
--- a/src/test/kotlin/net/thauvin/erik/jokeapi/JokeConfigTest.kt
+++ b/src/test/kotlin/net/thauvin/erik/jokeapi/JokeConfigTest.kt
@@ -1,8 +1,7 @@
/*
* JokeConfigTest.kt
*
- * Copyright (c) 2022, Erik C. Thauvin (erik@thauvin.net)
- * All rights reserved.
+ * Copyright 2022-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@@ -53,13 +52,12 @@ import net.thauvin.erik.jokeapi.models.IdRange
import net.thauvin.erik.jokeapi.models.Joke
import net.thauvin.erik.jokeapi.models.Language
import net.thauvin.erik.jokeapi.models.Type
-import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.Test
-import java.util.logging.ConsoleHandler
-import java.util.logging.Level
+import org.junit.jupiter.api.extension.ExtendWith
import kotlin.test.assertContains
-class JokeConfigTest {
+@ExtendWith(BeforeAllTests::class)
+internal class JokeConfigTest {
@Test
fun `Get Joke with Default Builder`() {
val joke = getJoke()
@@ -181,15 +179,4 @@ class JokeConfigTest {
prop(JokeConfig::auth).isEqualTo(auth)
}
}
-
- companion object {
- @JvmStatic
- @BeforeAll
- fun beforeAll() {
- with(logger) {
- addHandler(ConsoleHandler().apply { level = Level.FINE })
- level = Level.FINE
- }
- }
- }
}
diff --git a/src/test/kotlin/net/thauvin/erik/jokeapi/UtilTest.kt b/src/test/kotlin/net/thauvin/erik/jokeapi/UtilTest.kt
index 34bbedf..cb28d1f 100644
--- a/src/test/kotlin/net/thauvin/erik/jokeapi/UtilTest.kt
+++ b/src/test/kotlin/net/thauvin/erik/jokeapi/UtilTest.kt
@@ -1,8 +1,7 @@
/*
- * FetchUrlTest.kt
+ * UtilTest.kt
*
- * Copyright (c) 2022, Erik C. Thauvin (erik@thauvin.net)
- * All rights reserved.
+ * Copyright 2022-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@@ -36,13 +35,12 @@ import assertk.assertThat
import assertk.assertions.contains
import org.json.JSONException
import org.json.JSONObject
-import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows
-import java.util.logging.ConsoleHandler
-import java.util.logging.Level
+import org.junit.jupiter.api.extension.ExtendWith
-class UtilTest {
+@ExtendWith(BeforeAllTests::class)
+internal class UtilTest {
@Test
fun `Invalid JSON Error`() {
assertThrows { parseError(JSONObject("{}")) }
@@ -59,15 +57,4 @@ class UtilTest {
val body = fetchUrl("https://postman-echo.com/get", token)
assertThat(body, "body").contains("\"authentication\":\"$token\"")
}
-
- companion object {
- @JvmStatic
- @BeforeAll
- fun beforeAll() {
- with(JokeApi.logger) {
- addHandler(ConsoleHandler().apply { level = Level.FINE })
- level = Level.FINE
- }
- }
- }
}