11/*
2- * Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
2+ * Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
33 */
44
55package kotlinx.rpc.krpc.test
@@ -12,6 +12,7 @@ import java.time.LocalDateTime
1212import java.time.format.DateTimeFormatter
1313import kotlin.coroutines.CoroutineContext
1414import kotlin.coroutines.resumeWithException
15+ import kotlin.test.assertContentEquals
1516import kotlin.test.assertEquals
1617
1718@OptIn(ExperimentalCoroutinesApi ::class )
@@ -20,9 +21,7 @@ class KrpcTestServiceBackend(override val coroutineContext: CoroutineContext) :
2021 const val SHARED_FLOW_REPLAY = 5
2122 }
2223
23- override suspend fun empty () {
24- println (" empty" )
25- }
24+ override suspend fun empty () {}
2625
2726 override suspend fun returnType (): String {
2827 return " test"
@@ -41,44 +40,52 @@ class KrpcTestServiceBackend(override val coroutineContext: CoroutineContext) :
4140 }
4241
4342 override suspend fun paramsSingle (arg1 : String ) {
44- println ( " SINGLE: $ arg1" )
43+ assertEquals( " test " , arg1)
4544 }
4645
4746 override suspend fun paramsDouble (arg1 : String , arg2 : String ) {
48- println (" double $arg1 $arg2 " )
47+ assertEquals(" test" , arg1)
48+ assertEquals(" test2" , arg2)
4949 }
5050
5151 override suspend fun varargParams (arg1 : String , vararg arg2 : String ) {
52- println (" vararg $arg1 ${arg2.joinToString()} " )
52+ assertEquals(" test" , arg1)
53+ assertEquals(" test2" , arg2[0 ])
54+ assertEquals(" test3" , arg2[1 ])
55+ assertEquals(emptyList(), arg2.drop(2 ))
5356 }
5457
5558 override suspend fun genericParams (arg1 : List <String >) {
56- println ( " Received list: ${arg1.joinToString()} " )
59+ assertEquals( listOf ( " test " , " test2 " , " test3 " ), arg1 )
5760 }
5861
5962 override suspend fun doubleGenericParams (arg1 : List <List <String >>) {
60- println ( " Received list of lists: ${arg1.joinToString { it.joinToString() }} }} " )
63+ assertContentEquals( listOf ( listOf ( " test " , " test2 " , " test3 " )), arg1 )
6164 }
6265
6366 @Suppress(" detekt.MaxLineLength" )
6467 override suspend fun mapParams (arg1 : Map <String , Map <Int , List <String >>>) {
65- println (" Received map: ${arg1.entries.joinToString { " ${it.key} -> ${it.value.entries.joinToString { (key, value) -> " $key -> ${value.joinToString()} " }} " }} " )
68+ assertEquals(arg1.size, 1 )
69+ assertContentEquals(arg1.keys, listOf (" key" ))
70+ assertEquals(arg1[" key" ]?.size, 1 )
71+ assertContentEquals(arg1[" key" ]?.keys, listOf (1 ))
72+ assertContentEquals(arg1[" key" ]?.get(1 ), listOf (" test" , " test2" , " test3" ))
6673 }
6774
6875 override suspend fun customType (arg1 : TestClass ): TestClass {
6976 return arg1
7077 }
7178
7279 override suspend fun nullable (arg1 : String? ): TestClass ? {
73- println (" nullable $arg1 " )
7480 return if (arg1 == null ) null else TestClass ()
7581 }
7682
7783 override suspend fun variance (
7884 arg2 : TestList <in TestClass >,
7985 arg3 : TestList2 <* >
8086 ): TestList <out TestClass > {
81- println (" variance: $arg2 $arg3 " )
87+ assertEquals(arg2.value, 42 )
88+ assertEquals(arg3.value, 42 )
8289 return TestList (3 )
8390 }
8491
@@ -98,7 +105,7 @@ class KrpcTestServiceBackend(override val coroutineContext: CoroutineContext) :
98105 override suspend fun incomingStreamAsyncCollect (arg1 : Flow <String >): Int {
99106 @Suppress(" detekt.GlobalCoroutineUsage" )
100107 GlobalScope .launch {
101- arg1.collect { println ( " incomingStreamAsyncCollect item $it " ) }
108+ assertContentEquals( listOf ( " test1 " , " test2 " , " test3 " ), arg1.toList())
102109 }
103110 return 5
104111 }
@@ -144,13 +151,13 @@ class KrpcTestServiceBackend(override val coroutineContext: CoroutineContext) :
144151 }
145152
146153 override suspend fun streamInDataClassWithStream (payloadWithPayload : PayloadWithPayload ): Int {
147- payloadWithPayload.collectAndPrint( )
154+ assertContentEquals( KrpcTransportTestBase .expectedPayloadWithPayload( 10 ), payloadWithPayload.collect() )
148155 return 5
149156 }
150157
151158 override suspend fun streamInStreamWithStream (payloadWithPayload : Flow <PayloadWithPayload >): Int {
152- payloadWithPayload.collect {
153- it.collectAndPrint( )
159+ payloadWithPayload.collectIndexed { index, it ->
160+ assertContentEquals( KrpcTransportTestBase .expectedPayloadWithPayload(index), it.collect() )
154161 }
155162 return 5
156163 }
@@ -228,7 +235,6 @@ class KrpcTestServiceBackend(override val coroutineContext: CoroutineContext) :
228235 }
229236
230237 override suspend fun answerToAnything (arg : String ): Int {
231- println (" Return 42" )
232238 return 42
233239 }
234240
@@ -276,9 +282,7 @@ class KrpcTestServiceBackend(override val coroutineContext: CoroutineContext) :
276282
277283 launch {
278284 assertEquals(listOf (0 , 1 , 2 , 3 , 4 ), sharedFlow.take(5 ).toList())
279- println (" hello 1" )
280285 state.emit(1 )
281- println (" hello 2" )
282286 }
283287
284288 return state
0 commit comments