-
Notifications
You must be signed in to change notification settings - Fork 9.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a proper Kotlin constructor for Request #7208
Conversation
This turns out to be very useful throughout our test suite.
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.Assertions.fail; | ||
|
||
public final class RequestTest { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Converted to Kotlin.
} | ||
} | ||
|
||
@Test public void headerForbidsNullArguments() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This particular test dropped.
import org.assertj.core.api.Assertions.fail | ||
import org.junit.jupiter.api.Test | ||
|
||
class RequestTest { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Converted from Java. The first 4 tests are new.
|
okhttp-android/src/androidTest/kotlin/okhttp3/android/AndroidAsyncDnsTest.kt
Show resolved
Hide resolved
constructor( | ||
url: HttpUrl, | ||
headers: Headers = Headers.headersOf(), | ||
method: String = "\u0000", // Sentinel value chooses based on what the body is. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cute, was a bit against it at first, but it hits the sweet spot for usage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It also removes the comment I came here to make, that HttpMethods should be public API, since you need to pass in here. But not an issue since this can be left out mostly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I considered null
as the sentinel, but that lets users pass null which I don’t like.
I considered making the when
expression the default value, but that puts the parameters in a surprising order.
This is ugly, but users shouldn’t see it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2028: IETF formalises the \u0000 Verb based on widespread popularity of the just do what you need to semantics...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ooooh think of the poor C programmers, strlen on this guy isn't fun.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My concerns with the Constructor were just around additional params, but it seems to satisfy the typical cases, and use the Builder for anything more exotic (tags, ).
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okhttp/src/jvmMain/kotlin/okhttp3/Cache.kt
This turns out to be very useful throughout our test suite.