Compare commits

..

4 commits

Author SHA1 Message Date
88be433719 Updated copyright 2023-01-28 21:39:47 -08:00
35c1ec99ae Updated dependencies 2023-01-28 21:39:29 -08:00
7c96301dc0 Minor cleanup 2023-01-28 21:17:45 -08:00
f5ecf2d1b4 Added BeforeAllTests class 2023-01-28 21:11:32 -08:00
29 changed files with 123 additions and 183 deletions

View file

@ -1,6 +1,6 @@
<component name="CopyrightManager"> <component name="CopyrightManager">
<copyright> <copyright>
<option name="notice" value="&amp;#36;file.fileName&#10;&#10;Copyright (c) &amp;#36;today.year, Erik C. Thauvin (erik@thauvin.net)&#10;All rights reserved.&#10;&#10;Redistribution and use in source and binary forms, with or without&#10;modification, are permitted provided that the following conditions are met:&#10;&#10; Redistributions of source code must retain the above copyright notice, this&#10; list of conditions and the following disclaimer.&#10;&#10; Redistributions in binary form must reproduce the above copyright notice,&#10; this list of conditions and the following disclaimer in the documentation&#10; and/or other materials provided with the distribution.&#10;&#10; Neither the name of this project nor the names of its contributors may be&#10; used to endorse or promote products derived from this software without&#10; specific prior written permission.&#10;&#10;THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS &quot;AS IS&quot;&#10;AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE&#10;IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE&#10;DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE&#10;FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL&#10;DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR&#10;SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER&#10;CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,&#10;OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE&#10;OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." /> <option name="notice" value="&amp;#36;file.fileName&#10;&#10;Copyright 2022-&amp;#36;today.year Erik C. Thauvin (erik@thauvin.net)&#10;&#10;Redistribution and use in source and binary forms, with or without&#10;modification, are permitted provided that the following conditions are met:&#10;&#10; Redistributions of source code must retain the above copyright notice, this&#10; list of conditions and the following disclaimer.&#10;&#10; Redistributions in binary form must reproduce the above copyright notice,&#10; this list of conditions and the following disclaimer in the documentation&#10; and/or other materials provided with the distribution.&#10;&#10; Neither the name of this project nor the names of its contributors may be&#10; used to endorse or promote products derived from this software without&#10; specific prior written permission.&#10;&#10;THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS &quot;AS IS&quot;&#10;AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE&#10;IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE&#10;DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE&#10;FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL&#10;DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR&#10;SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER&#10;CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,&#10;OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE&#10;OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." />
<option name="myName" value="Erik's Copyright Notice" /> <option name="myName" value="Erik's Copyright Notice" />
</copyright> </copyright>
</component> </component>

2
.idea/kotlinc.xml generated
View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="KotlinJpsPluginSettings"> <component name="KotlinJpsPluginSettings">
<option name="version" value="1.7.20" /> <option name="version" value="1.8.0" />
</component> </component>
</project> </project>

5
.idea/misc.xml generated
View file

@ -1,7 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" /> <component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" project-jdk-name="18" project-jdk-type="JavaSDK"> <component name="PDMPlugin">
<option name="skipTestSources" value="false" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" project-jdk-name="19" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" /> <output url="file://$PROJECT_DIR$/out" />
</component> </component>
</project> </project>

View file

@ -1,5 +1,4 @@
Copyright (c) 2022, Erik C. Thauvin (erik@thauvin.net) Copyright 2022-2023 Erik C. Thauvin (erik@thauvin.net)
All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met: modification, are permitted provided that the following conditions are met:

View file

@ -1,10 +1,16 @@
[![License (3-Clause BSD)](https://img.shields.io/badge/license-BSD%203--Clause-blue.svg?style=flat-square)](https://opensource.org/licenses/BSD-3-Clause) <!-- [![Release](https://img.shields.io/github/release/ethauvin/jokeapi.svg)](https://github.com/ethauvin/jokeapi/releases/latest) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/net.thauvin.erik/jokeapi/badge.svg?color=blue)](https://maven-badges.herokuapp.com/maven-central/net.thauvin.erik/jokeapi) --> [![Nexus Snapshot](https://img.shields.io/nexus/s/net.thauvin.erik/jokeapi?server=https%3A%2F%2Foss.sonatype.org%2F)](https://oss.sonatype.org/content/repositories/snapshots/net/thauvin/erik/jokeapi/) [![License (3-Clause BSD)](https://img.shields.io/badge/license-BSD%203--Clause-blue.svg?style=flat-square)](https://opensource.org/licenses/BSD-3-Clause)
[![Kotlin](https://img.shields.io/badge/kotlin-1.8.0-blue)](https://kotlinlang.org/)
[![Nexus Snapshot](https://img.shields.io/nexus/s/net.thauvin.erik/jokeapi?label=snapshot&server=https%3A%2F%2Foss.sonatype.org%2F)](https://oss.sonatype.org/content/repositories/snapshots/net/thauvin/erik/jokeapi/)
[![Release](https://img.shields.io/github/release/ethauvin/jokeapi.svg)](https://github.com/ethauvin/jokeapi/releases/latest)
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/net.thauvin.erik/jokeapi/badge.svg?color=blue)](https://maven-badges.herokuapp.com/maven-central/net.thauvin.erik/jokeapi)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=ethauvin_jokeapi&metric=alert_status)](https://sonarcloud.io/dashboard?id=ethauvin_jokeapi) [![GitHub CI](https://github.com/ethauvin/jokeapi/actions/workflows/gradle.yml/badge.svg)](https://github.com/ethauvin/jokeapi/actions/workflows/gradle.yml) [![CircleCI](https://circleci.com/gh/ethauvin/jokeapi/tree/master.svg?style=shield)](https://circleci.com/gh/ethauvin/jokeapi/tree/master) [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=ethauvin_jokeapi&metric=alert_status)](https://sonarcloud.io/dashboard?id=ethauvin_jokeapi)
[![GitHub CI](https://github.com/ethauvin/jokeapi/actions/workflows/gradle.yml/badge.svg)](https://github.com/ethauvin/jokeapi/actions/workflows/gradle.yml)
[![CircleCI](https://circleci.com/gh/ethauvin/jokeapi/tree/master.svg?style=shield)](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) ## 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). 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 ```kotlin
data class Joke( 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)... - 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 ```kotlin
class JokeException( class JokeException(
@ -88,7 +94,7 @@ To use with [Gradle](https://gradle.org/), include the following dependency in y
```gradle ```gradle
repositories { repositories {
mavenCentral() 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 { dependencies {

View file

@ -4,18 +4,18 @@ import org.jetbrains.dokka.gradle.DokkaTask
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins { plugins {
id("com.github.ben-manes.versions") version "0.42.0" id("com.github.ben-manes.versions") version "0.44.0"
id("io.gitlab.arturbosch.detekt") version "1.21.0" id("io.gitlab.arturbosch.detekt") version "1.22.0"
id("java") id("java")
id("maven-publish") id("maven-publish")
id("org.jetbrains.dokka") version "1.7.20" id("org.jetbrains.dokka") version "1.7.20"
id("org.jetbrains.kotlinx.kover") version "0.6.1" 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") 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" group = "net.thauvin.erik"
version = "0.9-SNAPSHOT" version = "0.9-SNAPSHOT"
@ -35,14 +35,10 @@ dependencies {
implementation("org.json:json:20220924") implementation("org.json:json:20220924")
testImplementation(kotlin("test")) 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") testImplementation("com.willowtreeapps.assertk:assertk-jvm:0.25")
} }
tasks.test {
useJUnitPlatform()
}
java { java {
sourceCompatibility = JavaVersion.VERSION_11 sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11 targetCompatibility = JavaVersion.VERSION_11
@ -66,6 +62,10 @@ val javadocJar by tasks.creating(Jar::class) {
} }
tasks { tasks {
test {
useJUnitPlatform()
}
withType<KotlinCompile>().configureEach { withType<KotlinCompile>().configureEach {
kotlinOptions.jvmTarget = java.targetCompatibility.toString() kotlinOptions.jvmTarget = java.targetCompatibility.toString()
} }
@ -141,8 +141,8 @@ publishing {
} }
} }
scm { scm {
connection.set("scm:git:git://github.com/$gitHub.git") connection.set("scm:git://github.com/$gitHub.git")
developerConnection.set("scm:git:git@github.com:$gitHub.git") developerConnection.set("scm:git@github.com:$gitHub.git")
url.set(mavenUrl) url.set(mavenUrl)
} }
issueManagement { issueManagement {

View file

@ -2,7 +2,6 @@
<SmellBaseline> <SmellBaseline>
<ManuallySuppressedIssues/> <ManuallySuppressedIssues/>
<CurrentIssues> <CurrentIssues>
<ID>ComplexMethod:JokeApi.kt$fun getRawJokes( categories: Set&lt;Category> = setOf(Category.ANY), lang: Language = Language.EN, blacklistFlags: Set&lt;Flag> = emptySet(), type: Type = Type.ALL, format: Format = Format.JSON, contains: String = "", idRange: IdRange = IdRange(), amount: Int = 1, safe: Boolean = false, auth: String = "" ): String</ID>
<ID>LongParameterList:JokeApi.kt$( amount: Int, categories: Set&lt;Category> = setOf(Category.ANY), lang: Language = Language.EN, blacklistFlags: Set&lt;Flag> = emptySet(), type: Type = Type.ALL, contains: String = "", idRange: IdRange = IdRange(), safe: Boolean = false, auth: String = "", splitNewLine: Boolean = false )</ID> <ID>LongParameterList:JokeApi.kt$( amount: Int, categories: Set&lt;Category> = setOf(Category.ANY), lang: Language = Language.EN, blacklistFlags: Set&lt;Flag> = emptySet(), type: Type = Type.ALL, contains: String = "", idRange: IdRange = IdRange(), safe: Boolean = false, auth: String = "", splitNewLine: Boolean = false )</ID>
<ID>LongParameterList:JokeApi.kt$( categories: Set&lt;Category> = setOf(Category.ANY), lang: Language = Language.EN, blacklistFlags: Set&lt;Flag> = emptySet(), type: Type = Type.ALL, contains: String = "", idRange: IdRange = IdRange(), safe: Boolean = false, auth: String = "", splitNewLine: Boolean = false )</ID> <ID>LongParameterList:JokeApi.kt$( categories: Set&lt;Category> = setOf(Category.ANY), lang: Language = Language.EN, blacklistFlags: Set&lt;Flag> = emptySet(), type: Type = Type.ALL, contains: String = "", idRange: IdRange = IdRange(), safe: Boolean = false, auth: String = "", splitNewLine: Boolean = false )</ID>
<ID>LongParameterList:JokeApi.kt$( categories: Set&lt;Category> = setOf(Category.ANY), lang: Language = Language.EN, blacklistFlags: Set&lt;Flag> = emptySet(), type: Type = Type.ALL, format: Format = Format.JSON, contains: String = "", idRange: IdRange = IdRange(), amount: Int = 1, safe: Boolean = false, auth: String = "" )</ID> <ID>LongParameterList:JokeApi.kt$( categories: Set&lt;Category> = setOf(Category.ANY), lang: Language = Language.EN, blacklistFlags: Set&lt;Flag> = emptySet(), type: Type = Type.ALL, format: Format = Format.JSON, contains: String = "", idRange: IdRange = IdRange(), amount: Int = 1, safe: Boolean = false, auth: String = "" )</ID>
@ -19,6 +18,5 @@
<ID>MagicNumber:util.kt$500</ID> <ID>MagicNumber:util.kt$500</ID>
<ID>MagicNumber:util.kt$523</ID> <ID>MagicNumber:util.kt$523</ID>
<ID>TooManyFunctions:JokeConfig.kt$JokeConfig$Builder</ID> <ID>TooManyFunctions:JokeConfig.kt$JokeConfig$Builder</ID>
<ID>UnusedPrivateMember:JokeConfig.kt$JokeConfig.Builder$search: String</ID>
</CurrentIssues> </CurrentIssues>
</SmellBaseline> </SmellBaseline>

View file

@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists 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 zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists

View file

@ -1,8 +1,7 @@
/* /*
* JokeApi.kt * JokeApi.kt
* *
* Copyright (c) 2022, Erik C. Thauvin (erik@thauvin.net) * Copyright 2022-2023 Erik C. Thauvin (erik@thauvin.net)
* All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
@ -311,18 +310,16 @@ fun getRawJokes(
if (idRange.start >= 0) { if (idRange.start >= 0) {
if (idRange.end == -1 || idRange.start == idRange.end) { if (idRange.end == -1 || idRange.start == idRange.end) {
params[Parameter.RANGE] = idRange.start.toString() params[Parameter.RANGE] = idRange.start.toString()
} else if (idRange.end > idRange.start) {
params[Parameter.RANGE] = "${idRange.start}-${idRange.end}"
} else { } 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 // Amount
require(amount > 0) { "Invalid Amount: $amount" }
if (amount > 1) { if (amount > 1) {
params[Parameter.AMOUNT] = amount.toString() params[Parameter.AMOUNT] = amount.toString()
} else if (amount <= 0) {
throw IllegalArgumentException("Invalid Amount: $amount")
} }
// Safe // Safe

View file

@ -1,8 +1,7 @@
/* /*
* Configuration.kt * JokeConfig.kt
* *
* Copyright (c) 2022, Erik C. Thauvin (erik@thauvin.net) * Copyright 2022-2023 Erik C. Thauvin (erik@thauvin.net)
* All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:

View file

@ -1,8 +1,7 @@
/* /*
* HttpErrorException.kt * HttpErrorException.kt
* *
* Copyright (c) 2022, Erik C. Thauvin (erik@thauvin.net) * Copyright 2022-2023 Erik C. Thauvin (erik@thauvin.net)
* All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:

View file

@ -1,8 +1,7 @@
/* /*
* JokeException.kt * JokeException.kt
* *
* Copyright (c) 2022, Erik C. Thauvin (erik@thauvin.net) * Copyright 2022-2023 Erik C. Thauvin (erik@thauvin.net)
* All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:

View file

@ -1,8 +1,7 @@
/* /*
* Category.kt * Category.kt
* *
* Copyright (c) 2022, Erik C. Thauvin (erik@thauvin.net) * Copyright 2022-2023 Erik C. Thauvin (erik@thauvin.net)
* All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:

View file

@ -1,8 +1,7 @@
/* /*
* Flag.kt * Flag.kt
* *
* Copyright (c) 2022, Erik C. Thauvin (erik@thauvin.net) * Copyright 2022-2023 Erik C. Thauvin (erik@thauvin.net)
* All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:

View file

@ -1,8 +1,7 @@
/* /*
* Format.kt * Format.kt
* *
* Copyright (c) 2022, Erik C. Thauvin (erik@thauvin.net) * Copyright 2022-2023 Erik C. Thauvin (erik@thauvin.net)
* All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:

View file

@ -1,8 +1,7 @@
/* /*
* IdRange.kt * IdRange.kt
* *
* Copyright (c) 2022, Erik C. Thauvin (erik@thauvin.net) * Copyright 2022-2023 Erik C. Thauvin (erik@thauvin.net)
* All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:

View file

@ -1,8 +1,7 @@
/* /*
* Joke.kt * Joke.kt
* *
* Copyright (c) 2022, Erik C. Thauvin (erik@thauvin.net) * Copyright 2022-2023 Erik C. Thauvin (erik@thauvin.net)
* All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:

View file

@ -1,8 +1,7 @@
/* /*
* Language.kt * Language.kt
* *
* Copyright (c) 2022, Erik C. Thauvin (erik@thauvin.net) * Copyright 2022-2023 Erik C. Thauvin (erik@thauvin.net)
* All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:

View file

@ -1,8 +1,7 @@
/* /*
* Parameter.kt * Parameter.kt
* *
* Copyright (c) 2022, Erik C. Thauvin (erik@thauvin.net) * Copyright 2022-2023 Erik C. Thauvin (erik@thauvin.net)
* All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:

View file

@ -1,8 +1,7 @@
/* /*
* Type.kt * Type.kt
* *
* Copyright (c) 2022, Erik C. Thauvin (erik@thauvin.net) * Copyright 2022-2023 Erik C. Thauvin (erik@thauvin.net)
* All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:

View file

@ -1,8 +1,7 @@
/* /*
* util.kt * util.kt
* *
* Copyright (c) 2022, Erik C. Thauvin (erik@thauvin.net) * Copyright 2022-2023 Erik C. Thauvin (erik@thauvin.net)
* All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:

View file

@ -1,8 +1,7 @@
/* /*
* ApiCallTest.kt * ApiCallTest.kt
* *
* Copyright (c) 2022, Erik C. Thauvin (erik@thauvin.net) * Copyright 2022-2023 Erik C. Thauvin (erik@thauvin.net)
* All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
@ -36,18 +35,16 @@ import assertk.assertThat
import assertk.assertions.isGreaterThan import assertk.assertions.isGreaterThan
import assertk.assertions.startsWith import assertk.assertions.startsWith
import net.thauvin.erik.jokeapi.JokeApi.Companion.apiCall 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.Format
import net.thauvin.erik.jokeapi.models.Parameter import net.thauvin.erik.jokeapi.models.Parameter
import org.json.JSONObject import org.json.JSONObject
import org.junit.jupiter.api.Assertions.assertFalse import org.junit.jupiter.api.Assertions.assertFalse
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertAll import org.junit.jupiter.api.assertAll
import java.util.logging.ConsoleHandler import org.junit.jupiter.api.extension.ExtendWith
import java.util.logging.Level
import kotlin.test.assertContains import kotlin.test.assertContains
@ExtendWith(BeforeAllTests::class)
internal class ApiCallTest { internal class ApiCallTest {
@Test @Test
fun `Get Flags`() { fun `Get Flags`() {
@ -76,15 +73,4 @@ internal class ApiCallTest {
val ping = apiCall(endPoint = "ping", params = mapOf(Parameter.FORMAT to Format.TXT.value)) val ping = apiCall(endPoint = "ping", params = mapOf(Parameter.FORMAT to Format.TXT.value))
assertThat(ping, "apiCall(ping, txt)").startsWith("Pong!") assertThat(ping, "apiCall(ping, txt)").startsWith("Pong!")
} }
companion object {
@JvmStatic
@BeforeAll
fun beforeAll() {
with(logger) {
addHandler(ConsoleHandler().apply { level = Level.FINE })
level = Level.FINE
}
}
}
} }

View file

@ -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
}
}
}

View file

@ -1,8 +1,7 @@
/* /*
* ExceptionsTest.kt * ExceptionsTest.kt
* *
* Copyright (c) 2022, Erik C. Thauvin (erik@thauvin.net) * Copyright 2022-2023 Erik C. Thauvin (erik@thauvin.net)
* All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * 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.HttpErrorException
import net.thauvin.erik.jokeapi.exceptions.JokeException import net.thauvin.erik.jokeapi.exceptions.JokeException
import net.thauvin.erik.jokeapi.models.Category import net.thauvin.erik.jokeapi.models.Category
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows import org.junit.jupiter.api.assertThrows
import org.junit.jupiter.api.extension.ExtendWith
import org.junit.jupiter.params.ParameterizedTest import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.ValueSource import org.junit.jupiter.params.provider.ValueSource
import java.util.logging.ConsoleHandler
import java.util.logging.Level
@ExtendWith(BeforeAllTests::class)
internal class ExceptionsTest { internal class ExceptionsTest {
@Test @Test
fun `Validate Joke Exception`() { fun `Validate Joke Exception`() {
@ -89,15 +87,4 @@ internal class ExceptionsTest {
prop(HttpErrorException::cause).isNull() prop(HttpErrorException::cause).isNull()
} }
} }
companion object {
@JvmStatic
@BeforeAll
fun beforeAll() {
with(logger) {
addHandler(ConsoleHandler().apply { level = Level.FINE })
level = Level.FINE
}
}
}
} }

View file

@ -1,8 +1,7 @@
/* /*
* GetJokeTest.kt * GetJokeTest.kt
* *
* Copyright (c) 2022, Erik C. Thauvin (erik@thauvin.net) * Copyright 2022-2023 Erik C. Thauvin (erik@thauvin.net)
* All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * 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.Joke
import net.thauvin.erik.jokeapi.models.Language import net.thauvin.erik.jokeapi.models.Language
import net.thauvin.erik.jokeapi.models.Type import net.thauvin.erik.jokeapi.models.Type
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows import org.junit.jupiter.api.assertThrows
import java.util.logging.ConsoleHandler import org.junit.jupiter.api.extension.ExtendWith
import java.util.logging.Level
@ExtendWith(BeforeAllTests::class)
internal class GetJokeTest { internal class GetJokeTest {
@Test @Test
fun `Get Joke`() { fun `Get Joke`() {
@ -176,7 +174,6 @@ internal class GetJokeTest {
logger.fine(joke.toString()) logger.fine(joke.toString())
assertThat(joke, "getJoke(safe)").all { assertThat(joke, "getJoke(safe)").all {
prop(Joke::safe).isTrue() 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
}
}
}
} }

View file

@ -1,8 +1,7 @@
/* /*
* GetJokeTests.kt * GetJokesTest.kt
* *
* Copyright (c) 2022, Erik C. Thauvin (erik@thauvin.net) * Copyright 2022-2023 Erik C. Thauvin (erik@thauvin.net)
* All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
@ -37,22 +36,19 @@ import assertk.assertThat
import assertk.assertions.contains import assertk.assertions.contains
import assertk.assertions.each import assertk.assertions.each
import assertk.assertions.index import assertk.assertions.index
import assertk.assertions.isEmpty
import assertk.assertions.isEqualTo import assertk.assertions.isEqualTo
import assertk.assertions.isGreaterThanOrEqualTo import assertk.assertions.isGreaterThanOrEqualTo
import assertk.assertions.isNotNull import assertk.assertions.isNotNull
import assertk.assertions.isTrue import assertk.assertions.isTrue
import assertk.assertions.prop import assertk.assertions.prop
import assertk.assertions.size 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.Joke
import net.thauvin.erik.jokeapi.models.Language import net.thauvin.erik.jokeapi.models.Language
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows import org.junit.jupiter.api.assertThrows
import java.util.logging.ConsoleHandler import org.junit.jupiter.api.extension.ExtendWith
import java.util.logging.Level
@ExtendWith(BeforeAllTests::class)
internal class GetJokesTest { internal class GetJokesTest {
@Test @Test
fun `Get Multiple Jokes`() { fun `Get Multiple Jokes`() {
@ -63,7 +59,6 @@ internal class GetJokesTest {
each { each {
it.prop(Joke::id).isGreaterThanOrEqualTo(0) it.prop(Joke::id).isGreaterThanOrEqualTo(0)
it.prop(Joke::safe).isTrue() it.prop(Joke::safe).isTrue()
it.prop(Joke::flags).isEmpty()
it.prop(Joke::lang).isEqualTo(Language.FR) it.prop(Joke::lang).isEqualTo(Language.FR)
} }
} }
@ -82,20 +77,8 @@ internal class GetJokesTest {
size().isEqualTo(1) size().isEqualTo(1)
index(0).all { index(0).all {
prop(Joke::id).isGreaterThanOrEqualTo(0) prop(Joke::id).isGreaterThanOrEqualTo(0)
prop(Joke::flags).isEmpty()
prop(Joke::safe).isTrue() prop(Joke::safe).isTrue()
} }
} }
} }
companion object {
@JvmStatic
@BeforeAll
fun beforeAll() {
with(logger) {
addHandler(ConsoleHandler().apply { level = Level.FINE })
level = Level.FINE
}
}
}
} }

View file

@ -1,8 +1,7 @@
/* /*
* GetRawJokesTest.kt * GetRawJokesTest.kt
* *
* Copyright (c) 2022, Erik C. Thauvin (erik@thauvin.net) * Copyright 2022-2023 Erik C. Thauvin (erik@thauvin.net)
* All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
@ -37,15 +36,13 @@ import assertk.assertThat
import assertk.assertions.doesNotContain import assertk.assertions.doesNotContain
import assertk.assertions.isNotEmpty import assertk.assertions.isNotEmpty
import assertk.assertions.startsWith 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.Format
import net.thauvin.erik.jokeapi.models.IdRange import net.thauvin.erik.jokeapi.models.IdRange
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import java.util.logging.ConsoleHandler import org.junit.jupiter.api.extension.ExtendWith
import java.util.logging.Level
import kotlin.test.assertContains import kotlin.test.assertContains
@ExtendWith(BeforeAllTests::class)
internal class GetRawJokesTest { internal class GetRawJokesTest {
@Test @Test
fun `Get Raw Joke with TXT`() { 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)) val response = getRawJokes(contains = "foo", safe = true, amount = 2, idRange = IdRange(160, 161))
assertContains(response, "\"error\": true", false, "getRawJokes(foo)") assertContains(response, "\"error\": true", false, "getRawJokes(foo)")
} }
companion object {
@JvmStatic
@BeforeAll
fun beforeAll() {
with(logger) {
addHandler(ConsoleHandler().apply { level = Level.FINE })
level = Level.FINE
}
}
}
} }

View file

@ -1,8 +1,7 @@
/* /*
* JokeConfigTest.kt * JokeConfigTest.kt
* *
* Copyright (c) 2022, Erik C. Thauvin (erik@thauvin.net) * Copyright 2022-2023 Erik C. Thauvin (erik@thauvin.net)
* All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * 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.Joke
import net.thauvin.erik.jokeapi.models.Language import net.thauvin.erik.jokeapi.models.Language
import net.thauvin.erik.jokeapi.models.Type import net.thauvin.erik.jokeapi.models.Type
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import java.util.logging.ConsoleHandler import org.junit.jupiter.api.extension.ExtendWith
import java.util.logging.Level
import kotlin.test.assertContains import kotlin.test.assertContains
class JokeConfigTest { @ExtendWith(BeforeAllTests::class)
internal class JokeConfigTest {
@Test @Test
fun `Get Joke with Default Builder`() { fun `Get Joke with Default Builder`() {
val joke = getJoke() val joke = getJoke()
@ -181,15 +179,4 @@ class JokeConfigTest {
prop(JokeConfig::auth).isEqualTo(auth) prop(JokeConfig::auth).isEqualTo(auth)
} }
} }
companion object {
@JvmStatic
@BeforeAll
fun beforeAll() {
with(logger) {
addHandler(ConsoleHandler().apply { level = Level.FINE })
level = Level.FINE
}
}
}
} }

View file

@ -1,8 +1,7 @@
/* /*
* FetchUrlTest.kt * UtilTest.kt
* *
* Copyright (c) 2022, Erik C. Thauvin (erik@thauvin.net) * Copyright 2022-2023 Erik C. Thauvin (erik@thauvin.net)
* All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
@ -36,13 +35,12 @@ import assertk.assertThat
import assertk.assertions.contains import assertk.assertions.contains
import org.json.JSONException import org.json.JSONException
import org.json.JSONObject import org.json.JSONObject
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows import org.junit.jupiter.api.assertThrows
import java.util.logging.ConsoleHandler import org.junit.jupiter.api.extension.ExtendWith
import java.util.logging.Level
class UtilTest { @ExtendWith(BeforeAllTests::class)
internal class UtilTest {
@Test @Test
fun `Invalid JSON Error`() { fun `Invalid JSON Error`() {
assertThrows<JSONException> { parseError(JSONObject("{}")) } assertThrows<JSONException> { parseError(JSONObject("{}")) }
@ -59,15 +57,4 @@ class UtilTest {
val body = fetchUrl("https://postman-echo.com/get", token) val body = fetchUrl("https://postman-echo.com/get", token)
assertThat(body, "body").contains("\"authentication\":\"$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
}
}
}
} }