Skip to content

Commit 01ffcc7

Browse files
Update tests & Spotless
1 parent b0125b6 commit 01ffcc7

File tree

11 files changed

+452
-203
lines changed

11 files changed

+452
-203
lines changed

app/src/main/java/io/getstream/android/core/sample/client/StreamClient.kt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,14 @@ fun createStreamClient(
105105
connectionIdHolder = connectionIdHolder,
106106
socketFactory = socketFactory,
107107
healthMonitor = healthMonitor,
108-
serializationConfig = StreamClientSerializationConfig.default(object :
109-
StreamProductEventSerialization<Unit> {
110-
override fun serialize(data: Unit): Result<String> = Result.success("")
111-
override fun deserialize(raw: String): Result<Unit> = Result.success(Unit)
112-
}),
108+
serializationConfig =
109+
StreamClientSerializationConfig.default(
110+
object : StreamProductEventSerialization<Unit> {
111+
override fun serialize(data: Unit): Result<String> = Result.success("")
112+
113+
override fun deserialize(raw: String): Result<Unit> = Result.success(Unit)
114+
}
115+
),
113116
batcher = batcher,
114117
)
115118
}

stream-android-core/src/main/java/io/getstream/android/core/api/StreamClient.kt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import io.getstream.android.core.api.processing.StreamRetryProcessor
3232
import io.getstream.android.core.api.processing.StreamSerialProcessingQueue
3333
import io.getstream.android.core.api.processing.StreamSingleFlightProcessor
3434
import io.getstream.android.core.api.serialization.StreamClientEventSerialization
35-
import io.getstream.android.core.api.serialization.StreamProductEventSerialization
3635
import io.getstream.android.core.api.socket.StreamConnectionIdHolder
3736
import io.getstream.android.core.api.socket.StreamWebSocket
3837
import io.getstream.android.core.api.socket.StreamWebSocketFactory
@@ -272,11 +271,11 @@ fun StreamClient(
272271
jsonSerialization = compositeSerialization,
273272
eventParser =
274273
StreamCompositeEventSerializationImpl(
275-
internal = serializationConfig.eventParser
276-
?: StreamClientEventSerialization(compositeSerialization),
274+
internal =
275+
serializationConfig.eventParser
276+
?: StreamClientEventSerialization(compositeSerialization),
277277
external = serializationConfig.productEventSerializers,
278-
)
279-
,
278+
),
280279
healthMonitor = healthMonitor,
281280
batcher = batcher,
282281
internalSocket = socket,

stream-android-core/src/main/java/io/getstream/android/core/api/model/config/StreamClientSerializationConfig.kt

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,14 @@ private constructor(
4444
* @param alsoExternal The event types to also parse as external.
4545
* @return A default [StreamClientSerializationConfig].
4646
*/
47-
fun <T> default(productEvents: StreamProductEventSerialization<T>, alsoExternal: Set<String> = emptySet()) =
48-
StreamClientSerializationConfig(productEventSerializers = productEvents, alsoExternal = alsoExternal)
47+
fun <T> default(
48+
productEvents: StreamProductEventSerialization<T>,
49+
alsoExternal: Set<String> = emptySet(),
50+
) =
51+
StreamClientSerializationConfig(
52+
productEventSerializers = productEvents,
53+
alsoExternal = alsoExternal,
54+
)
4955

5056
/**
5157
* Creates a [StreamClientSerializationConfig] with the given JSON serialization.
@@ -55,8 +61,16 @@ private constructor(
5561
* @param alsoExternal The event types to also parse as external.
5662
* @return A [StreamClientSerializationConfig] with the given JSON serialization.
5763
*/
58-
fun <T> json(serialization: StreamJsonSerialization, productEvents: StreamProductEventSerialization<T>, alsoExternal: Set<String> = emptySet()) =
59-
StreamClientSerializationConfig(json = serialization, productEventSerializers = productEvents, alsoExternal = alsoExternal)
64+
fun <T> json(
65+
serialization: StreamJsonSerialization,
66+
productEvents: StreamProductEventSerialization<T>,
67+
alsoExternal: Set<String> = emptySet(),
68+
) =
69+
StreamClientSerializationConfig(
70+
json = serialization,
71+
productEventSerializers = productEvents,
72+
alsoExternal = alsoExternal,
73+
)
6074

6175
/**
6276
* Creates a [StreamClientSerializationConfig] with the given event parsing.
@@ -66,7 +80,15 @@ private constructor(
6680
* @param alsoExternal The event types to also parse as external.
6781
* @return A [StreamClientSerializationConfig] with the given event parsing.
6882
*/
69-
fun <T> event(serialization: StreamClientEventSerialization, productEvents: StreamProductEventSerialization<T>, alsoExternal: Set<String> = emptySet()) =
70-
StreamClientSerializationConfig(eventParser = serialization, productEventSerializers = productEvents, alsoExternal = alsoExternal)
83+
fun <T> event(
84+
serialization: StreamClientEventSerialization,
85+
productEvents: StreamProductEventSerialization<T>,
86+
alsoExternal: Set<String> = emptySet(),
87+
) =
88+
StreamClientSerializationConfig(
89+
eventParser = serialization,
90+
productEventSerializers = productEvents,
91+
alsoExternal = alsoExternal,
92+
)
7193
}
7294
}

