1
1
package org.dataloader
2
2
3
3
import org.junit.jupiter.api.Test
4
- import java.util.concurrent.CompletableFuture
5
- import java.util.concurrent.CompletableFuture.*
4
+ import reactor.core.publisher.Flux
5
+ import java.util.concurrent.CompletableFuture.completedFuture
6
6
7
7
/* *
8
8
* Some Kotlin code to prove that are JSpecify annotations work here
@@ -13,28 +13,83 @@ class KotlinExamples {
13
13
14
14
@Test
15
15
fun `basic kotlin test of non nullable value types` () {
16
- val dataLoader: DataLoader <String , String > = DataLoaderFactory .newDataLoader { keys -> completedFuture(keys.toList()) }
16
+ val batchLoadFunction = BatchLoader <String , String >
17
+ { keys -> completedFuture(keys.toList()) }
18
+ val dataLoader: DataLoader <String , String > =
19
+ DataLoaderFactory .newDataLoader(batchLoadFunction)
17
20
18
21
val cfA = dataLoader.load(" A" )
19
22
val cfB = dataLoader.load(" B" )
20
23
21
24
dataLoader.dispatch()
22
25
23
26
assert (cfA.join().equals(" A" ))
24
- assert (cfA .join().equals(" A " ))
27
+ assert (cfB .join().equals(" B " ))
25
28
}
26
29
27
30
@Test
28
31
fun `basic kotlin test of nullable value types` () {
29
- val dataLoader: DataLoader <String , String ?> = DataLoaderFactory .newDataLoader { keys -> completedFuture(keys.toList()) }
32
+ val batchLoadFunction: BatchLoader <String , String ?> = BatchLoader { keys -> completedFuture(keys.toList()) }
33
+ val dataLoader: DataLoader <String , String ?> = DataLoaderFactory .newDataLoader(batchLoadFunction)
34
+
35
+ standardNullableAsserts(dataLoader)
36
+ }
37
+
38
+ @Test
39
+ fun `basic kotlin test of nullable value types in mapped batch loader` () {
40
+ val batchLoadFunction = MappedBatchLoader <String , String ?>
41
+ { keys -> completedFuture(keys.associateBy({ it })) }
42
+
43
+ val dataLoader: DataLoader <String , String ?> = DataLoaderFactory .newMappedDataLoader(batchLoadFunction)
44
+
45
+ standardNullableAsserts(dataLoader)
46
+ }
47
+
48
+ @Test
49
+ fun `basic kotlin test of nullable value types in mapped batch loader with context` () {
50
+ val batchLoadFunction = MappedBatchLoaderWithContext <String , String ?>
51
+ { keys, env -> completedFuture(keys.associateBy({ it })) }
52
+
53
+ val dataLoader: DataLoader <String , String ?> = DataLoaderFactory .newMappedDataLoader(batchLoadFunction)
54
+
55
+ standardNullableAsserts(dataLoader)
56
+ }
30
57
58
+ @Test
59
+ fun `basic kotlin test of nullable value types in mapped batch publisher` () {
60
+ val batchLoadFunction = MappedBatchPublisher <String , String ?>
61
+ { keys, subscriber ->
62
+ val map: Map <String , String ?> = keys.associateBy({ it })
63
+ Flux .fromIterable(map.entries).subscribe(subscriber);
64
+ }
65
+
66
+ val dataLoader: DataLoader <String , String ?> = DataLoaderFactory .newMappedPublisherDataLoader(batchLoadFunction)
67
+
68
+ standardNullableAsserts(dataLoader)
69
+ }
70
+
71
+ @Test
72
+ fun `basic kotlin test of nullable value types in mapped batch publisher with context` () {
73
+ val batchLoadFunction = MappedBatchPublisherWithContext <String , String ?>
74
+ { keys, subscriber, env ->
75
+ val map: Map <String , String ?> = keys.associateBy({ it })
76
+ Flux .fromIterable(map.entries).subscribe(subscriber);
77
+ }
78
+
79
+ val dataLoader: DataLoader <String , String ?> = DataLoaderFactory .newMappedPublisherDataLoader(batchLoadFunction)
80
+
81
+ standardNullableAsserts(dataLoader)
82
+ }
83
+
84
+ private fun standardNullableAsserts (dataLoader : DataLoader <String , String ?>) {
31
85
val cfA = dataLoader.load(" A" )
32
86
val cfB = dataLoader.load(" B" )
33
87
34
88
dataLoader.dispatch()
35
89
36
90
assert (cfA.join().equals(" A" ))
37
- assert (cfA .join().equals(" A " ))
91
+ assert (cfB .join().equals(" B " ))
38
92
}
39
93
94
+
40
95
}
0 commit comments