Skip to content

Commit a9ea42a

Browse files
committed
Better test of null context provider
1 parent c68f79c commit a9ea42a

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/test/java/org/dataloader/DataLoaderContextTest.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,18 @@ public CompletionStage<List<String>> load(List<String> keys, Object context) {
4545

4646
@Test
4747
public void null_is_passed_as_context_if_you_do_nothing() throws Exception {
48-
BatchLoader<String, String> batchLoader = CompletableFuture::completedFuture;
48+
BatchLoader<String, String> batchLoader = new BatchLoader<String, String>() {
49+
@Override
50+
public CompletionStage<List<String>> load(List<String> keys) {
51+
throw new UnsupportedOperationException("this wont be called");
52+
}
53+
54+
@Override
55+
public CompletionStage<List<String>> load(List<String> keys, Object context) {
56+
List<String> list = keys.stream().map(k -> k + "-" + context).collect(Collectors.toList());
57+
return CompletableFuture.completedFuture(list);
58+
}
59+
};
4960
DataLoader<String, String> loader = new DataLoader<>(batchLoader);
5061

5162
loader.load("A");
@@ -54,6 +65,6 @@ public void null_is_passed_as_context_if_you_do_nothing() throws Exception {
5465

5566
List<String> results = loader.dispatchAndJoin();
5667

57-
assertThat(results, equalTo(asList("A", "B", "C", "D")));
68+
assertThat(results, equalTo(asList("A-null", "B-null", "C-null", "D-null")));
5869
}
5970
}

0 commit comments

Comments
 (0)