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 33import org .dataloader .annotations .PublicSpi ;
44import org .dataloader .impl .CompletableFutureKit ;
55import org .dataloader .impl .NoOpValueCache ;
6+ import org .jspecify .annotations .Nullable ;
67import org .jspecify .annotations .NullMarked ;
78
89import java .util .ArrayList ;
4041 */
4142@ PublicSpi
4243@ NullMarked
43- public interface ValueCache <K , V > {
44+ public interface ValueCache <K , V extends @ Nullable Object > {
4445
4546 /**
4647 * Creates a new value cache, using the default no-op implementation.
Original file line number Diff line number Diff line change 11package org.dataloader
22
3+ import java.util.concurrent.CompletableFuture
34import org.junit.jupiter.api.Test
45import reactor.core.publisher.Flux
56import java.util.concurrent.CompletableFuture.completedFuture
7+ import org.dataloader.impl.NoOpValueCache
68
79/* *
810 * Some Kotlin code to prove that are JSpecify annotations work here
@@ -81,6 +83,19 @@ class KotlinExamples {
8183 standardNullableAsserts(dataLoader)
8284 }
8385
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+
8499 private fun standardNullableAsserts (dataLoader : DataLoader <String , String ?>) {
85100 val cfA = dataLoader.load(" A" )
86101 val cfB = dataLoader.load(" B" )
You can’t perform that action at this time.
0 commit comments