File tree Expand file tree Collapse file tree 2 files changed +17
-1
lines changed
test/kotlin/org/dataloader Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change 3
3
import org .dataloader .annotations .PublicSpi ;
4
4
import org .dataloader .impl .CompletableFutureKit ;
5
5
import org .dataloader .impl .NoOpValueCache ;
6
+ import org .jspecify .annotations .Nullable ;
6
7
import org .jspecify .annotations .NullMarked ;
7
8
8
9
import java .util .ArrayList ;
40
41
*/
41
42
@ PublicSpi
42
43
@ NullMarked
43
- public interface ValueCache <K , V > {
44
+ public interface ValueCache <K , V extends @ Nullable Object > {
44
45
45
46
/**
46
47
* Creates a new value cache, using the default no-op implementation.
Original file line number Diff line number Diff line change 1
1
package org.dataloader
2
2
3
+ import java.util.concurrent.CompletableFuture
3
4
import org.junit.jupiter.api.Test
4
5
import reactor.core.publisher.Flux
5
6
import java.util.concurrent.CompletableFuture.completedFuture
7
+ import org.dataloader.impl.NoOpValueCache
6
8
7
9
/* *
8
10
* Some Kotlin code to prove that are JSpecify annotations work here
@@ -81,6 +83,19 @@ class KotlinExamples {
81
83
standardNullableAsserts(dataLoader)
82
84
}
83
85
86
+ @Test
87
+ fun `basic kotlin test of nullable value types in value cache` () {
88
+ val valueCache = object : ValueCache <String , String ?> by NoOpValueCache () {
89
+ override fun get (key : String ): CompletableFuture <String ?> = if (key == " null" )
90
+ completedFuture(null )
91
+ else
92
+ completedFuture(key)
93
+ }
94
+
95
+ assert (valueCache[" key" ].get() == " key" )
96
+ assert (valueCache[" null" ].get() == null )
97
+ }
98
+
84
99
private fun standardNullableAsserts (dataLoader : DataLoader <String , String ?>) {
85
100
val cfA = dataLoader.load(" A" )
86
101
val cfB = dataLoader.load(" B" )
You can’t perform that action at this time.
0 commit comments