1
1
/*
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.
3
3
*/
4
4
5
5
package kotlinx.rpc.krpc.test
@@ -12,6 +12,7 @@ import java.time.LocalDateTime
12
12
import java.time.format.DateTimeFormatter
13
13
import kotlin.coroutines.CoroutineContext
14
14
import kotlin.coroutines.resumeWithException
15
+ import kotlin.test.assertContentEquals
15
16
import kotlin.test.assertEquals
16
17
17
18
@OptIn(ExperimentalCoroutinesApi ::class )
@@ -20,9 +21,7 @@ class KrpcTestServiceBackend(override val coroutineContext: CoroutineContext) :
20
21
const val SHARED_FLOW_REPLAY = 5
21
22
}
22
23
23
- override suspend fun empty () {
24
- println (" empty" )
25
- }
24
+ override suspend fun empty () {}
26
25
27
26
override suspend fun returnType (): String {
28
27
return " test"
@@ -41,44 +40,52 @@ class KrpcTestServiceBackend(override val coroutineContext: CoroutineContext) :
41
40
}
42
41
43
42
override suspend fun paramsSingle (arg1 : String ) {
44
- println ( " SINGLE: $ arg1" )
43
+ assertEquals( " test " , arg1)
45
44
}
46
45
47
46
override suspend fun paramsDouble (arg1 : String , arg2 : String ) {
48
- println (" double $arg1 $arg2 " )
47
+ assertEquals(" test" , arg1)
48
+ assertEquals(" test2" , arg2)
49
49
}
50
50
51
51
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 ))
53
56
}
54
57
55
58
override suspend fun genericParams (arg1 : List <String >) {
56
- println ( " Received list: ${arg1.joinToString()} " )
59
+ assertEquals( listOf ( " test " , " test2 " , " test3 " ), arg1 )
57
60
}
58
61
59
62
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 )
61
64
}
62
65
63
66
@Suppress(" detekt.MaxLineLength" )
64
67
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" ))
66
73
}
67
74
68
75
override suspend fun customType (arg1 : TestClass ): TestClass {
69
76
return arg1
70
77
}
71
78
72
79
override suspend fun nullable (arg1 : String? ): TestClass ? {
73
- println (" nullable $arg1 " )
74
80
return if (arg1 == null ) null else TestClass ()
75
81
}
76
82
77
83
override suspend fun variance (
78
84
arg2 : TestList <in TestClass >,
79
85
arg3 : TestList2 <* >
80
86
): TestList <out TestClass > {
81
- println (" variance: $arg2 $arg3 " )
87
+ assertEquals(arg2.value, 42 )
88
+ assertEquals(arg3.value, 42 )
82
89
return TestList (3 )
83
90
}
84
91
@@ -98,7 +105,7 @@ class KrpcTestServiceBackend(override val coroutineContext: CoroutineContext) :
98
105
override suspend fun incomingStreamAsyncCollect (arg1 : Flow <String >): Int {
99
106
@Suppress(" detekt.GlobalCoroutineUsage" )
100
107
GlobalScope .launch {
101
- arg1.collect { println ( " incomingStreamAsyncCollect item $it " ) }
108
+ assertContentEquals( listOf ( " test1 " , " test2 " , " test3 " ), arg1.toList())
102
109
}
103
110
return 5
104
111
}
@@ -144,13 +151,13 @@ class KrpcTestServiceBackend(override val coroutineContext: CoroutineContext) :
144
151
}
145
152
146
153
override suspend fun streamInDataClassWithStream (payloadWithPayload : PayloadWithPayload ): Int {
147
- payloadWithPayload.collectAndPrint( )
154
+ assertContentEquals( KrpcTransportTestBase .expectedPayloadWithPayload( 10 ), payloadWithPayload.collect() )
148
155
return 5
149
156
}
150
157
151
158
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() )
154
161
}
155
162
return 5
156
163
}
@@ -228,7 +235,6 @@ class KrpcTestServiceBackend(override val coroutineContext: CoroutineContext) :
228
235
}
229
236
230
237
override suspend fun answerToAnything (arg : String ): Int {
231
- println (" Return 42" )
232
238
return 42
233
239
}
234
240
@@ -276,9 +282,7 @@ class KrpcTestServiceBackend(override val coroutineContext: CoroutineContext) :
276
282
277
283
launch {
278
284
assertEquals(listOf (0 , 1 , 2 , 3 , 4 ), sharedFlow.take(5 ).toList())
279
- println (" hello 1" )
280
285
state.emit(1 )
281
- println (" hello 2" )
282
286
}
283
287
284
288
return state
0 commit comments