Skip to content

Commit

Permalink
Merge pull request #178 from aaronweihe/ahe/okhttp4
Browse files Browse the repository at this point in the history
Upgrade to OkHttp 4
  • Loading branch information
tinder-ahe authored Mar 26, 2021
2 parents dd3923a + c779fbf commit 0e8833d
Show file tree
Hide file tree
Showing 12 changed files with 24 additions and 34 deletions.
5 changes: 2 additions & 3 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@ ext.versions = [
jodaTime: '2.9.9',
glide: '4.12.0',

okHttp: '3.11.0',
okHttp: '4.9.1',
okio: '1.13.0',
mockWebServer: '3.11.0',
timber: '4.6.0',
okSse: '0.9.0',

Expand Down Expand Up @@ -92,7 +91,7 @@ ext.libs = [
okHttp: "com.squareup.okhttp3:okhttp:$versions.okHttp",
okHttpLoggingInterceptor: "com.squareup.okhttp3:logging-interceptor:$versions.okHttp",
okio: "com.squareup.okio:okio:$versions.okio",
mockWebServer: "com.squareup.okhttp3:mockwebserver:$versions.mockWebServer",
mockWebServer: "com.squareup.okhttp3:mockwebserver:$versions.okHttp",
timber: "com.jakewharton.timber:timber:$versions.timber",
okSse: "com.github.heremaps:oksse:$versions.okSse",

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ import java.util.concurrent.TimeUnit

internal class GsonMessageAdapterTest {

@get:Rule
private val mockWebServer = MockWebServer()
@get:Rule val mockWebServer = MockWebServer()
private val serverUrlString by lazy { mockWebServer.url("/").toString() }

private val serverLifecycleRegistry = LifecycleRegistry()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ import java.util.concurrent.TimeUnit

internal class JacksonMessageAdapterTest {

@get:Rule
private val mockWebServer = MockWebServer()
@get:Rule val mockWebServer = MockWebServer()
private val serverUrlString by lazy { mockWebServer.url("/").toString() }

private val serverLifecycleRegistry = LifecycleRegistry()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import com.squareup.moshi.JsonAdapter
import com.squareup.moshi.JsonQualifier
import com.squareup.moshi.JsonReader
import com.squareup.moshi.JsonWriter
import com.squareup.moshi.KotlinJsonAdapterFactory
import com.squareup.moshi.Moshi
import com.squareup.moshi.ToJson
import com.tinder.scarlet.WebSocket.Event
import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory
import com.tinder.scarlet.Scarlet
import com.tinder.scarlet.Stream
import com.tinder.scarlet.WebSocket.Event
import com.tinder.scarlet.messageadapter.moshi.MoshiMessageAdapter.Factory
import com.tinder.scarlet.testutils.TestStreamObserver
import com.tinder.scarlet.testutils.containingBytes
Expand All @@ -28,7 +28,7 @@ import com.tinder.scarlet.ws.Send
import okhttp3.OkHttpClient
import okhttp3.mockwebserver.MockWebServer
import okio.Buffer
import okio.ByteString
import okio.ByteString.Companion.decodeHex
import org.assertj.core.api.Assertions.assertThat
import org.junit.Rule
import org.junit.Test
Expand All @@ -38,8 +38,7 @@ import java.util.concurrent.TimeUnit

internal class MoshiMessageAdapterTest {

@get:Rule
private val mockWebServer = MockWebServer()
@get:Rule val mockWebServer = MockWebServer()
private val serverUrlString by lazy { mockWebServer.url("/").toString() }

private lateinit var server: Service
Expand Down Expand Up @@ -196,7 +195,7 @@ internal class MoshiMessageAdapterTest {
// Given
givenConnectionIsEstablished(Factory.Config())
val jsonWithUtf8Bom = Buffer()
.write(ByteString.decodeHex("EFBBBF"))
.write("EFBBBF".decodeHex())
.writeUtf8("""{"name":"value"}""")
.readByteString()
.toByteArray()
Expand All @@ -220,7 +219,7 @@ internal class MoshiMessageAdapterTest {
// Given
givenConnectionIsEstablished(Factory.Config())
val jsonWithUtf16Bom = Buffer()
.write(ByteString.decodeHex("FEFF"))
.write("FEFF".decodeHex())
.writeString("""{"name":"value"}""", Charset.forName("UTF-16"))
.readByteString()
.toByteArray()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,15 @@ import com.tinder.scarlet.ws.Receive
import com.tinder.scarlet.ws.Send
import okhttp3.OkHttpClient
import okhttp3.mockwebserver.MockWebServer
import okio.ByteString
import okio.ByteString.Companion.decodeBase64
import org.assertj.core.api.Assertions.assertThat
import org.junit.Rule
import org.junit.Test
import java.util.concurrent.TimeUnit

internal class ProtobufMessageAdapterTest {

@get:Rule
private val mockWebServer = MockWebServer()
@get:Rule val mockWebServer = MockWebServer()
private val serverUrlString by lazy { mockWebServer.url("/").toString() }

private lateinit var server: Service
Expand All @@ -43,7 +42,7 @@ internal class ProtobufMessageAdapterTest {
// Given
givenConnectionIsEstablished()
val phone = PhoneProtos.Phone.newBuilder().setNumber("(519) 867-5309").build()
val expectedSerializedPhone = ByteString.decodeBase64("Cg4oNTE5KSA4NjctNTMwOQ==")!!.toByteArray()
val expectedSerializedPhone = "Cg4oNTE5KSA4NjctNTMwOQ==".decodeBase64()!!.toByteArray()
val serverPhoneObserver = server.receivePhone().test()

// When
Expand Down Expand Up @@ -85,7 +84,7 @@ internal class ProtobufMessageAdapterTest {
fun deserializeUsingRegistry() {
// Given
givenConnectionIsEstablished(withRegistry = true)
val serializedPhone = ByteString.decodeBase64("Cg4oNTE5KSA4NjctNTMwORAB")!!.toByteArray()
val serializedPhone = "Cg4oNTE5KSA4NjctNTMwORAB".decodeBase64()!!.toByteArray()
val serverPhoneObserver = server.receivePhone().test()

// When
Expand All @@ -110,7 +109,7 @@ internal class ProtobufMessageAdapterTest {
// Given
givenConnectionIsEstablished()
val phone = PhoneProtos.Phone.newBuilder().setNumber("(519) 867-5309").build()
val serializedPhone = ByteString.decodeBase64("Cg4oNTE5KSA4NjctNTMwOQ==")!!.toByteArray()
val serializedPhone = "Cg4oNTE5KSA4NjctNTMwOQ==".decodeBase64()!!.toByteArray()
val serverStringDeserializationObserver = server.receiveWrongClassDeserialization().test()

// When
Expand All @@ -131,7 +130,7 @@ internal class ProtobufMessageAdapterTest {
fun deserializeWrongValue() {
// Given
givenConnectionIsEstablished()
val data = ByteString.decodeBase64("////")!!.toByteArray()
val data = "////".decodeBase64()!!.toByteArray()
val serverPhoneObserver = server.receivePhoneDeserialization().test()

// When
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ import java.util.concurrent.TimeUnit

class ReceiveChannelTest {

@get:Rule
private val mockWebServer = MockWebServer()
@get:Rule val mockWebServer = MockWebServer()
private val serverUrlString by lazy { mockWebServer.url("/").toString() }

private val serverLifecycleRegistry = LifecycleRegistry()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ import java.util.concurrent.TimeUnit

class ObservableTest {

@get:Rule
private val mockWebServer = MockWebServer()
@get:Rule val mockWebServer = MockWebServer()
private val serverUrlString by lazy { mockWebServer.url("/").toString() }

private val serverLifecycleRegistry = LifecycleRegistry()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ import java.util.concurrent.TimeUnit

internal class FlowableTest {

@get:Rule
private val mockWebServer = MockWebServer()
@get:Rule val mockWebServer = MockWebServer()
private val serverUrlString by lazy { mockWebServer.url("/").toString() }

private val serverLifecycleRegistry = LifecycleRegistry()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ import java.util.concurrent.TimeUnit

class ObservableTest {

@get:Rule
private val mockWebServer = MockWebServer()
@get:Rule val mockWebServer = MockWebServer()
private val serverUrlString by lazy { mockWebServer.url("/").toString() }

private val serverLifecycleRegistry = LifecycleRegistry()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import com.tinder.scarlet.Stream
import com.tinder.scarlet.WebSocket
import com.tinder.scarlet.utils.toStream
import okhttp3.WebSocketListener
import okio.ByteString
import okio.ByteString.Companion.toByteString

class OkHttpWebSocket internal constructor(
private val okHttpWebSocketHolder: OkHttpWebSocketHolder,
Expand All @@ -30,7 +30,7 @@ class OkHttpWebSocket internal constructor(
is Message.Text -> okHttpWebSocketHolder.send(message.value)
is Message.Bytes -> {
val bytes = message.value
val byteString = ByteString.of(bytes, 0, bytes.size)
val byteString = bytes.toByteString(0, bytes.size)
okHttpWebSocketHolder.send(byteString)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ import java.util.concurrent.TimeUnit

internal class OkHttpWebSocketIntegrationTest {

@get:Rule
private val mockWebServer = MockWebServer()
@get:Rule val mockWebServer = MockWebServer()
private val serverUrlString by lazy { mockWebServer.url("/").toString() }

private val serverLifecycleRegistry = LifecycleRegistry()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ internal class StaticUrlRequestFactoryTest {
val request2 = staticUrlRequestFactory.createRequest()

// Then
assertThat(request1.url()).isEqualTo(request2.url())
assertThat(request1.url).isEqualTo(request2.url)
}
}

0 comments on commit 0e8833d

Please sign in to comment.