Added BeforeAllTests class
This commit is contained in:
parent
888c9eddfd
commit
f5ecf2d1b4
8 changed files with 64 additions and 107 deletions
|
@ -36,18 +36,16 @@ import assertk.assertThat
|
|||
import assertk.assertions.isGreaterThan
|
||||
import assertk.assertions.startsWith
|
||||
import net.thauvin.erik.jokeapi.JokeApi.Companion.apiCall
|
||||
import net.thauvin.erik.jokeapi.JokeApi.Companion.logger
|
||||
import net.thauvin.erik.jokeapi.models.Format
|
||||
import net.thauvin.erik.jokeapi.models.Parameter
|
||||
import org.json.JSONObject
|
||||
import org.junit.jupiter.api.Assertions.assertFalse
|
||||
import org.junit.jupiter.api.BeforeAll
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.assertAll
|
||||
import java.util.logging.ConsoleHandler
|
||||
import java.util.logging.Level
|
||||
import org.junit.jupiter.api.extension.ExtendWith
|
||||
import kotlin.test.assertContains
|
||||
|
||||
@ExtendWith(BeforeAllTests::class)
|
||||
internal class ApiCallTest {
|
||||
@Test
|
||||
fun `Get Flags`() {
|
||||
|
@ -76,15 +74,4 @@ internal class ApiCallTest {
|
|||
val ping = apiCall(endPoint = "ping", params = mapOf(Parameter.FORMAT to Format.TXT.value))
|
||||
assertThat(ping, "apiCall(ping, txt)").startsWith("Pong!")
|
||||
}
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
@BeforeAll
|
||||
fun beforeAll() {
|
||||
with(logger) {
|
||||
addHandler(ConsoleHandler().apply { level = Level.FINE })
|
||||
level = Level.FINE
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
48
src/test/kotlin/net/thauvin/erik/jokeapi/BeforeAllTests.kt
Normal file
48
src/test/kotlin/net/thauvin/erik/jokeapi/BeforeAllTests.kt
Normal file
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* BeforeAllTests.kt
|
||||
*
|
||||
* Copyright (c) 2023, Erik C. Thauvin (erik@thauvin.net)
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -48,14 +48,13 @@ import net.thauvin.erik.jokeapi.JokeApi.Companion.logger
|
|||
import net.thauvin.erik.jokeapi.exceptions.HttpErrorException
|
||||
import net.thauvin.erik.jokeapi.exceptions.JokeException
|
||||
import net.thauvin.erik.jokeapi.models.Category
|
||||
import org.junit.jupiter.api.BeforeAll
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.assertThrows
|
||||
import org.junit.jupiter.api.extension.ExtendWith
|
||||
import org.junit.jupiter.params.ParameterizedTest
|
||||
import org.junit.jupiter.params.provider.ValueSource
|
||||
import java.util.logging.ConsoleHandler
|
||||
import java.util.logging.Level
|
||||
|
||||
@ExtendWith(BeforeAllTests::class)
|
||||
internal class ExceptionsTest {
|
||||
@Test
|
||||
fun `Validate Joke Exception`() {
|
||||
|
@ -89,15 +88,4 @@ internal class ExceptionsTest {
|
|||
prop(HttpErrorException::cause).isNull()
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
@BeforeAll
|
||||
fun beforeAll() {
|
||||
with(logger) {
|
||||
addHandler(ConsoleHandler().apply { level = Level.FINE })
|
||||
level = Level.FINE
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,12 +57,11 @@ import net.thauvin.erik.jokeapi.models.IdRange
|
|||
import net.thauvin.erik.jokeapi.models.Joke
|
||||
import net.thauvin.erik.jokeapi.models.Language
|
||||
import net.thauvin.erik.jokeapi.models.Type
|
||||
import org.junit.jupiter.api.BeforeAll
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.assertThrows
|
||||
import java.util.logging.ConsoleHandler
|
||||
import java.util.logging.Level
|
||||
import org.junit.jupiter.api.extension.ExtendWith
|
||||
|
||||
@ExtendWith(BeforeAllTests::class)
|
||||
internal class GetJokeTest {
|
||||
@Test
|
||||
fun `Get Joke`() {
|
||||
|
@ -176,7 +175,6 @@ internal class GetJokeTest {
|
|||
logger.fine(joke.toString())
|
||||
assertThat(joke, "getJoke(safe)").all {
|
||||
prop(Joke::safe).isTrue()
|
||||
prop(Joke::flags).isEmpty()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -211,15 +209,4 @@ internal class GetJokeTest {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
@BeforeAll
|
||||
fun beforeAll() {
|
||||
with(logger) {
|
||||
addHandler(ConsoleHandler().apply { level = Level.FINE })
|
||||
level = Level.FINE
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,22 +37,19 @@ import assertk.assertThat
|
|||
import assertk.assertions.contains
|
||||
import assertk.assertions.each
|
||||
import assertk.assertions.index
|
||||
import assertk.assertions.isEmpty
|
||||
import assertk.assertions.isEqualTo
|
||||
import assertk.assertions.isGreaterThanOrEqualTo
|
||||
import assertk.assertions.isNotNull
|
||||
import assertk.assertions.isTrue
|
||||
import assertk.assertions.prop
|
||||
import assertk.assertions.size
|
||||
import net.thauvin.erik.jokeapi.JokeApi.Companion.logger
|
||||
import net.thauvin.erik.jokeapi.models.Joke
|
||||
import net.thauvin.erik.jokeapi.models.Language
|
||||
import org.junit.jupiter.api.BeforeAll
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.assertThrows
|
||||
import java.util.logging.ConsoleHandler
|
||||
import java.util.logging.Level
|
||||
import org.junit.jupiter.api.extension.ExtendWith
|
||||
|
||||
@ExtendWith(BeforeAllTests::class)
|
||||
internal class GetJokesTest {
|
||||
@Test
|
||||
fun `Get Multiple Jokes`() {
|
||||
|
@ -63,7 +60,6 @@ internal class GetJokesTest {
|
|||
each {
|
||||
it.prop(Joke::id).isGreaterThanOrEqualTo(0)
|
||||
it.prop(Joke::safe).isTrue()
|
||||
it.prop(Joke::flags).isEmpty()
|
||||
it.prop(Joke::lang).isEqualTo(Language.FR)
|
||||
}
|
||||
}
|
||||
|
@ -82,20 +78,8 @@ internal class GetJokesTest {
|
|||
size().isEqualTo(1)
|
||||
index(0).all {
|
||||
prop(Joke::id).isGreaterThanOrEqualTo(0)
|
||||
prop(Joke::flags).isEmpty()
|
||||
prop(Joke::safe).isTrue()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
@BeforeAll
|
||||
fun beforeAll() {
|
||||
with(logger) {
|
||||
addHandler(ConsoleHandler().apply { level = Level.FINE })
|
||||
level = Level.FINE
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,15 +37,13 @@ import assertk.assertThat
|
|||
import assertk.assertions.doesNotContain
|
||||
import assertk.assertions.isNotEmpty
|
||||
import assertk.assertions.startsWith
|
||||
import net.thauvin.erik.jokeapi.JokeApi.Companion.logger
|
||||
import net.thauvin.erik.jokeapi.models.Format
|
||||
import net.thauvin.erik.jokeapi.models.IdRange
|
||||
import org.junit.jupiter.api.BeforeAll
|
||||
import org.junit.jupiter.api.Test
|
||||
import java.util.logging.ConsoleHandler
|
||||
import java.util.logging.Level
|
||||
import org.junit.jupiter.api.extension.ExtendWith
|
||||
import kotlin.test.assertContains
|
||||
|
||||
@ExtendWith(BeforeAllTests::class)
|
||||
internal class GetRawJokesTest {
|
||||
@Test
|
||||
fun `Get Raw Joke with TXT`() {
|
||||
|
@ -79,15 +77,4 @@ internal class GetRawJokesTest {
|
|||
val response = getRawJokes(contains = "foo", safe = true, amount = 2, idRange = IdRange(160, 161))
|
||||
assertContains(response, "\"error\": true", false, "getRawJokes(foo)")
|
||||
}
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
@BeforeAll
|
||||
fun beforeAll() {
|
||||
with(logger) {
|
||||
addHandler(ConsoleHandler().apply { level = Level.FINE })
|
||||
level = Level.FINE
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,13 +53,12 @@ import net.thauvin.erik.jokeapi.models.IdRange
|
|||
import net.thauvin.erik.jokeapi.models.Joke
|
||||
import net.thauvin.erik.jokeapi.models.Language
|
||||
import net.thauvin.erik.jokeapi.models.Type
|
||||
import org.junit.jupiter.api.BeforeAll
|
||||
import org.junit.jupiter.api.Test
|
||||
import java.util.logging.ConsoleHandler
|
||||
import java.util.logging.Level
|
||||
import org.junit.jupiter.api.extension.ExtendWith
|
||||
import kotlin.test.assertContains
|
||||
|
||||
class JokeConfigTest {
|
||||
@ExtendWith(BeforeAllTests::class)
|
||||
internal class JokeConfigTest {
|
||||
@Test
|
||||
fun `Get Joke with Default Builder`() {
|
||||
val joke = getJoke()
|
||||
|
@ -181,15 +180,4 @@ class JokeConfigTest {
|
|||
prop(JokeConfig::auth).isEqualTo(auth)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
@BeforeAll
|
||||
fun beforeAll() {
|
||||
with(logger) {
|
||||
addHandler(ConsoleHandler().apply { level = Level.FINE })
|
||||
level = Level.FINE
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,13 +36,12 @@ import assertk.assertThat
|
|||
import assertk.assertions.contains
|
||||
import org.json.JSONException
|
||||
import org.json.JSONObject
|
||||
import org.junit.jupiter.api.BeforeAll
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.assertThrows
|
||||
import java.util.logging.ConsoleHandler
|
||||
import java.util.logging.Level
|
||||
import org.junit.jupiter.api.extension.ExtendWith
|
||||
|
||||
class UtilTest {
|
||||
@ExtendWith(BeforeAllTests::class)
|
||||
internal class UtilTest {
|
||||
@Test
|
||||
fun `Invalid JSON Error`() {
|
||||
assertThrows<JSONException> { parseError(JSONObject("{}")) }
|
||||
|
@ -59,15 +58,4 @@ class UtilTest {
|
|||
val body = fetchUrl("https://postman-echo.com/get", token)
|
||||
assertThat(body, "body").contains("\"authentication\":\"$token\"")
|
||||
}
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
@BeforeAll
|
||||
fun beforeAll() {
|
||||
with(JokeApi.logger) {
|
||||
addHandler(ConsoleHandler().apply { level = Level.FINE })
|
||||
level = Level.FINE
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue