22
33import org .dataloader .fixtures .TestKit ;
44import org .dataloader .fixtures .parameterized .DelegatingDataLoaderFactory ;
5- import org .jspecify .annotations .NonNull ;
65import org .jspecify .annotations .NullMarked ;
76import org .jspecify .annotations .Nullable ;
87import org .junit .jupiter .api .Test ;
1110import java .util .Map ;
1211import java .util .concurrent .CompletableFuture ;
1312import java .util .concurrent .atomic .AtomicInteger ;
13+ import java .util .stream .Collectors ;
1414
1515import static org .awaitility .Awaitility .await ;
1616import static org .hamcrest .CoreMatchers .equalTo ;
@@ -34,14 +34,37 @@ void canUnwrapDataLoaders() {
3434 }
3535
3636 @ Test
37+ @ NullMarked
3738 void canCreateAClassOk () {
3839 DataLoader <String , String > rawLoader = TestKit .idLoader ();
3940 DelegatingDataLoader <String , String > delegatingDataLoader = new DelegatingDataLoader <>(rawLoader ) {
40- @ Override
41- public CompletableFuture <String > load (@ NonNull String key , @ Nullable Object keyContext ) {
42- CompletableFuture <String > cf = super .load (key , keyContext );
41+ private CompletableFuture <String > enhance (CompletableFuture <String > cf ) {
4342 return cf .thenApply (v -> "|" + v + "|" );
4443 }
44+
45+ private CompletableFuture <List <String >> enhanceList (CompletableFuture <List <String >> cf ) {
46+ return cf .thenApply (v -> v .stream ().map (s -> "|" + s + "|" ).collect (Collectors .toList ()));
47+ }
48+
49+ @ Override
50+ public CompletableFuture <String > load (String key , @ Nullable Object keyContext ) {
51+ return enhance (super .load (key , keyContext ));
52+ }
53+
54+ @ Override
55+ public CompletableFuture <String > load (String key ) {
56+ return enhance (super .load (key ));
57+ }
58+
59+ @ Override
60+ public CompletableFuture <List <String >> loadMany (List <String > keys ) {
61+ return enhanceList (super .loadMany (keys ));
62+ }
63+
64+ @ Override
65+ public CompletableFuture <List <String >> loadMany (List <String > keys , List <Object > keyContexts ) {
66+ return enhanceList (super .loadMany (keys , keyContexts ));
67+ }
4568 };
4669
4770 assertThat (delegatingDataLoader .getDelegate (), is (rawLoader ));
0 commit comments