Skip to content
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

Use Kotlin's regex API in MediaType #6962

Merged
merged 1 commit into from
Dec 29, 2021
Merged

Conversation

swankjesse
Copy link
Member

Preparing to promote this class to commonMain

* This test includes tests from [Guava's](https://code.google.com/p/guava-libraries/)
* MediaTypeTest.
*/
open class MediaTypeTest {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we lose any public API protection from moving these to kotlin? I thought we had some API only java tests, but I think we remove them?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mainly about the different preferred forms for kotlin and java. MediaType.parse(string) vs string.toMediaType()

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so. We had two strategies for API compatibility: japicmp (Java source and binary compatibility) and KotlinSourceModernTest (Kotlin source compatibility). These tests jobs are testing the behavior, not the API.

okhttp/build.gradle.kts Outdated Show resolved Hide resolved
@@ -71,6 +71,9 @@ object Dependencies {
const val kotlinReflect = "org.jetbrains.kotlin:kotlin-reflect:${Versions.kotlin}"
const val kotlinStdlibOsgi = "org.jetbrains.kotlin:kotlin-osgi-bundle:${Versions.kotlin}"
const val kotlinJunit5 = "org.jetbrains.kotlin:kotlin-test-junit5:${Versions.kotlin}"
const val kotlinTest = "org.jetbrains.kotlin:kotlin-test-common:${Versions.kotlin}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need all these dependencies anymore. Just kotlin-test on commonTest.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want that to be true but it didn't work for me on my first attempt. I'll try it again.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn’t work as-is. I might need to upgrade things? Later.

> Task :okhttp:compileTestKotlinJvm FAILED
e: /Users/jwilson/Projects/okhttp/okhttp/src/jvmTest/java/okhttp3/MediaTypeGetTest.kt: (18, 20): Unresolved reference: assertEquals
e: /Users/jwilson/Projects/okhttp/okhttp/src/jvmTest/java/okhttp3/MediaTypeGetTest.kt: (19, 20): Unresolved reference: assertFailsWith
e: /Users/jwilson/Projects/okhttp/okhttp/src/jvmTest/java/okhttp3/MediaTypeTest.kt: (21, 20): Unresolved reference: Test

* MediaTypeTest.
*/
open class MediaTypeTest {
protected open fun parse(string: String): MediaType = string.toMediaType()
Copy link
Collaborator

@yschimke yschimke Dec 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be string.toMediaTypeOrNull() and the return type MediaType?, since it was

  protected MediaType parse(String string) {
    return MediaType.parse(string);
  }

while

    @JvmStatic
    @JvmName("get")
    fun String.toMediaType(): MediaType {

and

    @JvmStatic
    @JvmName("parse")
    fun String.toMediaTypeOrNull(): MediaType? {

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, good call!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I switched it cause I had to get rid of !! in the source.)

Preparing to promote this class to commonMain
@swankjesse swankjesse merged commit b23158b into master Dec 29, 2021
@oldergod oldergod deleted the jwilson.1216.kt_regex branch December 29, 2021 23:32
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants