Repository: tipsy/javalin
Pull request #1503 (2022-04-06 13:53:45)

[tests] Move from Unirest 1.x to Unirest 3.x


Patch:
diff --git a/javalin-graphql/pom.xml b/javalin-graphql/pom.xml
index c9fcd463..e4bfb8fa 100644
--- a/javalin-graphql/pom.xml
+++ b/javalin-graphql/pom.xml
@@ -57,7 +57,7 @@
             <scope>test</scope>
         </dependency>
         <dependency>
-            <groupId>com.mashape.unirest</groupId>
+            <groupId>com.konghq</groupId>
             <artifactId>unirest-java</artifactId>
             <scope>test</scope>
         </dependency>
diff --git a/javalin-openapi/pom.xml b/javalin-openapi/pom.xml
index 37e0d4f9..b60aa48d 100644
--- a/javalin-openapi/pom.xml
+++ b/javalin-openapi/pom.xml
@@ -82,7 +82,7 @@
             <scope>test</scope>
         </dependency>
         <dependency>
-            <groupId>com.mashape.unirest</groupId>
+            <groupId>com.konghq</groupId>
             <artifactId>unirest-java</artifactId>
             <scope>test</scope>
         </dependency>
diff --git a/javalin/pom.xml b/javalin/pom.xml
index b8e56268..945c4866 100644
--- a/javalin/pom.xml
+++ b/javalin/pom.xml
@@ -120,7 +120,7 @@
             <scope>test</scope>
         </dependency>
         <dependency>
-            <groupId>com.mashape.unirest</groupId>
+            <groupId>com.konghq</groupId>
             <artifactId>unirest-java</artifactId>
             <scope>test</scope>
         </dependency>
diff --git a/pom.xml b/pom.xml
index d1f373a8..d0067aff 100644
--- a/pom.xml
+++ b/pom.xml
@@ -73,7 +73,7 @@
         <shade.plugin.version>3.2.4</shade.plugin.version>
         <javadoc.plugin.version>3.3.0</javadoc.plugin.version>
         <build-helper.plugin.version>3.2.0</build-helper.plugin.version>
-        <enforcer.plugin.version>3.0.0-M3</enforcer.plugin.version>
+        <enforcer.plugin.version>3.0.0</enforcer.plugin.version>
         <clean.plugin.version>3.1.0</clean.plugin.version>
         <install.plugin.version>3.0.0-M1</install.plugin.version>
         <resources.plugin.version>3.2.0</resources.plugin.version>
@@ -116,7 +116,7 @@
         <bytebuddy.version>1.11.13</bytebuddy.version>
         <bytebuddyagent.version>1.11.13</bytebuddyagent.version>
         <okhttp.version>4.9.1</okhttp.version>
-        <unirest.version>1.4.9</unirest.version>
+        <unirest.version>3.13.6</unirest.version>
         <selenium.chrome.driver.version>4.1.3</selenium.chrome.driver.version>
         <webdrivermanager.version>5.1.0</webdrivermanager.version>
     </properties>
@@ -348,7 +348,7 @@
                 <version>${assertj.version}</version>
             </dependency>
             <dependency>
-                <groupId>com.mashape.unirest</groupId>
+                <groupId>com.konghq</groupId>
                 <artifactId>unirest-java</artifactId>
                 <version>${unirest.version}</version>
             </dependency>


Test patch:
diff --git a/javalin-graphql/src/test/kotlin/io/javalin/plugin/graphql/TestGraphQL.kt b/javalin-graphql/src/test/kotlin/io/javalin/plugin/graphql/TestGraphQL.kt
index 72772752..43b23d24 100644
--- a/javalin-graphql/src/test/kotlin/io/javalin/plugin/graphql/TestGraphQL.kt
+++ b/javalin-graphql/src/test/kotlin/io/javalin/plugin/graphql/TestGraphQL.kt
@@ -1,15 +1,15 @@
 package io.javalin.plugin.graphql
 
-import com.mashape.unirest.http.JsonNode
 import io.javalin.Javalin
 import io.javalin.plugin.graphql.helpers.*
 import io.javalin.testing.HttpUtil
 import io.javalin.testing.TestUtil
+import kong.unirest.JsonNode
+import kong.unirest.json.JSONObject
 import org.assertj.core.api.Assertions.assertThat
 import org.java_websocket.client.WebSocketClient
 import org.java_websocket.drafts.Draft_6455
 import org.java_websocket.handshake.ServerHandshake
