Skip to content

Commit

Permalink
small tweak: improve name consistency on URIExtensions.kt
Browse files Browse the repository at this point in the history
  • Loading branch information
jpnovais committed Oct 23, 2024
1 parent f729f9a commit 8a01ae9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ package build.linea

import java.net.URI

fun URI.getPortWithSchemaDefaults(): Int {
fun URI.getPortWithSchemeDefaults(): Int {
return if (port != -1) {
port
} else {
when (scheme.lowercase()) {
"http" -> 80
"https" -> 443
// Focous on HTTP as it what we need for now
// Focous on HTTP as it is what we need for now
else -> throw IllegalArgumentException("Unsupported scheme: $scheme")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import java.net.URI
class URIExtensionsTest {
@Test
fun `getPortWithSchemaDefaults`() {
assertThat(URI.create("http://example.com").getPortWithSchemaDefaults()).isEqualTo(80)
assertThat(URI.create("https://example.com").getPortWithSchemaDefaults()).isEqualTo(443)
assertThat(URI.create("http://example.com:8080").getPortWithSchemaDefaults()).isEqualTo(8080)
assertThat(URI.create("https://example.com:8080").getPortWithSchemaDefaults()).isEqualTo(8080)
assertThat(URI.create("myschema://example.com:8080").getPortWithSchemaDefaults()).isEqualTo(8080)
assertThatThrownBy { (URI.create("mySchema://example.com").getPortWithSchemaDefaults()) }
assertThat(URI.create("http://example.com").getPortWithSchemeDefaults()).isEqualTo(80)
assertThat(URI.create("https://example.com").getPortWithSchemeDefaults()).isEqualTo(443)
assertThat(URI.create("http://example.com:8080").getPortWithSchemeDefaults()).isEqualTo(8080)
assertThat(URI.create("https://example.com:8080").getPortWithSchemeDefaults()).isEqualTo(8080)
assertThat(URI.create("myschema://example.com:8080").getPortWithSchemeDefaults()).isEqualTo(8080)
assertThatThrownBy { (URI.create("mySchema://example.com").getPortWithSchemeDefaults()) }
.isInstanceOf(IllegalArgumentException::class.java)
.hasMessage("Unsupported scheme: mySchema")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package net.consensys.linea.vertx

import build.linea.getPortWithSchemaDefaults
import build.linea.getPortWithSchemeDefaults
import io.vertx.core.http.HttpClientOptions
import java.net.URI

fun <T : HttpClientOptions> T.setDefaultsFrom(uri: URI): T {
isSsl = uri.scheme.lowercase() == "https"
defaultHost = uri.host
defaultPort = uri.getPortWithSchemaDefaults()
defaultPort = uri.getPortWithSchemeDefaults()

return this
}

0 comments on commit 8a01ae9

Please sign in to comment.