stream-android-core/src/main/java/io/getstream/android/core/api/serialization/StreamProductEventSerialization.kt

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/*
2+
* Copyright (c) 2014-2025 Stream.io Inc. All rights reserved.
3+
*
4+
* Licensed under the Stream License;
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://github.com/GetStream/stream-core-android/blob/main/LICENSE
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package io.getstream.android.core.api.serialization
217

318
import io.getstream.android.core.annotations.StreamCoreApi
@@ -26,8 +41,8 @@ interface StreamProductEventSerialization<T> {
2641
* Decodes a product event from a [String] representation.
2742
*
2843
* @param raw The string to deserialize.
29-
* @return `Result.success(T)` when decoding succeeds, or `Result.failure(Throwable)` when
30-
* the process fails.
44+
* @return `Result.success(T)` when decoding succeeds, or `Result.failure(Throwable)` when the
45+
* process fails.
3146
*/
3247
fun deserialize(raw: String): Result<T>
3348
}

stream-android-core/src/main/java/io/getstream/android/core/api/socket/listeners/StreamClientListener.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ package io.getstream.android.core.api.socket.listeners
1717

1818
import io.getstream.android.core.annotations.StreamCoreApi
1919
import io.getstream.android.core.api.model.connection.StreamConnectionState
20-
import io.getstream.android.core.api.model.event.StreamClientWsEvent
2120

2221
/**
2322
* Listener interface for Feeds socket events.

stream-android-core/src/main/java/io/getstream/android/core/internal/serialization/StreamCompositeEventSerializationImpl.kt

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/*
2+
* Copyright (c) 2014-2025 Stream.io Inc. All rights reserved.
3+
*
4+
* Licensed under the Stream License;
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://github.com/GetStream/stream-core-android/blob/main/LICENSE
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package io.getstream.android.core.internal.serialization
217

318
import com.squareup.moshi.JsonReader
@@ -8,22 +23,22 @@ import io.getstream.android.core.api.utils.runCatchingCancellable
823
import okio.Buffer
924

1025
/**
11-
* Represents a composite event that can be either a [StreamClientWsEvent] or a product-specific event.
26+
* Represents a composite event that can be either a [StreamClientWsEvent] or a product-specific
27+
* event.
1228
*
1329
* @param T The type of the product-specific event.
1430
*/
15-
internal class StreamCompositeSerializationEvent<T> private constructor(
16-
val core: StreamClientWsEvent? = null,
17-
val product: T? = null,
18-
) {
31+
internal class StreamCompositeSerializationEvent<T>
32+
private constructor(val core: StreamClientWsEvent? = null, val product: T? = null) {
1933
companion object {
2034
/**
2135
* Creates a new [StreamCompositeSerializationEvent] with the given [event].
2236
*
2337
* @param event The event to wrap.
2438
* @return A new [StreamCompositeSerializationEvent] with the given [event].
2539
*/
26-
fun <T> internal(event: StreamClientWsEvent) = StreamCompositeSerializationEvent<T>(core = event)
40+
fun <T> internal(event: StreamClientWsEvent) =
41+
StreamCompositeSerializationEvent<T>(core = event)
2742

2843
/**
2944
* Creates a new [StreamCompositeSerializationEvent] with the given [event].
@@ -52,7 +67,8 @@ internal class StreamCompositeSerializationEvent<T> private constructor(
5267
internal class StreamCompositeEventSerializationImpl<T>(
5368
private val internal: StreamClientEventSerialization,
5469
private val external: StreamProductEventSerialization<T>,
55-
private val internalTypes: Set<String> = setOf("connection.ok", "connection.error", "health.check"),
70+
private val internalTypes: Set<String> =
71+
setOf("connection.ok", "connection.error", "health.check"),
5672
private val alsoExternal: Set<String> = emptySet(),
5773
) {
5874
/**
@@ -63,8 +79,12 @@ internal class StreamCompositeEventSerializationImpl<T>(
6379
* the process fails.
6480
*/
6581
fun serialize(data: StreamCompositeSerializationEvent<T>): Result<String> {
66-
data.core?.let { return internal.serialize(it) }
67-
data.product?.let { return external.serialize(it) }
82+
data.core?.let {
83+
return internal.serialize(it)
84+
}
85+
data.product?.let {
86+
return external.serialize(it)
87+
}
6888
return Result.failure(NullPointerException())
6989
}
7090

@@ -86,14 +106,16 @@ internal class StreamCompositeEventSerializationImpl<T>(
86106
}
87107
in alsoExternal -> {
88108
val coreSer = internal
89-
val extSer = external
109+
val extSer = external
90110
val core = coreSer.deserialize(raw).getOrThrow()
91111
val prod = extSer.deserialize(raw).getOrThrow()
92112
Result.success(StreamCompositeSerializationEvent.both(core, prod))
93113
}
94114
in internalTypes -> {
95115
val coreSer = internal
96-
coreSer.deserialize(raw).map { StreamCompositeSerializationEvent.internal(it) }
116+
coreSer.deserialize(raw).map {
117+
StreamCompositeSerializationEvent.internal(it)
118+
}
97119
}
98120
else -> {
99121
val ext = external
@@ -109,24 +131,30 @@ internal class StreamCompositeEventSerializationImpl<T>(
109131
val reader = JsonReader.of(Buffer().writeUtf8(raw))
110132
reader.isLenient = true
111133
return try {
112-
if (reader.peek() != JsonReader.Token.BEGIN_OBJECT) return null
134+
if (reader.peek() != JsonReader.Token.BEGIN_OBJECT) {
135+
return null
136+
}
113137
reader.beginObject()
114138
var result: String? = null
115139
while (reader.hasNext()) {
116140
val name = reader.nextName()
117141
if (name == "type" && reader.peek() == JsonReader.Token.STRING) {
118142
result = reader.nextString()
119143
// consume the rest to keep reader state valid
120-
while (reader.hasNext()) reader.skipValue()
144+
while (reader.hasNext()) {
145+
reader.skipValue()
146+
}
121147
break
122148
} else {
123149
reader.skipValue()
124150
}
125151
}
126-
if (reader.peek() == JsonReader.Token.END_OBJECT) reader.endObject()
152+
if (reader.peek() == JsonReader.Token.END_OBJECT) {
153+
reader.endObject()
154+
}
127155
result
128156
} catch (_: Throwable) {
129157
null
130158
}
131159
}
132-
}
160+
}

stream-android-core/src/main/java/io/getstream/android/core/internal/socket/StreamSocketSession.kt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -198,12 +198,13 @@ internal class StreamSocketSession<T>(
198198
eventParser
199199
.deserialize(message)
200200
.onSuccess { event ->
201-
202201
logger.v { "[onBatch] Deserialized event: $event" }
203202
val coreEvent = event.core
204203
val productEvent = event.product
205204

206-
if (coreEvent != null && coreEvent is StreamClientConnectionErrorEvent) {
205+
if (
206+
coreEvent != null && coreEvent is StreamClientConnectionErrorEvent
207+
) {
207208
notifyState(
208209
StreamConnectionState.Disconnected(
209210
StreamEndpointException("Connection error", coreEvent.error)
@@ -324,9 +325,7 @@ internal class StreamSocketSession<T>(
324325
logger.d { "[onMessage] Socket message (string): $text" }
325326
eventParser
326327
.deserialize(text)
327-
.map {
328-
it.core
329-
}
328+
.map { it.core }
330329
.map { authResponse ->
331330
when (authResponse) {
332331
is StreamClientConnectedEvent -> {

stream-android-core/src/test/java/io/getstream/android/core/internal/client/StreamClientIImplTest.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class StreamClientIImplTest {
4848
private lateinit var singleFlight: StreamSingleFlightProcessor
4949
private lateinit var serialQueue: StreamSerialProcessingQueue
5050
private lateinit var connectionIdHolder: StreamConnectionIdHolder
51-
private lateinit var socketSession: StreamSocketSession
51+
private lateinit var socketSession: StreamSocketSession<Unit>
5252
private lateinit var logger: StreamLogger
5353

5454
private lateinit var subscriptionManager: StreamSubscriptionManager<StreamClientListener>
@@ -93,7 +93,6 @@ class StreamClientIImplTest {
9393
connectionIdHolder = connectionIdHolder,
9494
socketSession = socketSession,
9595
logger = logger,
96-
retryProcessor = mockk(relaxed = true),
9796
mutableConnectionState = connFlow,
9897
scope = scope,
9998
subscriptionManager = subscriptionManager,

stream-android-core/src/test/java/io/getstream/android/core/internal/http/interceptor/StreamApiKeyInterceptorTest.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package io.getstream.android.core.internal.http.interceptor
1717

1818
import io.getstream.android.core.api.model.exceptions.StreamClientException
19+
import io.getstream.android.core.api.model.exceptions.StreamEndpointException
1920
import io.getstream.android.core.api.model.value.StreamApiKey
2021
import io.getstream.android.core.utils.boxWithReflection
2122
import io.mockk.every
@@ -70,7 +71,7 @@ class StreamApiKeyInterceptorTest {
7071
val interceptor = StreamApiKeyInterceptor(apiKey)
7172
val chain = mockChain(request)
7273

73-
assertFailsWith<StreamClientException> { interceptor.intercept(chain) }
74+
assertFailsWith<StreamEndpointException> { interceptor.intercept(chain) }
7475
}
7576

7677
// --- Helpers ---

0 commit comments

Comments
 (0)