-import org.json.JSONObject
 import org.junit.jupiter.api.Assertions.assertEquals
 import org.junit.jupiter.api.Assertions.assertFalse
 import org.junit.jupiter.api.Assertions.assertTrue
@@ -110,8 +110,7 @@ class TestGraphQL {
 
     private fun sendPetition(httpUtil: HttpUtil, body: String): JSONObject {
         val response = httpUtil.post(graphqlPath).body(JsonNode(body)).asString()
-        val json = JSONObject(response.body)
-        return json
+        return JSONObject(response.body)
     }
 
     internal open inner class TestClient(var app: Javalin, path: String, headers: Map<String, String> = emptyMap()) : WebSocketClient(URI.create("ws://localhost:" + app.port() + path), Draft_6455(), headers, 0) {
diff --git a/javalin-openapi/src/test/java/io/javalin/plugin/openapi/TestOpenApi.kt b/javalin-openapi/src/test/java/io/javalin/plugin/openapi/TestOpenApi.kt
index 2f237a21..bfc51f2f 100644
--- a/javalin-openapi/src/test/java/io/javalin/plugin/openapi/TestOpenApi.kt
+++ b/javalin-openapi/src/test/java/io/javalin/plugin/openapi/TestOpenApi.kt
@@ -18,7 +18,6 @@ import cc.vileda.openapi.dsl.securityScheme
 import cc.vileda.openapi.dsl.server
 import cc.vileda.openapi.dsl.tag
 import com.fasterxml.jackson.databind.SerializationFeature
-import com.mashape.unirest.http.Unirest
 import io.javalin.Javalin
 import io.javalin.apibuilder.ApiBuilder.crud
 import io.javalin.apibuilder.CrudHandler
@@ -42,6 +41,7 @@ import io.swagger.v3.oas.models.info.Info
 import io.swagger.v3.oas.models.security.SecurityRequirement
 import io.swagger.v3.oas.models.security.SecurityScheme
 import io.swagger.v3.oas.models.servers.Server
+import kong.unirest.Unirest
 import org.assertj.core.api.Assertions.assertThat
 import org.assertj.core.api.Assertions.assertThatExceptionOfType
 import org.junit.jupiter.api.Test
diff --git a/javalin/src/test/java/io/javalin/TestAccessManager.kt b/javalin/src/test/java/io/javalin/TestAccessManager.kt
index e5c0c1cc..eb7b09de 100644
--- a/javalin/src/test/java/io/javalin/TestAccessManager.kt
+++ b/javalin/src/test/java/io/javalin/TestAccessManager.kt
@@ -7,13 +7,13 @@
 
 package io.javalin
 
-import com.mashape.unirest.http.Unirest
 import io.javalin.TestAccessManager.MyRoles.ROLE_ONE
 import io.javalin.TestAccessManager.MyRoles.ROLE_TWO
 import io.javalin.apibuilder.ApiBuilder.crud
 import io.javalin.apibuilder.ApiBuilder.get
 import io.javalin.core.security.RouteRole
 import io.javalin.testing.TestUtil
+import kong.unirest.Unirest
 import org.assertj.core.api.Assertions.assertThat
 import org.junit.jupiter.api.Test
 
diff --git a/javalin/src/test/java/io/javalin/TestApiBuilder.kt b/javalin/src/test/java/io/javalin/TestApiBuilder.kt
index f1e08f76..708a2695 100644
--- a/javalin/src/test/java/io/javalin/TestApiBuilder.kt
+++ b/javalin/src/test/java/io/javalin/TestApiBuilder.kt
@@ -7,8 +7,6 @@
 
 package io.javalin
 
-import com.mashape.unirest.http.HttpMethod
-import com.mashape.unirest.http.Unirest
 import io.javalin.apibuilder.ApiBuilder
 import io.javalin.apibuilder.ApiBuilder.after
 import io.javalin.apibuilder.ApiBuilder.before
@@ -24,6 +22,8 @@ import io.javalin.http.Context
 import io.javalin.http.Handler
 import io.javalin.testing.TestUtil
 import io.javalin.testing.TestUtil.okHandler
+import kong.unirest.HttpMethod
+import kong.unirest.Unirest
 import org.assertj.core.api.Assertions.assertThat
 import org.assertj.core.api.Assertions.assertThatExceptionOfType
 import org.junit.jupiter.api.Test
diff --git a/javalin/src/test/java/io/javalin/TestCompression.kt b/javalin/src/test/java/io/javalin/TestCompression.kt
index 65416c24..58532b96 100644
--- a/javalin/src/test/java/io/javalin/TestCompression.kt
+++ b/javalin/src/test/java/io/javalin/TestCompression.kt
@@ -6,7 +6,6 @@
 
 package io.javalin
 
-import com.mashape.unirest.http.Unirest
 import com.nixxcode.jvmbrotli.common.BrotliLoader
 import com.nixxcode.jvmbrotli.dec.BrotliInputStream
 import io.javalin.core.compression.Brotli
@@ -17,6 +16,7 @@ import io.javalin.core.util.OptionalDependency
 import io.javalin.http.OutputStreamWrapper
 import io.javalin.http.staticfiles.Location
 import io.javalin.testing.TestUtil
+import kong.unirest.Unirest
 import okhttp3.Headers
 import okhttp3.OkHttpClient
 import okhttp3.Request
diff --git a/javalin/src/test/java/io/javalin/TestCookie.kt b/javalin/src/test/java/io/javalin/TestCookie.kt
index 4b8c10e5..13a2ead4 100644
--- a/javalin/src/test/java/io/javalin/TestCookie.kt
+++ b/javalin/src/test/java/io/javalin/TestCookie.kt
@@ -1,10 +1,10 @@
 package io.javalin
 
-import com.mashape.unirest.http.Unirest
 import io.javalin.core.util.Header
 import io.javalin.http.Cookie
 import io.javalin.http.SameSite
 import io.javalin.testing.TestUtil
+import kong.unirest.Unirest
 import org.assertj.core.api.Assertions.assertThat
 import org.junit.jupiter.api.Test
 
diff --git a/javalin/src/test/java/io/javalin/TestCors.kt b/javalin/src/test/java/io/javalin/TestCors.kt
index 048849b9..0b188ddb 100644
--- a/javalin/src/test/java/io/javalin/TestCors.kt
+++ b/javalin/src/test/java/io/javalin/TestCors.kt
@@ -6,7 +6,6 @@
 
 package io.javalin
 
-import com.mashape.unirest.http.Unirest
 import io.javalin.core.util.Header.ACCESS_CONTROL_ALLOW_CREDENTIALS
 import io.javalin.core.util.Header.ACCESS_CONTROL_ALLOW_HEADERS
 import io.javalin.core.util.Header.ACCESS_CONTROL_ALLOW_METHODS
@@ -16,6 +15,7 @@ import io.javalin.core.util.Header.ACCESS_CONTROL_REQUEST_METHOD
 import io.javalin.core.util.Header.ORIGIN
 import io.javalin.core.util.Header.REFERER
 import io.javalin.testing.TestUtil
+import kong.unirest.Unirest
 import org.assertj.core.api.Assertions.assertThat
 import org.assertj.core.api.Assertions.assertThatExceptionOfType
 import org.junit.jupiter.api.Test
@@ -34,7 +34,7 @@ class TestCors {
         val javalin = Javalin.create { it.enableCorsForOrigin("origin-1", "referer-1") }
         TestUtil.test(javalin) { app, http ->
             app.get("/") { ctx -> ctx.result("Hello") }
-            assertThat(Unirest.get(http.origin).asString().headers[ACCESS_CONTROL_ALLOW_ORIGIN]).isNull()
+            assertThat(Unirest.get(http.origin).asString().headers[ACCESS_CONTROL_ALLOW_ORIGIN]).isEmpty()
             assertThat(Unirest.get(http.origin).header(ORIGIN, "origin-1").asString().headers[ACCESS_CONTROL_ALLOW_ORIGIN]!![0]).isEqualTo("origin-1")
             assertThat(Unirest.get(http.origin).header(REFERER, "referer-1").asString().headers[ACCESS_CONTROL_ALLOW_ORIGIN]!![0]).isEqualTo("referer-1")
         }
@@ -45,8 +45,8 @@ class TestCors {
         val javalin = Javalin.create { it.enableCorsForOrigin("origin-1.com") }
         TestUtil.test(javalin) { app, http ->
             app.get("/") { ctx -> ctx.result("Hello") }
-            assertThat(Unirest.get(http.origin).header(ORIGIN, "origin-2.com").asString().headers[ACCESS_CONTROL_ALLOW_ORIGIN]).isNull()
-            assertThat(Unirest.get(http.origin).header(ORIGIN, "origin-1.com.au").asString().headers[ACCESS_CONTROL_ALLOW_ORIGIN]).isNull()
+            assertThat(Unirest.get(http.origin).header(ORIGIN, "origin-2.com").asString().headers[ACCESS_CONTROL_ALLOW_ORIGIN]).isEmpty()
+            assertThat(Unirest.get(http.origin).header(ORIGIN, "origin-1.com.au").asString().headers[ACCESS_CONTROL_ALLOW_ORIGIN]).isEmpty()
         }
     }
 
@@ -58,11 +58,10 @@ class TestCors {
             assertThat(Unirest.get(http.origin).header("Origin", "some-origin").asString().headers[ACCESS_CONTROL_ALLOW_ORIGIN]!![0]).isEqualTo("some-origin")
             assertThat(Unirest.get(http.origin).header("Origin", "some-origin").asString().headers[ACCESS_CONTROL_ALLOW_CREDENTIALS]!![0]).isEqualTo("true") // cookies allowed
             assertThat(Unirest.get(http.origin).header("Referer", "some-referer").asString().headers[ACCESS_CONTROL_ALLOW_ORIGIN]!![0]).isEqualTo("some-referer")
-            assertThat(Unirest.get(http.origin).asString().headers[ACCESS_CONTROL_ALLOW_ORIGIN]).isNull()
+            assertThat(Unirest.get(http.origin).asString().headers[ACCESS_CONTROL_ALLOW_ORIGIN]).isEmpty()
         }
     }
 
-
     @Test
     fun `enableCorsForAllOrigins enables cors for all origins with AccessManager`() {
         val accessManagedCorsApp = Javalin.create {
@@ -84,7 +83,6 @@ class TestCors {
         }
     }
 
-
     @Test
     fun `enableCorsForAllOrigins allows options endpoint mapping`() {
         val javalin = Javalin.create { it.enableCorsForAllOrigins() }
diff --git a/javalin/src/test/java/io/javalin/TestCustomJetty.kt b/javalin/src/test/java/io/javalin/TestCustomJetty.kt
index 27440eda..fbe0f7ae 100644
--- a/javalin/src/test/java/io/javalin/TestCustomJetty.kt
+++ b/javalin/src/test/java/io/javalin/TestCustomJetty.kt
@@ -7,11 +7,11 @@
 
 package io.javalin
 
-import com.mashape.unirest.http.Unirest
 import io.javalin.core.LoomUtil
 import io.javalin.http.HttpCode
 import io.javalin.testing.TestServlet
 import io.javalin.testing.TestUtil
+import kong.unirest.Unirest
 import org.assertj.core.api.Assertions.assertThat
 import org.eclipse.jetty.server.ForwardedRequestCustomizer
 import org.eclipse.jetty.server.Handler
diff --git a/javalin/src/test/java/io/javalin/TestEncoding.kt b/javalin/src/test/java/io/javalin/TestEncoding.kt
index e4a24e4b..f7f906e5 100644
--- a/javalin/src/test/java/io/javalin/TestEncoding.kt
+++ b/javalin/src/test/java/io/javalin/TestEncoding.kt
@@ -7,10 +7,10 @@
 
 package io.javalin
 
-import com.mashape.unirest.http.Unirest
 import io.javalin.core.util.Header
 import io.javalin.http.ContentType
 import io.javalin.testing.TestUtil
+import kong.unirest.Unirest
 import org.assertj.core.api.Assertions.assertThat
 import org.junit.jupiter.api.Test
 import java.net.URLEncoder
diff --git a/javalin/src/test/java/io/javalin/TestEtags.kt b/javalin/src/test/java/io/javalin/TestEtags.kt
index b369ebaf..eaf300e1 100644
--- a/javalin/src/test/java/io/javalin/TestEtags.kt
+++ b/javalin/src/test/java/io/javalin/TestEtags.kt
@@ -6,15 +6,15 @@
 
 package io.javalin
 
-import com.mashape.unirest.http.Unirest
 import io.javalin.core.util.Header
 import io.javalin.testing.TestUtil
+import kong.unirest.Unirest
 import org.assertj.core.api.Assertions.assertThat
 import org.junit.jupiter.api.Test
 
 class TestEtags {
 
-    val etagsEnabledApp = Javalin.create { it.autogenerateEtags = true }
+    private val etagsEnabledApp = Javalin.create { it.autogenerateEtags = true }
 
     @Test
     fun `default app does not set etags for GET`() = TestUtil.test { app, http ->
@@ -40,7 +40,7 @@ class TestEtags {
 
     @Test
     fun `autogenerated etags work for input stream response`() = TestUtil.test(etagsEnabledApp) { app, http ->
-        app.get("/inputStreamResult") { ctx -> ctx.result(javaClass.getResourceAsStream("/public/file")) }
+        app.get("/inputStreamResult") { ctx -> ctx.result(javaClass.getResourceAsStream("/public/file")!!) }
         val response = Unirest.get(http.origin + "/inputStreamResult").asString()
         assertThat(response.status).isEqualTo(200)
         assertThat(response.body).isEqualTo("TESTFILE")
diff --git a/javalin/src/test/java/io/javalin/TestFilters.kt b/javalin/src/test/java/io/javalin/TestFilters.kt
index 9092dafd..b846a2c9 100644
--- a/javalin/src/test/java/io/javalin/TestFilters.kt
+++ b/javalin/src/test/java/io/javalin/TestFilters.kt
@@ -7,8 +7,8 @@
 
 package io.javalin
 
-import com.mashape.unirest.http.HttpMethod
 import io.javalin.testing.TestUtil
+import kong.unirest.HttpMethod
 import org.assertj.core.api.Assertions.assertThat
 import org.junit.jupiter.api.Test
 
diff --git a/javalin/src/test/java/io/javalin/TestFuture.kt b/javalin/src/test/java/io/javalin/TestFuture.kt
index e5dfa592..fe6789c0 100644
--- a/javalin/src/test/java/io/javalin/TestFuture.kt
+++ b/javalin/src/test/java/io/javalin/TestFuture.kt
@@ -121,7 +121,7 @@ class TestFuture {
         assertThat(contentResponse.headers.getFirst(Header.CONTENT_TYPE)).isEqualTo(ContentType.JSON)
         val noContentResponse = http.get("/?no-content")
         assertThat(noContentResponse.status).isEqualTo(204)
-        assertThat(noContentResponse.body).isEqualTo(null)
+        assertThat(noContentResponse.body).isEqualTo("")
         assertThat(noContentResponse.headers.getFirst(Header.CONTENT_TYPE)).isEqualTo(ContentType.PLAIN)
     }
 
diff --git a/javalin/src/test/java/io/javalin/TestGracefulShutdown.java b/javalin/src/test/java/io/javalin/TestGracefulShutdown.java
index 8e56af29..671ca168 100644
--- a/javalin/src/test/java/io/javalin/TestGracefulShutdown.java
+++ b/javalin/src/test/java/io/javalin/TestGracefulShutdown.java
@@ -7,11 +7,11 @@
  */
 
 package io.javalin;
-
-import com.mashape.unirest.http.HttpResponse;
-import com.mashape.unirest.http.Unirest;
+;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
+import kong.unirest.HttpResponse;
+import kong.unirest.Unirest;
 import org.eclipse.jetty.server.Server;
 import org.eclipse.jetty.server.handler.StatisticsHandler;
 import org.junit.jupiter.api.Disabled;
diff --git a/javalin/src/test/java/io/javalin/TestRequest.kt b/javalin/src/test/java/io/javalin/TestRequest.kt
index 32cf71f7..a9eec91b 100644
--- a/javalin/src/test/java/io/javalin/TestRequest.kt
+++ b/javalin/src/test/java/io/javalin/TestRequest.kt
@@ -6,12 +6,12 @@
 
 package io.javalin
 
-import com.mashape.unirest.http.Unirest
 import io.javalin.core.security.BasicAuthFilter
 import io.javalin.core.util.Header
 import io.javalin.http.staticfiles.Location
 import io.javalin.http.util.ContextUtil
 import io.javalin.testing.TestUtil
+import kong.unirest.Unirest
 import org.assertj.core.api.Assertions.assertThat
 import org.junit.jupiter.api.Test
 
@@ -365,7 +365,7 @@ class TestRequest {
     @Test
     fun `userAgent works`() = TestUtil.test { app, http ->
         app.get("/") { ctx -> ctx.result(ctx.userAgent()!!) }
-        assertThat(http.getBody("/")).isEqualTo("unirest-java/1.3.11")
+        assertThat(http.getBody("/")).isEqualTo("unirest-java/3.1.00")
     }
 
     @Test
diff --git a/javalin/src/test/java/io/javalin/TestResponse.kt b/javalin/src/test/java/io/javalin/TestResponse.kt
index da94c128..9c4d1a07 100644
--- a/javalin/src/test/java/io/javalin/TestResponse.kt
+++ b/javalin/src/test/java/io/javalin/TestResponse.kt
@@ -7,20 +7,18 @@
 
 package io.javalin
 
-import com.mashape.unirest.http.HttpMethod
-import com.mashape.unirest.http.Unirest
 import io.javalin.core.util.Header
 import io.javalin.http.ContentType
 import io.javalin.http.util.SeekableWriter
 import io.javalin.testing.TestUtil
+import kong.unirest.HttpMethod
+import kong.unirest.Unirest
 import org.apache.commons.io.FileUtils
-import org.apache.commons.io.IOUtils
 import org.assertj.core.api.Assertions.assertThat
 import org.junit.jupiter.api.Disabled
 import org.junit.jupiter.api.Test
 import org.junit.jupiter.api.io.TempDir
 import java.io.ByteArrayInputStream
-import java.io.ByteArrayOutputStream
 import java.io.File
 import java.util.*
 
@@ -55,10 +53,9 @@ class TestResponse {
         }
 
         app.get("/hello") { ctx -> ctx.result(bytes) }
-        val response = http.call(HttpMethod.GET, "/hello")
-        val bout = ByteArrayOutputStream()
-        assertThat(IOUtils.copy(response.rawBody, bout)).isEqualTo(bytes.size)
-        assertThat(bytes).isEqualTo(bout.toByteArray())
+        val response = Unirest.get("${http.origin}/hello").asBytes()
+        assertThat(response.body.size).isEqualTo(bytes.size)
+        assertThat(bytes).isEqualTo(response.body)
     }
 
     @Test
@@ -66,10 +63,9 @@ class TestResponse {
         val buf = ByteArray(65537) // big and not on a page boundary
         Random().nextBytes(buf)
         app.get("/stream") { ctx -> ctx.result(ByteArrayInputStream(buf)) }
-        val response = http.call(HttpMethod.GET, "/stream")
-        val bout = ByteArrayOutputStream()
-        assertThat(IOUtils.copy(response.rawBody, bout)).isEqualTo(buf.size)
-        assertThat(buf).isEqualTo(bout.toByteArray())
+        val response = Unirest.get("${http.origin}/stream").asBytes()
+        assertThat(response.body.size).isEqualTo(buf.size)
+        assertThat(buf).isEqualTo(response.body)
     }
 
     @Test
@@ -179,13 +175,20 @@ class TestResponse {
     }
 
     @Test
-    @Disabled("This functionality is apparently broken")
+    @Disabled("https://github.com/tipsy/javalin/issues/1502")
     fun `seekable - overreaching range works`() = TestUtil.test { app, http ->
         app.get("/seekable-3") { ctx -> ctx.seekableStream(getSeekableInput(), ContentType.PLAIN) }
         val response = Unirest.get(http.origin + "/seekable-3")
             .headers(mapOf(Header.RANGE to "bytes=0-${SeekableWriter.chunkSize * 4}"))
-            .asString().body
-        assertThat(response.length).isEqualTo(SeekableWriter.chunkSize * 3)
+            .asBytes()
+
+        println(response.headers)
+        println(SeekableWriter.chunkSize)
+        println(response.status)
+        println(response.statusText)
+        println(response.body)
+        println(response.parsingError)
+        assertThat(response.body.size).isEqualTo(SeekableWriter.chunkSize * 3)
     }
 
     @Test
diff --git a/javalin/src/test/java/io/javalin/TestRouting.kt b/javalin/src/test/java/io/javalin/TestRouting.kt
index fa7a2901..1df621e9 100644
--- a/javalin/src/test/java/io/javalin/TestRouting.kt
+++ b/javalin/src/test/java/io/javalin/TestRouting.kt
@@ -7,14 +7,15 @@
 
 package io.javalin
 
-import com.mashape.unirest.http.HttpMethod
 import io.javalin.apibuilder.ApiBuilder.after
 import io.javalin.apibuilder.ApiBuilder.get
 import io.javalin.apibuilder.ApiBuilder.path
 import io.javalin.core.routing.MissingBracketsException
 import io.javalin.core.routing.ParameterNamesNotUniqueException
 import io.javalin.core.routing.WildcardBracketAdjacentException
+import io.javalin.http.HandlerType.TRACE
 import io.javalin.testing.TestUtil
+import kong.unirest.HttpMethod
 import okhttp3.OkHttpClient
 import okhttp3.Request
 import org.assertj.core.api.Assertions.assertThat
@@ -44,14 +45,16 @@ class TestRouting {
         app.patch("/mapped", TestUtil.okHandler)
         app.head("/mapped", TestUtil.okHandler)
         app.options("/mapped", TestUtil.okHandler)
-        for (httpMethod in HttpMethod.values()) {
+        app.addHandler(TRACE, "/mapped", TestUtil.okHandler)
+
+        for (httpMethod in http.allMethods()) {
             assertThat(http.call(httpMethod, "/mapped").status).isEqualTo(200)
         }
     }
 
     @Test
     fun `all unmapped verbs return 404`() = TestUtil.test { _, http ->
-        for (httpMethod in HttpMethod.values()) {
+        for (httpMethod in http.allMethods()) {
             assertThat(http.call(httpMethod, "/unmapped").status).isEqualTo(404)
         }
     }
diff --git a/javalin/src/test/java/io/javalin/TestServerHeader.kt b/javalin/src/test/java/io/javalin/TestServerHeader.kt
index 9abd45b8..f3a77779 100644
--- a/javalin/src/test/java/io/javalin/TestServerHeader.kt
+++ b/javalin/src/test/java/io/javalin/TestServerHeader.kt
@@ -1,7 +1,7 @@
 package io.javalin
 
-import com.mashape.unirest.http.HttpMethod
 import io.javalin.testing.TestUtil
+import kong.unirest.HttpMethod
 import org.assertj.core.api.Assertions.assertThat
 import org.junit.jupiter.api.Test
 
@@ -11,6 +11,6 @@ class TestServerHeader {
     fun `server header is not set by default`() = TestUtil.test { app, http ->
         app.get("/hello") { ctx -> ctx.status(200).result("Hello world") }
         val response = http.call(HttpMethod.GET, "/hello")
-        assertThat(response.headers.getFirst("Server")).isNull()
+        assertThat(response.headers.getFirst("Server")).isEqualTo("")
     }
 }
diff --git a/javalin/src/test/java/io/javalin/TestWebSocket.kt b/javalin/src/test/java/io/javalin/TestWebSocket.kt
index 8aa416eb..c41857d9 100644
--- a/javalin/src/test/java/io/javalin/TestWebSocket.kt
+++ b/javalin/src/test/java/io/javalin/TestWebSocket.kt
@@ -6,7 +6,6 @@
 
 package io.javalin
 
-import com.mashape.unirest.http.Unirest
 import io.javalin.apibuilder.ApiBuilder.ws
 import io.javalin.core.util.Header
 import io.javalin.http.UnauthorizedResponse
@@ -16,6 +15,7 @@ import io.javalin.testing.TestUtil
 import io.javalin.testing.TypedException
 import io.javalin.websocket.WsContext
 import io.javalin.websocket.WsMessageContext
+import kong.unirest.Unirest
 import org.assertj.core.api.Assertions.assertThat
 import org.eclipse.jetty.websocket.api.CloseStatus
 import org.eclipse.jetty.websocket.api.MessageTooLargeException
diff --git a/javalin/src/test/java/io/javalin/http/ContentTypeTest.kt b/javalin/src/test/java/io/javalin/http/ContentTypeTest.kt
index 931ab329..e7f380e5 100644
--- a/javalin/src/test/java/io/javalin/http/ContentTypeTest.kt
+++ b/javalin/src/test/java/io/javalin/http/ContentTypeTest.kt
@@ -42,7 +42,7 @@ class ContentTypeTest {
             val response = http.get("/test.md")
             assertThat(response.status).isEqualTo(200)
             assertThat(response.body).contains("# Hello Markdown!")
-            assertThat(response.headers.getFirst(Header.CONTENT_TYPE)).isNull()
+            assertThat(response.headers.getFirst(Header.CONTENT_TYPE)).isEqualTo("")
         }
     }
 
diff --git a/javalin/src/test/java/io/javalin/staticfiles/TestSinglePageMode.kt b/javalin/src/test/java/io/javalin/staticfiles/TestSinglePageMode.kt
index 6b2a192a..9848d6d0 100644
--- a/javalin/src/test/java/io/javalin/staticfiles/TestSinglePageMode.kt
+++ b/javalin/src/test/java/io/javalin/staticfiles/TestSinglePageMode.kt
@@ -6,7 +6,6 @@
 
 package io.javalin.staticfiles
 
-import com.mashape.unirest.http.Unirest
 import io.javalin.Javalin
 import io.javalin.core.util.Header
 import io.javalin.core.util.OptionalDependency
@@ -14,6 +13,7 @@ import io.javalin.http.ContentType
 import io.javalin.http.Context
 import io.javalin.http.staticfiles.Location
 import io.javalin.testing.TestUtil
+import kong.unirest.Unirest
 import org.assertj.core.api.Assertions.assertThat
 import org.assertj.core.api.Assertions.assertThatExceptionOfType
 import org.junit.jupiter.api.Test
diff --git a/javalin/src/test/java/io/javalin/testing/HttpUtil.kt b/javalin/src/test/java/io/javalin/testing/HttpUtil.kt
index 2f526353..aad33f6f 100644
--- a/javalin/src/test/java/io/javalin/testing/HttpUtil.kt
+++ b/javalin/src/test/java/io/javalin/testing/HttpUtil.kt
@@ -6,20 +6,19 @@
 
 package io.javalin.testing
 
-import com.mashape.unirest.http.HttpMethod
-import com.mashape.unirest.http.Unirest
-import com.mashape.unirest.request.HttpRequestWithBody
 import io.javalin.http.ContentType
 import io.javalin.http.HttpCode
-import org.apache.http.impl.client.HttpClients
+import kong.unirest.HttpMethod
+import kong.unirest.Unirest
 
 class HttpUtil(port: Int) {
 
     @JvmField
     val origin: String = "http://localhost:$port"
 
-    fun enableUnirestRedirects() = Unirest.setHttpClient(HttpClients.custom().build())
-    fun disableUnirestRedirects() = Unirest.setHttpClient(HttpClients.custom().disableRedirectHandling().build())
+    fun allMethods() = HttpMethod.GET.all() // TODO: Can be changed to HttpMethod.all() when https://github.com/Kong/unirest-java/issues/439 will be fixed
+    fun enableUnirestRedirects() = Unirest.config().reset().followRedirects(true)
+    fun disableUnirestRedirects() = Unirest.config().reset().followRedirects(false)
 
     // Unirest
     fun get(path: String) = Unirest.get(origin + path).asString()
@@ -29,7 +28,7 @@ class HttpUtil(port: Int) {
     fun getBody(path: String) = Unirest.get(origin + path).asString().body
     fun getBody(path: String, headers: Map<String, String>) = Unirest.get(origin + path).headers(headers).asString().body
     fun post(path: String) = Unirest.post(origin + path)
-    fun call(method: HttpMethod, pathname: String) = HttpRequestWithBody(method, origin + pathname).asString()
+    fun call(method: HttpMethod, pathname: String) = Unirest.request(method.name(), origin + pathname).asString()
     fun htmlGet(path: String) = Unirest.get(origin + path).header("Accept", ContentType.HTML).asString()
     fun jsonGet(path: String) = Unirest.get(origin + path).header("Accept", ContentType.JSON).asString()
     fun sse(path: String) = Unirest.get(origin + path).header("Accept", "text/event-stream").header("Connection", "keep-alive").header("Cache-Control", "no-cache").asStringAsync()
diff --git a/javalin/src/test/java/io/javalin/testing/TestUtil.java b/javalin/src/test/java/io/javalin/testing/TestUtil.java
index b31b520b..22ec7f0d 100644
--- a/javalin/src/test/java/io/javalin/testing/TestUtil.java
+++ b/javalin/src/test/java/io/javalin/testing/TestUtil.java
@@ -6,10 +6,10 @@
 
 package io.javalin.testing;
 
-import com.mashape.unirest.http.HttpMethod;
 import io.javalin.Javalin;
 import io.javalin.core.util.JavalinLogger;
 import io.javalin.http.Handler;
+import kong.unirest.HttpMethod;
 import java.io.ByteArrayOutputStream;
 import java.io.PrintStream;