diff --git a/.circleci/config.yml b/.circleci/config.yml index 8dabc3f..77889be 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,8 +1,4 @@ -version: 2.1 - -orbs: - sdkman: joshdholtz/sdkman@0.2.0 - +version: 2 defaults: &defaults working_directory: ~/repo environment: @@ -10,31 +6,18 @@ defaults: &defaults TERM: dumb CI_NAME: "CircleCI" -commands: - build_and_test: - parameters: - reports-dir: - type: string - default: "build/reports/test_results" - steps: - - checkout - - sdkman/setup-sdkman - - sdkman/sdkman-install: - candidate: kotlin - version: 2.0.20 - - run: - name: Download dependencies - command: ./bld download - - run: - name: Compile source - command: ./bld compile - - run: - name: Run tests - command: ./bld jacoco -reports-dir=<< parameters.reports-dir >> - - store_test_results: - path: << parameters.reports-dir >> - - store_artifacts: - path: build/reports/jacoco/test/html +defaults_gradle: &defaults_bld + steps: + - checkout + - run: + name: Download the bld dependencies + command: ./bld download + - run: + name: Compile source with bld + command: ./bld compile + - run: + name: Run tests with bld + command: ./bld test jobs: bld_jdk17: @@ -43,8 +26,7 @@ jobs: docker: - image: cimg/openjdk:17.0 - steps: - - build_and_test + <<: *defaults_bld bld_jdk20: <<: *defaults @@ -52,10 +34,10 @@ jobs: docker: - image: cimg/openjdk:20.0 - steps: - - build_and_test + <<: *defaults_bld workflows: + version: 2 bld: jobs: - bld_jdk17 diff --git a/.github/workflows/bld.yml b/.github/workflows/bld.yml index 007e63a..ba51eb1 100644 --- a/.github/workflows/bld.yml +++ b/.github/workflows/bld.yml @@ -2,50 +2,48 @@ name: bld-ci on: [ push, pull_request, workflow_dispatch ] -env: - COVERAGE_JDK: "21" - COVERAGE_KOTLIN: "2.1.20" - jobs: build-bld-project: + runs-on: ubuntu-latest + + env: + COVERAGE_SDK: "17" + strategy: matrix: - java-version: [ 17, 21, 24 ] - kotlin-version: [ 1.9.25, 2.0.21, 2.1.20 ] - os: [ ubuntu-latest, windows-latest, macos-latest ] - - runs-on: ${{ matrix.os }} + java-version: [ 17, 20 ] steps: - name: Checkout source repository - uses: actions/checkout@v4 + uses: actions/checkout@v3 with: fetch-depth: 0 - - name: Set up JDK ${{ matrix.java-version }} with Kotlin ${{ matrix.kotlin-version }} - uses: actions/setup-java@v4 + - name: Set up JDK ${{ matrix.java-version }} + uses: actions/setup-java@v3 with: - distribution: "zulu" + distribution: 'zulu' java-version: ${{ matrix.java-version }} - - name: Download dependencies + - name: Grant bld execute permission + run: chmod +x bld + + - name: Download the bld dependencies run: ./bld download - - name: Compile source + - name: Compile source with bld run: ./bld compile - - name: Run tests + - name: Run tests with bld run: ./bld jacoco - name: Remove pom.xml - if: success() && matrix.java-version == env.COVERAGE_JDK && matrix.kotlin-version == env.COVERAGE_KOTLIN - && matrix.os == 'ubuntu-latest' + if: success() && matrix.java-version == env.COVERAGE_SDK run: rm -rf pom.xml - name: SonarCloud Scan uses: sonarsource/sonarcloud-github-action@master - if: success() && matrix.java-version == env.COVERAGE_JDK && matrix.kotlin-version == env.COVERAGE_KOTLIN - && matrix.os == 'ubuntu-latest' + if: success() && matrix.java-version == env.COVERAGE_SDK env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} diff --git a/.idea/bld.xml b/.idea/bld.xml deleted file mode 100644 index 6600cee..0000000 --- a/.idea/bld.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/intellij-javadocs-4.0.1.xml b/.idea/intellij-javadocs-4.0.1.xml deleted file mode 100644 index 4b17413..0000000 --- a/.idea/intellij-javadocs-4.0.1.xml +++ /dev/null @@ -1,204 +0,0 @@ - - - - - UPDATE - false - true - - TYPE - METHOD - FIELD - - - DEFAULT - PROTECTED - PUBLIC - - - - - - ^.*(public|protected|private)*.+interface\s+\w+.* - /**\n - * The interface ${name}.\n -<#if element.typeParameters?has_content> * \n -</#if> -<#list element.typeParameters as typeParameter> - * @param <${typeParameter.name}> the type parameter\n -</#list> - */ - - - ^.*(public|protected|private)*.+enum\s+\w+.* - /**\n - * The enum ${name}.\n - */ - - - ^.*(public|protected|private)*.+class\s+\w+.* - /**\n - * The type ${name}.\n -<#if element.typeParameters?has_content> * \n -</#if> -<#list element.typeParameters as typeParameter> - * @param <${typeParameter.name}> the type parameter\n -</#list> - */ - - - .+ - /**\n - * The type ${name}.\n - */ - - - - - .+ - /**\n - * Instantiates a new ${name}.\n -<#if element.parameterList.parameters?has_content> - *\n -</#if> -<#list element.parameterList.parameters as parameter> - * @param ${parameter.name} the ${paramNames[parameter.name]}\n -</#list> -<#if element.throwsList.referenceElements?has_content> - *\n -</#if> -<#list element.throwsList.referenceElements as exception> - * @throws ${exception.referenceName} the ${exceptionNames[exception.referenceName]}\n -</#list> - */ - - - - - ^.*(public|protected|private)*\s*.*(\w(\s*<.+>)*)+\s+get\w+\s*\(.*\).+ - /**\n - * Gets ${partName}.\n -<#if element.typeParameters?has_content> * \n -</#if> -<#list element.typeParameters as typeParameter> - * @param <${typeParameter.name}> the type parameter\n -</#list> -<#if element.parameterList.parameters?has_content> - *\n -</#if> -<#list element.parameterList.parameters as parameter> - * @param ${parameter.name} the ${paramNames[parameter.name]}\n -</#list> -<#if isNotVoid> - *\n - * @return the ${partName}\n -</#if> -<#if element.throwsList.referenceElements?has_content> - *\n -</#if> -<#list element.throwsList.referenceElements as exception> - * @throws ${exception.referenceName} the ${exceptionNames[exception.referenceName]}\n -</#list> - */ - - - ^.*(public|protected|private)*\s*.*(void|\w(\s*<.+>)*)+\s+set\w+\s*\(.*\).+ - /**\n - * Sets ${partName}.\n -<#if element.typeParameters?has_content> * \n -</#if> -<#list element.typeParameters as typeParameter> - * @param <${typeParameter.name}> the type parameter\n -</#list> -<#if element.parameterList.parameters?has_content> - *\n -</#if> -<#list element.parameterList.parameters as parameter> - * @param ${parameter.name} the ${paramNames[parameter.name]}\n -</#list> -<#if isNotVoid> - *\n - * @return the ${partName}\n -</#if> -<#if element.throwsList.referenceElements?has_content> - *\n -</#if> -<#list element.throwsList.referenceElements as exception> - * @throws ${exception.referenceName} the ${exceptionNames[exception.referenceName]}\n -</#list> - */ - - - ^.*((public\s+static)|(static\s+public))\s+void\s+main\s*\(\s*String\s*(\[\s*\]|\.\.\.)\s+\w+\s*\).+ - /**\n - * The entry point of application.\n - - <#if element.parameterList.parameters?has_content> - *\n -</#if> - * @param ${element.parameterList.parameters[0].name} the input arguments\n -<#if element.throwsList.referenceElements?has_content> - *\n -</#if> -<#list element.throwsList.referenceElements as exception> - * @throws ${exception.referenceName} the ${exceptionNames[exception.referenceName]}\n -</#list> - */ - - - .+ - /**\n - * ${name}<#if isNotVoid> ${return}</#if>.\n -<#if element.typeParameters?has_content> * \n -</#if> -<#list element.typeParameters as typeParameter> - * @param <${typeParameter.name}> the type parameter\n -</#list> -<#if element.parameterList.parameters?has_content> - *\n -</#if> -<#list element.parameterList.parameters as parameter> - * @param ${parameter.name} the ${paramNames[parameter.name]}\n -</#list> -<#if isNotVoid> - *\n - * @return the ${return}\n -</#if> -<#if element.throwsList.referenceElements?has_content> - *\n -</#if> -<#list element.throwsList.referenceElements as exception> - * @throws ${exception.referenceName} the ${exceptionNames[exception.referenceName]}\n -</#list> - */ - - - - - ^.*(public|protected|private)*.+static.*(\w\s\w)+.+ - /**\n - * The constant ${element.getName()}.\n - */ - - - ^.*(public|protected|private)*.*(\w\s\w)+.+ - /**\n - <#if element.parent.isInterface()> - * The constant ${element.getName()}.\n -<#else> - * The ${name}.\n -</#if> */ - - - .+ - /**\n - <#if element.parent.isEnum()> - *${name} ${typeName}.\n -<#else> - * The ${name}.\n -</#if>*/ - - - - - \ No newline at end of file diff --git a/.idea/kotlinc.xml b/.idea/kotlinc.xml index a8d9757..f8467b4 100644 --- a/.idea/kotlinc.xml +++ b/.idea/kotlinc.xml @@ -1,6 +1,6 @@ - - + \ No newline at end of file diff --git a/.idea/libraries/bld.xml b/.idea/libraries/bld.xml index 153a060..ca84ff0 100644 --- a/.idea/libraries/bld.xml +++ b/.idea/libraries/bld.xml @@ -2,12 +2,12 @@ - + - + diff --git a/.idea/libraries/compile.xml b/.idea/libraries/compile.xml index 99cc0c0..9bd86aa 100644 --- a/.idea/libraries/compile.xml +++ b/.idea/libraries/compile.xml @@ -7,7 +7,7 @@ - - + + \ No newline at end of file diff --git a/.idea/libraries/runtime.xml b/.idea/libraries/runtime.xml index d4069f2..2ae5c4b 100644 --- a/.idea/libraries/runtime.xml +++ b/.idea/libraries/runtime.xml @@ -8,7 +8,7 @@ - - + + \ No newline at end of file diff --git a/.idea/libraries/test.xml b/.idea/libraries/test.xml index 57ed5ef..b80486a 100644 --- a/.idea/libraries/test.xml +++ b/.idea/libraries/test.xml @@ -8,7 +8,7 @@ - - + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index f2b4c1e..7408350 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,19 +1,21 @@ - - - - - - - - - - - - + + + + diff --git a/.idea/runConfigurations/Run Tests.xml b/.idea/runConfigurations/Run Tests.xml new file mode 100644 index 0000000..df4d7d6 --- /dev/null +++ b/.idea/runConfigurations/Run Tests.xml @@ -0,0 +1,9 @@ + + + + \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..9f84d53 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,11 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "type": "java", + "name": "Run Tests", + "request": "launch", + "mainClass": "net.thauvin.erik.JokeapiTest" + } + ] +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..133aa45 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,15 @@ +{ + "java.project.sourcePaths": [ + "src/main/java", + "src/main/resources", + "src/test/java", + "src/bld/java" + ], + "java.configuration.updateBuildConfiguration": "automatic", + "java.project.referencedLibraries": [ + "${HOME}/.bld/dist/bld-1.7.5.jar", + "lib/compile/*.jar", + "lib/runtime/*.jar", + "lib/test/*.jar" + ] +} diff --git a/LICENSE.txt b/LICENSE.txt index 82ecd17..4331a4d 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,4 +1,4 @@ -Copyright 2022-2025 Erik C. Thauvin (erik@thauvin.net) +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 bb86972..5308277 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,5 @@ [![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-2.1.20-7f52ff)](https://kotlinlang.org/) -[![bld](https://img.shields.io/badge/2.2.1-FA9052?label=bld&labelColor=2392FF)](https://rife2.com/bld) +[![Kotlin](https://img.shields.io/badge/kotlin-1.9.21-7f52ff)](https://kotlinlang.org/) [![Release](https://img.shields.io/github/release/ethauvin/jokeapi.svg)](https://github.com/ethauvin/jokeapi/releases/latest) [![Maven Central](https://img.shields.io/maven-central/v/net.thauvin.erik/jokeapi?color=blue)](https://central.sonatype.com/artifact/net.thauvin.erik/jokeapi) [![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/) @@ -16,7 +15,7 @@ A simple library to retrieve jokes from [Sv443's JokeAPI](https://v2.jokeapi.dev ## Examples (TL;DR) ```kotlin -import net.thauvin.erik.jokeapi.joke +import net.thauvin.erik.jokeapi.getJoke val joke = joke() val safe = joke(safe = true) @@ -95,10 +94,10 @@ joke.getJoke().forEach(System.out::println); To use with [bld](https://rife2.com/bld), include the following dependency in your build file: ```java -repositories = List.of(MAVEN_CENTRAL, SONATYPE_SNAPSHOTS_LEGACY); +repositories = List.of(MAVEN_CENTRAL); scope(compile) - .include(dependency("net.thauvin.erik", "jokeapi", "1.0.0")); + .include(dependency("net.thauvin.erik:cryptoprice:1.0.1")); ``` Be sure to use the [bld Kotlin extension](https://github.com/rife2/bld-kotlin) in your project. @@ -112,7 +111,7 @@ repositories { } dependencies { - implementation("net.thauvin.erik:jokeapi:1.0.0") + implementation("net.thauvin.erik:jokeapi:0.9.0") } ``` @@ -124,10 +123,9 @@ You can also retrieve one or more raw (unprocessed) jokes in all [supported form For example for YAML: ```kotlin -var jokes = getRawJokes(format = Format.YAML, idRange = IdRange(22)) -println(jokes.data) +var joke = getRawJokes(format = Format.YAML, idRange = IdRange(22)) +println(joke) ``` - ```yaml error: false category: "Programming" @@ -143,8 +141,8 @@ flags: id: 22 safe: true lang: "en" -``` +``` - View more [examples](https://github.com/ethauvin/jokeapi/blob/master/src/test/kotlin/net/thauvin/erik/jokeapi/GetRawJokesTest.kt#L46)... ## Extending @@ -154,37 +152,15 @@ A generic `apiCall()` function is available to access other [JokeAPI endpoints]( For example to retrieve the French [language code](https://v2.jokeapi.dev/#langcode-endpoint): ```kotlin -val response = JokeApi.apiCall( +val lang = JokeApi.apiCall( endPoint = "langcode", path = "french", params = mapOf(Parameter.FORMAT to Format.YAML.value) ) -if (response.statusCode == 200) { - println(response.data) -} +println(lang) ``` - ```yaml error: false code: "fr" ``` - View more [examples](https://github.com/ethauvin/jokeapi/blob/master/src/test/kotlin/net/thauvin/erik/jokeapi/ApiCallTest.kt#L48)... - -## Contributing - -If you want to contribute to this project, all you have to do is clone the GitHub -repository: - -```console -git clone git@github.com:ethauvin/jokeapi.git -``` - -Then use [bld](https://rife2.com/bld) to build: - -```console -cd jokeapi -./bld compile -``` - -The project has an [IntelliJ IDEA](https://www.jetbrains.com/idea/) project structure. You can just open it after all -the dependencies were downloaded and peruse the code. diff --git a/detekt-baseline.xml b/detekt-baseline.xml index 1a99819..50acbf1 100644 --- a/detekt-baseline.xml +++ b/detekt-baseline.xml @@ -1,12 +1,12 @@ - + - + - LongParameterList: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 = "" ) - LongParameterList:JokeConfig.kt$JokeConfig$( val categories: Set<Category>, val language: Language, val flags: Set<Flag>, val type: Type, val format: Format, val contains: String, val idRange: IdRange, val amount: Int, val safe: Boolean, val splitNewLine: Boolean, val auth: String ) - LongParameterList:JokeException.kt$JokeException$( val internalError: Boolean, val code: Int, message: String, val causedBy: List<String>, val additionalInfo: String, val timestamp: Long, cause: Throwable? = null ) + LongParameterList: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 = "" ) + LongParameterList:JokeConfig.kt$JokeConfig$( val categories: Set<Category>, val language: Language, val flags: Set<Flag>, val type: Type, val format: Format, val contains: String, val idRange: IdRange, val amount: Int, val safe: Boolean, val splitNewLine: Boolean, val auth: String ) + LongParameterList:JokeException.kt$JokeException$( val internalError: Boolean, val code: Int, message: String, val causedBy: List<String>, val additionalInfo: String, val timestamp: Long, cause: Throwable? = null ) MagicNumber:JokeUtil.kt$200 MagicNumber:JokeUtil.kt$399 MagicNumber:JokeUtil.kt$400 @@ -22,7 +22,6 @@ WildcardImport:GetJokeTest.kt$import assertk.assertions.* WildcardImport:GetJokeTest.kt$import net.thauvin.erik.jokeapi.models.* WildcardImport:GetJokesTest.kt$import assertk.assertions.* - WildcardImport:GetRawJokesTest.kt$import assertk.assertions.* WildcardImport:JokeApi.kt$import net.thauvin.erik.jokeapi.models.* WildcardImport:JokeConfig.kt$import net.thauvin.erik.jokeapi.models.* WildcardImport:JokeConfigTest.kt$import assertk.assertions.* diff --git a/lib/bld/bld-wrapper.jar b/lib/bld/bld-wrapper.jar index 1eb86cf..431fce9 100644 Binary files a/lib/bld/bld-wrapper.jar and b/lib/bld/bld-wrapper.jar differ diff --git a/lib/bld/bld-wrapper.properties b/lib/bld/bld-wrapper.properties index 751133d..d2d7adf 100644 --- a/lib/bld/bld-wrapper.properties +++ b/lib/bld/bld-wrapper.properties @@ -1,10 +1,9 @@ bld.downloadExtensionJavadoc=false bld.downloadExtensionSources=true -bld.downloadLocation= -bld.extension-detekt=com.uwyn.rife2:bld-detekt:0.9.10-SNAPSHOT -bld.extension-dokka=com.uwyn.rife2:bld-dokka:1.0.4-SNAPSHOT -bld.extension-jacoco=com.uwyn.rife2:bld-jacoco-report:0.9.10 -bld.extension-kotlin=com.uwyn.rife2:bld-kotlin:1.1.0-SNAPSHOT +bld.extension-jacoco=com.uwyn.rife2:bld-jacoco-report:0.9.1 +bld.extensions=com.uwyn.rife2:bld-kotlin:0.9.0-SNAPSHOT +bld.extension-detekt=com.uwyn.rife2:bld-detekt:0.9.0-SNAPSHOT bld.repositories=MAVEN_LOCAL,MAVEN_CENTRAL,RIFE2_SNAPSHOTS,RIFE2_RELEASES +bld.downloadLocation= bld.sourceDirectories= -bld.version=2.2.1 +bld.version=1.7.5 diff --git a/pom.xml b/pom.xml index e480d48..f2be8ba 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 net.thauvin.erik jokeapi - 1.0.1-SNAPSHOT + 0.9.1 jokeapi Retrieve jokes from Sv443's JokeAPI https://github.com/ethauvin/jokeapi @@ -18,19 +18,37 @@ org.jetbrains.kotlin kotlin-stdlib - 2.1.20 + 1.9.21 + compile + + + org.jetbrains.kotlin + kotlin-stdlib-common + 1.9.21 + compile + + + org.jetbrains.kotlin + kotlin-stdlib-jdk7 + 1.9.21 + compile + + + org.jetbrains.kotlin + kotlin-stdlib-jdk8 + 1.9.21 compile org.json json - 20250107 + 20231013 compile net.thauvin.erik.urlencoder urlencoder-lib-jvm - 1.6.0 + 1.4.0 compile diff --git a/src/bld/java/net/thauvin/erik/JokeApiBuild.java b/src/bld/java/net/thauvin/erik/JokeApiBuild.java index f454945..2d216a8 100644 --- a/src/bld/java/net/thauvin/erik/JokeApiBuild.java +++ b/src/bld/java/net/thauvin/erik/JokeApiBuild.java @@ -1,7 +1,7 @@ /* * JokeApiBuild.java * - * Copyright 2022-2025 Erik C. Thauvin (erik@thauvin.net) + * 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: @@ -35,11 +35,10 @@ import rife.bld.BuildCommand; import rife.bld.Project; import rife.bld.extension.CompileKotlinOperation; import rife.bld.extension.DetektOperation; -import rife.bld.extension.DokkaOperation; import rife.bld.extension.JacocoReportOperation; +import rife.bld.extension.dokka.DokkaOperation; import rife.bld.extension.dokka.LoggingLevel; import rife.bld.extension.dokka.OutputFormat; -import rife.bld.extension.kotlin.CompileOptions; import rife.bld.operations.exceptions.ExitStatusException; import rife.bld.publish.PomBuilder; import rife.bld.publish.PublishDeveloper; @@ -50,45 +49,41 @@ import rife.tools.exceptions.FileUtilsErrorException; import java.io.File; import java.io.IOException; import java.util.List; -import java.util.logging.ConsoleHandler; -import java.util.logging.Level; -import java.util.logging.Logger; import static rife.bld.dependencies.Repository.*; import static rife.bld.dependencies.Scope.compile; import static rife.bld.dependencies.Scope.test; public class JokeApiBuild extends Project { - final File srcMainKotlin = new File(srcMainDirectory(), "kotlin"); - public JokeApiBuild() { pkg = "net.thauvin.erik"; name = "jokeapi"; - version = version(1, 0, 1, "SNAPSHOT"); + version = version(0, 9, 1); javaRelease = 11; downloadSources = true; autoDownloadPurge = true; repositories = List.of(MAVEN_LOCAL, MAVEN_CENTRAL); - final var kotlin = version(2, 1, 20); + final var kotlin = version(1, 9, 21); scope(compile) .include(dependency("org.jetbrains.kotlin", "kotlin-stdlib", kotlin)) - .include(dependency("org.json", "json", "20250107")) - .include(dependency("net.thauvin.erik.urlencoder", "urlencoder-lib-jvm", version(1, 6, 0))); + .include(dependency("org.jetbrains.kotlin", "kotlin-stdlib-common", kotlin)) + .include(dependency("org.jetbrains.kotlin", "kotlin-stdlib-jdk7", kotlin)) + .include(dependency("org.jetbrains.kotlin", "kotlin-stdlib-jdk8", kotlin)) + .include(dependency("org.json", "json", "20231013")) + .include(dependency("net.thauvin.erik.urlencoder", "urlencoder-lib-jvm", version(1, 4, 0))); scope(test) - .include(dependency("org.jetbrains.kotlin", "kotlin-test-junit5", kotlin)) - .include(dependency("org.junit.jupiter", "junit-jupiter", version(5, 12, 2))) - .include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1, 12, 2))) - .include(dependency("org.junit.platform", "junit-platform-launcher", version(1, 12, 2))) - .include(dependency("com.willowtreeapps.assertk", "assertk-jvm", version(0, 28, 1))); + .include(dependency("org.jetbrains.kotlin", "kotlin-test-junit5", version(1, 9, 21))) + .include(dependency("org.junit.jupiter", "junit-jupiter", version(5, 10, 1))) + .include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1, 10, 1))) + .include(dependency("com.willowtreeapps.assertk", "assertk-jvm", version(0, 27, 0))); publishOperation() .repository(version.isSnapshot() ? repository(SONATYPE_SNAPSHOTS_LEGACY.location()) .withCredentials(property("sonatype.user"), property("sonatype.password")) : repository(SONATYPE_RELEASES_LEGACY.location()) .withCredentials(property("sonatype.user"), property("sonatype.password"))) - .repository(repository("github")) .info() .groupId(pkg) .artifactId(name) @@ -115,29 +110,18 @@ public class JokeApiBuild extends Project { .signKey(property("sign.key")) .signPassphrase(property("sign.passphrase")); - jarSourcesOperation().sourceDirectories(srcMainKotlin); + jarSourcesOperation().sourceDirectories(new File(srcMainDirectory(), "kotlin")); } public static void main(String[] args) { - // Enable detailed logging for the extensions - var level = Level.ALL; - var logger = Logger.getLogger("rife.bld.extension"); - var consoleHandler = new ConsoleHandler(); - - consoleHandler.setLevel(level); - logger.addHandler(consoleHandler); - logger.setLevel(level); - logger.setUseParentHandlers(false); - new JokeApiBuild().start(args); } @BuildCommand(summary = "Compiles the Kotlin project") @Override - public void compile() throws Exception { + public void compile() throws IOException { new CompileKotlinOperation() .fromProject(this) - .compileOptions(new CompileOptions().verbose(true)) .execute(); } @@ -158,10 +142,9 @@ public class JokeApiBuild extends Project { } @BuildCommand(summary = "Generates JaCoCo Reports") - public void jacoco() throws Exception { + public void jacoco() throws IOException { new JacocoReportOperation() .fromProject(this) - .sourceFiles(srcMainKotlin) .execute(); } @@ -183,12 +166,6 @@ public class JokeApiBuild extends Project { pomRoot(); } - @Override - public void publishLocal() throws Exception { - super.publishLocal(); - pomRoot(); - } - @BuildCommand(value = "pom-root", summary = "Generates the POM file in the root directory") public void pomRoot() throws FileUtilsErrorException { PomBuilder.generateInto(publishOperation().fromProject(this).info(), dependencies(), diff --git a/src/main/kotlin/net/thauvin/erik/jokeapi/JokeApi.kt b/src/main/kotlin/net/thauvin/erik/jokeapi/JokeApi.kt index 474aa27..b4df9aa 100644 --- a/src/main/kotlin/net/thauvin/erik/jokeapi/JokeApi.kt +++ b/src/main/kotlin/net/thauvin/erik/jokeapi/JokeApi.kt @@ -1,7 +1,7 @@ /* * JokeApi.kt * - * Copyright 2022-2025 Erik C. Thauvin (erik@thauvin.net) + * 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: @@ -45,16 +45,13 @@ import java.util.stream.Collectors object JokeApi { private const val API_URL = "https://v2.jokeapi.dev/" - /** - * The logger instance. - */ @JvmStatic val logger: Logger by lazy { Logger.getLogger(JokeApi::class.java.simpleName) } /** * Makes a direct API call. * - * See the [JokeAPI Documentation](https://jokeapi.dev/#endpoints) for more details. + * Sse the [JokeAPI Documentation](https://jokeapi.dev/#endpoints) for more details. */ @JvmStatic @JvmOverloads @@ -64,7 +61,7 @@ object JokeApi { path: String = "", params: Map = emptyMap(), auth: String = "" - ): JokeResponse { + ): String { val urlBuilder = StringBuilder("$API_URL$endPoint") if (path.isNotEmpty()) { @@ -98,11 +95,11 @@ object JokeApi { */ @JvmStatic @Throws(HttpErrorException::class) - fun getRawJokes(config: JokeConfig): JokeResponse { + fun getRawJokes(config: JokeConfig): String { return rawJokes( categories = config.categories, - lang = config.lang, - blacklistFlags = config.blacklistFlags, + lang = config.language, + blacklistFlags = config.flags, type = config.type, format = config.format, contains = config.contains, @@ -124,8 +121,8 @@ object JokeApi { fun joke(config: JokeConfig = JokeConfig.Builder().build()): Joke { return joke( categories = config.categories, - lang = config.lang, - blacklistFlags = config.blacklistFlags, + lang = config.language, + blacklistFlags = config.flags, type = config.type, contains = config.contains, idRange = config.idRange, @@ -145,8 +142,8 @@ object JokeApi { fun jokes(config: JokeConfig): Array { return jokes( categories = config.categories, - lang = config.lang, - blacklistFlags = config.blacklistFlags, + lang = config.language, + blacklistFlags = config.flags, type = config.type, contains = config.contains, idRange = config.idRange, @@ -164,32 +161,6 @@ object JokeApi { * * Sse the [JokeAPI Documentation](https://jokeapi.dev/#joke-endpoint) for more details. * - * @param categories JokeAPI has a first, coarse filter that just categorizes the jokes depending on what the joke is - * about or who the joke is directed at. A joke about programming will be in the [Category.PROGRAMMING] category, dark - * humor will be in the [Category.DARK] category and so on. If you want jokes from all categories, you can instead use - * [Category.ANY], which will make JokeAPI randomly choose a category. - * @param lang There are two types of languages; system languages and joke languages. Both are separate from each other. - * All system messages like errors can have a certain system language, while jokes can only have a joke language. - * It is possible, that system languages don't yet exist for your language while jokes already do. - * If no suitable system language is found, JokeAPI will default to English. - * @param blacklistFlags Blacklist Flags (or just "Flags") are a more fine layer of filtering. Multiple flags can be - * set on each joke, and they tell you something about the offensiveness of each joke. - * @param type Each joke comes with one of two types: [Type.SINGLE] or [Type.TWOPART]. If a joke is of type - * [Type.TWOPART], it has a setup string and a delivery string, which are both part of the joke. They are separated - * because you might want to present the users the delivery after a timeout or in a different section of the UI. - * A joke of type [Type.SINGLE] only has a single string, which is the entire joke. - * @param contains If the search string filter is used, only jokes that contain the specified string will be returned. - * @param idRange If this filter is used, you will only get jokes that are within the provided range of IDs. - * You don't necessarily need to provide an ID range though, a single ID will work just fine as well. - * For example, an ID range of 0-9 will mean you will only get one of the first 10 jokes, while an ID range of 5 will - * mean you will only get the 6th joke. - * @param safe Safe Mode. If enabled, JokeAPI will try its best to serve only jokes that are considered safe for - * everyone. Unsafe jokes are those who can be considered explicit in any way, either through the used language, its - * references or its [flags][blacklistFlags]. Jokes from the category [Category.DARK] are also generally marked as - * unsafe. - * @param auth JokeAPI has a way of whitelisting certain clients. This is achieved through an API token. - * At the moment, you will only receive one of these tokens temporarily if something breaks or if you are a business - * and need more than 120 requests per minute. * @param splitNewLine Split newline within [Type.SINGLE] joke. */ fun joke( @@ -213,7 +184,7 @@ fun joke( idRange = idRange, safe = safe, auth = auth - ).data + ) ) if (json.getBoolean("error")) { throw parseError(json) @@ -227,35 +198,7 @@ fun joke( * * Sse the [JokeAPI Documentation](https://jokeapi.dev/#joke-endpoint) for more details. * - * @param amount This filter allows you to set a certain amount of jokes to receive in a single call. Setting the - * filter to an invalid number will result in the API defaulting to serving a single joke. Setting it to a number - * larger than 10 will make JokeAPI default to the maximum (10). - * @param categories JokeAPI has a first, coarse filter that just categorizes the jokes depending on what the joke is - * about or who the joke is directed at. A joke about programming will be in the [Category.PROGRAMMING] category, dark - * humor will be in the [Category.DARK] category and so on. If you want jokes from all categories, you can instead use - * [Category.ANY], which will make JokeAPI randomly choose a category. - * @param lang There are two types of languages; system languages and joke languages. Both are separate from each other. - * All system messages like errors can have a certain system language, while jokes can only have a joke language. - * It is possible, that system languages don't yet exist for your language while jokes already do. - * If no suitable system language is found, JokeAPI will default to English. - * @param blacklistFlags Blacklist Flags (or just "Flags") are a more fine layer of filtering. Multiple flags can be - * set on each joke, and they tell you something about the offensiveness of each joke. - * @param type Each joke comes with one of two types: [Type.SINGLE] or [Type.TWOPART]. If a joke is of type - * [Type.TWOPART], it has a setup string and a delivery string, which are both part of the joke. They are separated - * because you might want to present the users the delivery after a timeout or in a different section of the UI. - * A joke of type [Type.SINGLE] only has a single string, which is the entire joke. - * @param contains If the search string filter is used, only jokes that contain the specified string will be returned. - * @param idRange If this filter is used, you will only get jokes that are within the provided range of IDs. - * You don't necessarily need to provide an ID range though, a single ID will work just fine as well. - * For example, an ID range of 0-9 will mean you will only get one of the first 10 jokes, while an ID range of 5 will - * mean you will only get the 6th joke. - * @param safe Safe Mode. If enabled, JokeAPI will try its best to serve only jokes that are considered safe for - * everyone. Unsafe jokes are those who can be considered explicit in any way, either through the used language, its - * references or its [flags][blacklistFlags]. Jokes from the category [Category.DARK] are also generally marked as - * unsafe. - * @param auth JokeAPI has a way of whitelisting certain clients. This is achieved through an API token. - * At the moment, you will only receive one of these tokens temporarily if something breaks or if you are a business - * and need more than 120 requests per minute. + * @param amount The required amount of jokes to return. * @param splitNewLine Split newline within [Type.SINGLE] joke. */ fun jokes( @@ -281,7 +224,7 @@ fun jokes( amount = amount, safe = safe, auth = auth - ).data + ) ) if (json.getBoolean("error")) { throw parseError(json) @@ -298,42 +241,8 @@ fun jokes( /** * Returns one or more jokes. * - * See the [JokeAPI Documentation](https://jokeapi.dev/#joke-endpoint) for more details. - * - * @param categories JokeAPI has a first, coarse filter that just categorizes the jokes depending on what the joke is - * about or who the joke is directed at. A joke about programming will be in the [Category.PROGRAMMING] category, dark - * humor will be in the [Category.DARK] category and so on. If you want jokes from all categories, you can instead use - * [Category.ANY], which will make JokeAPI randomly choose a category. - * @param lang There are two types of languages; system languages and joke languages. Both are separate from each other. - * All system messages like errors can have a certain system language, while jokes can only have a joke language. - * It is possible, that system languages don't yet exist for your language while jokes already do. - * If no suitable system language is found, JokeAPI will default to English. - * @param blacklistFlags Blacklist Flags (or just "Flags") are a more fine layer of filtering. Multiple flags can be - * set on each joke, and they tell you something about the offensiveness of each joke. - * @param type Each joke comes with one of two types: [Type.SINGLE] or [Type.TWOPART]. If a joke is of type - * [Type.TWOPART], it has a setup string and a delivery string, which are both part of the joke. They are separated - * because you might want to present the users the delivery after a timeout or in a different section of the UI. - * A joke of type [Type.SINGLE] only has a single string, which is the entire joke. - * @param contains If the search string filter is used, only jokes that contain the specified string will be returned. - * @param format Response Formats (or just "Formats") are a way to get your data in a different file format. - * Maybe your environment or language doesn't support JSON natively. In that case, JokeAPI is able to convert the - * JSON-formatted joke to a different format for you. - * @param idRange If this filter is used, you will only get jokes that are within the provided range of IDs. - * You don't necessarily need to provide an ID range though, a single ID will work just fine as well. - * For example, an ID range of 0-9 will mean you will only get one of the first 10 jokes, while an ID range of 5 will - * mean you will only get the 6th joke. - * @param amount This filter allows you to set a certain amount of jokes to receive in a single call. Setting the - * filter to an invalid number will result in the API defaulting to serving a single joke. Setting it to a number - * larger than 10 will make JokeAPI default to the maximum (10). - * @param safe Safe Mode. If enabled, JokeAPI will try its best to serve only jokes that are considered safe for - * everyone. Unsafe jokes are those who can be considered explicit in any way, either through the used language, its - * references or its [flags][blacklistFlags]. Jokes from the category [Category.DARK] are also generally marked as - * unsafe. - * @param auth JokeAPI has a way of whitelisting certain clients. This is achieved through an API token. - * At the moment, you will only receive one of these tokens temporarily if something breaks or if you are a business - * and need more than 120 requests per minute. + * Sse the [JokeAPI Documentation](https://jokeapi.dev/#joke-endpoint) for more details. */ -@Throws(HttpErrorException::class) fun rawJokes( categories: Set = setOf(Category.ANY), lang: Language = Language.EN, @@ -345,7 +254,7 @@ fun rawJokes( amount: Int = 1, safe: Boolean = false, auth: String = "" -): JokeResponse { +): String { val params = mutableMapOf() // Categories diff --git a/src/main/kotlin/net/thauvin/erik/jokeapi/JokeConfig.kt b/src/main/kotlin/net/thauvin/erik/jokeapi/JokeConfig.kt index a4d4901..4537d13 100644 --- a/src/main/kotlin/net/thauvin/erik/jokeapi/JokeConfig.kt +++ b/src/main/kotlin/net/thauvin/erik/jokeapi/JokeConfig.kt @@ -1,7 +1,7 @@ /* * JokeConfig.kt * - * Copyright 2022-2025 Erik C. Thauvin (erik@thauvin.net) + * 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: @@ -39,19 +39,19 @@ import net.thauvin.erik.jokeapi.models.* * * Use the [Builder] to create a new configuration. */ -class JokeConfig private constructor(builder: Builder) { - val categories = builder.categories - val lang = builder.lang - val blacklistFlags = builder.blacklistFlags - val type = builder.type - val format = builder.format - val contains = builder.contains - val idRange = builder.idRange - val amount = builder.amount - val safe = builder.safe - val splitNewLine = builder.splitNewLine - val auth = builder.auth - +class JokeConfig private constructor( + val categories: Set, + val language: Language, + val flags: Set, + val type: Type, + val format: Format, + val contains: String, + val idRange: IdRange, + val amount: Int, + val safe: Boolean, + val splitNewLine: Boolean, + val auth: String +) { /** * [Builds][build] a new configuration. * @@ -72,86 +72,20 @@ class JokeConfig private constructor(builder: Builder) { var splitNewLine: Boolean = false, var auth: String = "" ) { - /** - * JokeAPI has a first, coarse filter that just categorizes the jokes depending on what the joke is - * about or who the joke is directed at. A joke about programming will be in the [Category.PROGRAMMING] - * category, dark humor will be in the [Category.DARK] category and so on. If you want jokes from all - * categories, you can instead use [Category.ANY], which will make JokeAPI randomly choose a category. - */ - fun categories(categories: Set): Builder = apply { this.categories = categories } + fun categories(categories: Set) = apply { this.categories = categories } + fun lang(language: Language) = apply { lang = language } + fun blacklistFlags(flags: Set) = apply { blacklistFlags = flags } + fun type(type: Type) = apply { this.type = type } + fun format(format: Format) = apply { this.format = format } + fun contains(search: String) = apply { contains = search } + fun idRange(idRange: IdRange) = apply { this.idRange = idRange } + fun amount(amount: Int) = apply { this.amount = amount } + fun safe(safe: Boolean) = apply { this.safe = safe } + fun splitNewLine(splitNewLine: Boolean) = apply { this.splitNewLine = splitNewLine } + fun auth(auth: String) = apply { this.auth = auth } - /** - * There are two types of languages; system languages and joke languages. Both are separate from each other. - * All system messages like errors can have a certain system language, while jokes can only have a joke - * language. It is possible, that system languages don't yet exist for your language while jokes already do. - * If no suitable system language is found, JokeAPI will default to English. - */ - fun lang(language: Language): Builder = apply { lang = language } - - /** - * Blacklist Flags (or just "Flags") are a more fine layer of filtering. Multiple flags can be - * set on each joke, and they tell you something about the offensiveness of each joke. - */ - fun blacklistFlags(flags: Set): Builder = apply { blacklistFlags = flags } - - /** - * Each joke comes with one of two types: [Type.SINGLE] or [Type.TWOPART]. If a joke is of type - * [Type.TWOPART], it has a setup string and a delivery string, which are both part of the joke. They are - * separated because you might want to present the users the delivery after a timeout or in a different section - * of the UI. A joke of type [Type.SINGLE] only has a single string, which is the entire joke. - */ - fun type(type: Type): Builder = apply { this.type = type } - - /** - * Response Formats (or just "Formats") are a way to get your data in a different file format. - * Maybe your environment or language doesn't support JSON natively. In that case, JokeAPI is able to convert - * the JSON-formatted joke to a different format for you. - */ - fun format(format: Format): Builder = apply { this.format = format } - - /** - * If the search string filter is used, only jokes that contain the specified string will be returned. - */ - fun contains(search: String): Builder = apply { contains = search } - - /** - * If this filter is used, you will only get jokes that are within the provided range of IDs. - * You don't necessarily need to provide an ID range though, a single ID will work just fine as well. - * For example, an ID range of 0-9 will mean you will only get one of the first 10 jokes, while an ID range - * of 5 will mean you will only get the 6th joke. - */ - fun idRange(idRange: IdRange): Builder = apply { this.idRange = idRange } - - /** - * This filter allows you to set a certain amount of jokes to receive in a single call. Setting the - * filter to an invalid number will result in the API defaulting to serving a single joke. Setting it to a - * number larger than 10 will make JokeAPI default to the maximum (10). - */ - fun amount(amount: Int): Builder = apply { this.amount = amount } - - /** - * Safe Mode. If enabled, JokeAPI will try its best to serve only jokes that are considered safe for - * everyone. Unsafe jokes are those who can be considered explicit in any way, either through the used language, - * its references or its [flags][blacklistFlags]. Jokes from the category [Category.DARK] are also generally - * marked as unsafe. - */ - fun safe(safe: Boolean): Builder = apply { this.safe = safe } - - /** - * Split newline within [Type.SINGLE] joke. - */ - fun splitNewLine(splitNewLine: Boolean): Builder = apply { this.splitNewLine = splitNewLine } - - /** - * JokeAPI has a way of whitelisting certain clients. This is achieved through an API token. - * At the moment, you will only receive one of these tokens temporarily if something breaks or if you are a - * business and need more than 120 requests per minute. - */ - fun auth(auth: String): Builder = apply { this.auth = auth } - - /** - * Builds a new configuration. - */ - fun build() = JokeConfig(this) + fun build() = JokeConfig( + categories, lang, blacklistFlags, type, format, contains, idRange, amount, safe, splitNewLine, auth + ) } } diff --git a/src/main/kotlin/net/thauvin/erik/jokeapi/JokeUtil.kt b/src/main/kotlin/net/thauvin/erik/jokeapi/JokeUtil.kt index 651844c..ff9f3e6 100644 --- a/src/main/kotlin/net/thauvin/erik/jokeapi/JokeUtil.kt +++ b/src/main/kotlin/net/thauvin/erik/jokeapi/JokeUtil.kt @@ -1,7 +1,7 @@ /* * JokeUtil.kt * - * Copyright 2022-2025 Erik C. Thauvin (erik@thauvin.net) + * 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: @@ -39,37 +39,30 @@ import net.thauvin.erik.jokeapi.models.* import org.json.JSONObject import java.io.IOException import java.net.HttpURLConnection -import java.net.URI +import java.net.URL import java.util.logging.Level -/** - * Fetch a URL. - */ -internal fun fetchUrl(url: String, auth: String = ""): JokeResponse { +internal fun fetchUrl(url: String, auth: String = ""): String { if (JokeApi.logger.isLoggable(Level.FINE)) { JokeApi.logger.fine(url) } - val connection = URI(url).toURL().openConnection() as HttpURLConnection - try { - connection.setRequestProperty( - "User-Agent", "Mozilla/5.0 (X11; Linux x86_64; rv:130.0) Gecko/20100101 Firefox/130.0" - ) - if (auth.isNotEmpty()) { - connection.setRequestProperty("Authentication", auth) - } + val connection = URL(url).openConnection() as HttpURLConnection + connection.setRequestProperty( + "User-Agent", "Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/109.0" + ) + if (auth.isNotEmpty()) { + connection.setRequestProperty("Authentication", auth) + } - val isSuccess = connection.responseCode in 200..399 - val stream = if (isSuccess) connection.inputStream else connection.errorStream - val body = stream.bufferedReader().use { it.readText() } - if (!isSuccess && (body.isBlank() || connection.contentType.contains("text/html"))) { - throw httpError(connection.responseCode) - } else if (JokeApi.logger.isLoggable(Level.FINE)) { + if (connection.responseCode in 200..399) { + val body = connection.inputStream.bufferedReader().use { it.readText() } + if (JokeApi.logger.isLoggable(Level.FINE)) { JokeApi.logger.fine(body) } - return JokeResponse(connection.responseCode, body) - } finally { - connection.disconnect() + return body + } else { + throw httpError(connection.responseCode) } } @@ -130,9 +123,6 @@ private fun httpError(responseCode: Int): HttpErrorException { return httpException } -/** - * Parse Error. - */ internal fun parseError(json: JSONObject): JokeException { val causedBy = json.getJSONArray("causedBy") val causes = List(causedBy.length()) { i -> causedBy.getString(i) } @@ -146,9 +136,6 @@ internal fun parseError(json: JSONObject): JokeException { ) } -/** - * Parse Joke. - */ internal fun parseJoke(json: JSONObject, splitNewLine: Boolean): Joke { val jokes = mutableListOf() if (json.has("setup")) { 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 f2e8529..815afcc 100644 --- a/src/main/kotlin/net/thauvin/erik/jokeapi/exceptions/HttpErrorException.kt +++ b/src/main/kotlin/net/thauvin/erik/jokeapi/exceptions/HttpErrorException.kt @@ -1,7 +1,7 @@ /* * HttpErrorException.kt * - * Copyright 2022-2025 Erik C. Thauvin (erik@thauvin.net) + * 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: @@ -44,6 +44,7 @@ class HttpErrorException @JvmOverloads constructor( cause: Throwable? = null ) : IOException(message, cause) { companion object { + @Suppress("ConstPropertyName") private const val serialVersionUID = 1L } } 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 ac77344..16d4ec8 100644 --- a/src/main/kotlin/net/thauvin/erik/jokeapi/exceptions/JokeException.kt +++ b/src/main/kotlin/net/thauvin/erik/jokeapi/exceptions/JokeException.kt @@ -1,7 +1,7 @@ /* * JokeException.kt * - * Copyright 2022-2025 Erik C. Thauvin (erik@thauvin.net) + * 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 cfb008e..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,7 +1,7 @@ /* * Category.kt * - * Copyright 2022-2025 Erik C. Thauvin (erik@thauvin.net) + * 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 be2e21f..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,7 +1,7 @@ /* * Flag.kt * - * Copyright 2022-2025 Erik C. Thauvin (erik@thauvin.net) + * 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 1beb9d3..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,7 +1,7 @@ /* * Format.kt * - * Copyright 2022-2025 Erik C. Thauvin (erik@thauvin.net) + * 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 73d45ec..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,7 +1,7 @@ /* * IdRange.kt * - * Copyright 2022-2025 Erik C. Thauvin (erik@thauvin.net) + * 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 c2124ae..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,7 +1,7 @@ /* * Joke.kt * - * Copyright 2022-2025 Erik C. Thauvin (erik@thauvin.net) + * 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/JokeResponse.kt b/src/main/kotlin/net/thauvin/erik/jokeapi/models/JokeResponse.kt deleted file mode 100644 index d34f2c3..0000000 --- a/src/main/kotlin/net/thauvin/erik/jokeapi/models/JokeResponse.kt +++ /dev/null @@ -1,39 +0,0 @@ -/* - * JokeResponse.kt - * - * Copyright 2022-2025 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.models - -/** - * The Joke API response. - * - * @property statusCode The HTTP status code. - * @property data The response body text. - */ -data class JokeResponse(val statusCode: Int, val data: String) 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 3ee166e..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,7 +1,7 @@ /* * Language.kt * - * Copyright 2022-2025 Erik C. Thauvin (erik@thauvin.net) + * 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 8962b2a..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,7 +1,7 @@ /* * Parameter.kt * - * Copyright 2022-2025 Erik C. Thauvin (erik@thauvin.net) + * 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: @@ -34,7 +34,6 @@ package net.thauvin.erik.jokeapi.models /** * The available [URL Parameters](https://jokeapi.dev/#url-parameters). */ -@Suppress("unused") object Parameter { const val AMOUNT = "amount" const val CONTAINS = "contains" 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 4fd80fe..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,7 +1,7 @@ /* * Type.kt * - * Copyright 2022-2025 Erik C. Thauvin (erik@thauvin.net) + * 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 6153825..d9f9b30 100644 --- a/src/test/kotlin/net/thauvin/erik/jokeapi/ApiCallTest.kt +++ b/src/test/kotlin/net/thauvin/erik/jokeapi/ApiCallTest.kt @@ -1,7 +1,7 @@ /* * ApiCallTest.kt * - * Copyright 2022-2025 Erik C. Thauvin (erik@thauvin.net) + * 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: @@ -32,7 +32,6 @@ package net.thauvin.erik.jokeapi import assertk.assertThat -import assertk.assertions.isEqualTo import assertk.assertions.isGreaterThan import assertk.assertions.startsWith import net.thauvin.erik.jokeapi.JokeApi.apiCall @@ -52,9 +51,8 @@ internal class ApiCallTest { fun `Get Flags`() { // See https://v2.jokeapi.dev/#flags-endpoint val response = apiCall(endPoint = "flags") - val json = JSONObject(response.data) - assertAll( - "Validate JSON", + val json = JSONObject(response) + assertAll("Validate JSON", { assertFalse(json.getBoolean("error"), "apiCall(flags).error") }, { assertThat(json.getJSONArray("flags").length(), "apiCall(flags).flags").isGreaterThan(0) }, { assertThat(json.getLong("timestamp"), "apiCall(flags).timestamp").isGreaterThan(0) }) @@ -67,16 +65,14 @@ internal class ApiCallTest { endPoint = "langcode", path = "french", params = mapOf(Parameter.FORMAT to Format.YAML.value) ) - assertThat(lang.statusCode).isEqualTo(200) - assertContains(lang.data, "code: \"fr\"", false, "apiCall(langcode, french, yaml)") + assertContains(lang, "code: \"fr\"", false, "apiCall(langcode, french, yaml)") } @Test fun `Get Ping Response`() { // See https://v2.jokeapi.dev/#ping-endpoint val ping = apiCall(endPoint = "ping", params = mapOf(Parameter.FORMAT to Format.TXT.value)) - assertThat(ping.statusCode).isEqualTo(200) - assertThat(ping.data).startsWith("Pong!") + assertThat(ping, "apiCall(ping, txt)").startsWith("Pong!") } @Test @@ -86,7 +82,6 @@ internal class ApiCallTest { endPoint = "languages", params = mapOf(Parameter.FORMAT to Format.XML.value, Parameter.LANG to Language.FR.value) ) - assertThat(lang.statusCode).isEqualTo(200) - assertThat(lang.data).startsWith("") + assertThat(lang).startsWith("") } } diff --git a/src/test/kotlin/net/thauvin/erik/jokeapi/BeforeAllTests.kt b/src/test/kotlin/net/thauvin/erik/jokeapi/BeforeAllTests.kt index 50ce4b2..de9d48a 100644 --- a/src/test/kotlin/net/thauvin/erik/jokeapi/BeforeAllTests.kt +++ b/src/test/kotlin/net/thauvin/erik/jokeapi/BeforeAllTests.kt @@ -1,7 +1,7 @@ /* * BeforeAllTests.kt * - * Copyright 2022-2025 Erik C. Thauvin (erik@thauvin.net) + * 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/ExceptionsTest.kt b/src/test/kotlin/net/thauvin/erik/jokeapi/ExceptionsTest.kt index eb6837a..3932afd 100644 --- a/src/test/kotlin/net/thauvin/erik/jokeapi/ExceptionsTest.kt +++ b/src/test/kotlin/net/thauvin/erik/jokeapi/ExceptionsTest.kt @@ -1,7 +1,7 @@ /* * ExceptionsTest.kt * - * Copyright 2022-2025 Erik C. Thauvin (erik@thauvin.net) + * 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: @@ -41,6 +41,8 @@ import net.thauvin.erik.jokeapi.models.Category 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 @ExtendWith(BeforeAllTests::class) internal class ExceptionsTest { @@ -61,20 +63,19 @@ internal class ExceptionsTest { } } - @Test - fun `Validate HTTP Exceptions`() { - val locs = ArrayList>() - locs.add(Pair("https://apichallenges.herokuapp.com/secret/note", 401)) - locs.add(Pair("https://apichallenges.herokuapp.com/todo", 404)) - - for ((url, code) in locs) { - val e = assertThrows { - fetchUrl(url) - } - assertThat(e, "fetchUrl($code)").all { - prop(HttpErrorException::statusCode).isEqualTo(code) - prop(HttpErrorException::message).isNotNull().isNotEmpty() - } + @ParameterizedTest + @ValueSource(ints = [400, 404, 403, 413, 414, 429, 500, 523, 666]) + fun `Validate HTTP Exceptions`(code: Int) { + val e = assertThrows { + fetchUrl("https://httpstat.us/$code") + } + assertThat(e, "fetchUrl($code)").all { + prop(HttpErrorException::statusCode).isEqualTo(code) + prop(HttpErrorException::message).isNotNull().isNotEmpty() + if (code < 600) + prop(HttpErrorException::cause).isNotNull().assertThat(Throwable::message).isNotNull() + else + prop(HttpErrorException::cause).isNull() } } } diff --git a/src/test/kotlin/net/thauvin/erik/jokeapi/GetJokeTest.kt b/src/test/kotlin/net/thauvin/erik/jokeapi/GetJokeTest.kt index e5a7d39..c08ce39 100644 --- a/src/test/kotlin/net/thauvin/erik/jokeapi/GetJokeTest.kt +++ b/src/test/kotlin/net/thauvin/erik/jokeapi/GetJokeTest.kt @@ -1,7 +1,7 @@ /* * GetJokeTest.kt * - * Copyright 2022-2025 Erik C. Thauvin (erik@thauvin.net) + * 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: @@ -70,12 +70,15 @@ internal class GetJokeTest { @Test fun `Get Joke with ID`() { - val id = 201 + val id = 172 val joke = joke(idRange = IdRange(id)) logger.fine(joke.toString()) assertThat(joke, "joke($id)").all { - prop(Joke::flags).contains(Flag.RELIGIOUS); - prop(Joke::id).isEqualTo(id) + prop(Joke::flags).all { + contains(Flag.EXPLICIT) + contains(Flag.NSFW) + } + prop(Joke::id).isEqualTo(172) prop(Joke::category).isEqualTo(Category.PUN) } } @@ -134,10 +137,12 @@ internal class GetJokeTest { @Test fun `Get Joke with Split Newline`() { - val joke = joke(type = Type.SINGLE, idRange = IdRange(18), splitNewLine = true) + val joke = joke( + categories = setOf(Category.DARK), type = Type.SINGLE, idRange = IdRange(178), splitNewLine = true + ) logger.fine(joke.toString()) assertThat(joke::joke, "joke(splitNewLine=true)").all { - size().isGreaterThanOrEqualTo(2) + size().isEqualTo(2) each { containsNone("\n") } @@ -172,12 +177,13 @@ internal class GetJokeTest { @Test fun `Get Joke using Search`() { - val search = "UDP joke" + val id = 265 + val search = "his wife" val joke = - joke(contains = search, categories = setOf(Category.PROGRAMMING), safe = true) + joke(contains = search, categories = setOf(Category.PROGRAMMING), idRange = IdRange(id), safe = true) logger.fine(joke.toString()) assertThat(joke, "joke($search)").all { - prop(Joke::id).isEqualTo(0) + prop(Joke::id).isEqualTo(id) prop(Joke::joke).any { it.contains(search) } diff --git a/src/test/kotlin/net/thauvin/erik/jokeapi/GetJokesTest.kt b/src/test/kotlin/net/thauvin/erik/jokeapi/GetJokesTest.kt index ea49211..2e07a2d 100644 --- a/src/test/kotlin/net/thauvin/erik/jokeapi/GetJokesTest.kt +++ b/src/test/kotlin/net/thauvin/erik/jokeapi/GetJokesTest.kt @@ -1,7 +1,7 @@ /* * GetJokesTest.kt * - * Copyright 2022-2025 Erik C. Thauvin (erik@thauvin.net) + * 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/GetRawJokesTest.kt b/src/test/kotlin/net/thauvin/erik/jokeapi/GetRawJokesTest.kt index aa85337..7bcf1c6 100644 --- a/src/test/kotlin/net/thauvin/erik/jokeapi/GetRawJokesTest.kt +++ b/src/test/kotlin/net/thauvin/erik/jokeapi/GetRawJokesTest.kt @@ -1,7 +1,7 @@ /* * GetRawJokesTest.kt * - * Copyright 2022-2025 Erik C. Thauvin (erik@thauvin.net) + * 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: @@ -33,60 +33,47 @@ package net.thauvin.erik.jokeapi import assertk.all import assertk.assertThat -import assertk.assertions.* +import assertk.assertions.doesNotContain +import assertk.assertions.isNotEmpty +import assertk.assertions.startsWith import net.thauvin.erik.jokeapi.models.Format import net.thauvin.erik.jokeapi.models.IdRange -import net.thauvin.erik.jokeapi.models.JokeResponse import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith +import kotlin.test.assertContains @ExtendWith(BeforeAllTests::class) internal class GetRawJokesTest { @Test fun `Get Raw Joke with TXT`() { val response = rawJokes(format = Format.TXT) - assertThat(response).all { - prop("statusCode", JokeResponse::statusCode).isEqualTo(200) - prop("data", JokeResponse::data).all { - isNotEmpty() - doesNotContain("Error") - } + assertThat(response, "rawJoke(txt)").all { + isNotEmpty() + doesNotContain("Error") } } @Test fun `Get Raw Joke with XML`() { val response = rawJokes(format = Format.XML) - assertThat(response).all { - prop("statusCode", JokeResponse::statusCode).isEqualTo(200) - prop("data", JokeResponse::data).startsWith("\n\n false") - } + assertThat(response, "rawJoke(xml)").startsWith("\n\n false") } @Test fun `Get Raw Joke with YAML`() { val response = rawJokes(format = Format.YAML) - assertThat(response).all { - prop("statusCode", JokeResponse::statusCode).isEqualTo(200) - prop("data", JokeResponse::data).startsWith("error: false") - } + assertThat(response, "rawJoke(yaml)").startsWith("error: false") } @Test fun `Get Raw Jokes`() { val response = rawJokes(amount = 2) - assertThat(response).all { - prop("statusCode", JokeResponse::statusCode).isEqualTo(200) - prop("data", JokeResponse::data).isNotEmpty() - } + assertContains(response, "\"amount\": 2", false, "rawJoke(2)") } @Test fun `Get Raw Invalid Jokes`() { val response = rawJokes(contains = "foo", safe = true, amount = 2, idRange = IdRange(160, 161)) - assertThat(response).all { - prop("statusCode", JokeResponse::statusCode).isEqualTo(400) - prop("data", JokeResponse::data).contains("\"error\": true") - } + assertContains(response, "\"error\": true", false, "getRawJokes(foo)") } } diff --git a/src/test/kotlin/net/thauvin/erik/jokeapi/JokeConfigTest.kt b/src/test/kotlin/net/thauvin/erik/jokeapi/JokeConfigTest.kt index a4d4e0c..e617dfc 100644 --- a/src/test/kotlin/net/thauvin/erik/jokeapi/JokeConfigTest.kt +++ b/src/test/kotlin/net/thauvin/erik/jokeapi/JokeConfigTest.kt @@ -1,7 +1,7 @@ /* * JokeConfigTest.kt * - * Copyright 2022-2025 Erik C. Thauvin (erik@thauvin.net) + * 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: @@ -102,9 +102,8 @@ internal class JokeConfigTest { amount(2) safe(true) }.build() - val jokes = getRawJokes(config) - assertThat(jokes.statusCode).isEqualTo(200) - assertContains(jokes.data, "----------------------------------------------", false, "config.amount(2)") + val joke = getRawJokes(config) + assertContains(joke, "----------------------------------------------", false, "config.amount(2)") } @Test @@ -155,8 +154,8 @@ internal class JokeConfigTest { }.build() assertThat(config, "config").all { prop(JokeConfig::categories).isEqualTo(categories) - prop(JokeConfig::lang).isEqualTo(language) - prop(JokeConfig::blacklistFlags).isEqualTo(flags) + prop(JokeConfig::language).isEqualTo(language) + prop(JokeConfig::flags).isEqualTo(flags) prop(JokeConfig::type).isEqualTo(type) prop(JokeConfig::format).isEqualTo(format) prop(JokeConfig::contains).isEqualTo(search) diff --git a/src/test/kotlin/net/thauvin/erik/jokeapi/JokeUtilTest.kt b/src/test/kotlin/net/thauvin/erik/jokeapi/JokeUtilTest.kt index d50b97a..4b390c8 100644 --- a/src/test/kotlin/net/thauvin/erik/jokeapi/JokeUtilTest.kt +++ b/src/test/kotlin/net/thauvin/erik/jokeapi/JokeUtilTest.kt @@ -1,7 +1,7 @@ /* * JokeUtilTest.kt * - * Copyright 2022-2025 Erik C. Thauvin (erik@thauvin.net) + * 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: @@ -33,7 +33,6 @@ package net.thauvin.erik.jokeapi import assertk.assertThat import assertk.assertions.contains -import assertk.assertions.isEqualTo import org.json.JSONException import org.json.JSONObject import org.junit.jupiter.api.Test @@ -55,8 +54,7 @@ internal class JokeUtilTest { @Test fun `Validate Authentication Header`() { val token = "AUTH-TOKEN" - val response = fetchUrl("https://postman-echo.com/get", token) - assertThat(response.statusCode).isEqualTo(200) - assertThat(response.data, "body").contains("\"authentication\": \"$token\"") + val body = fetchUrl("https://postman-echo.com/get", token) + assertThat(body, "body").contains("\"authentication\": \"$token\"") } }