Skip to content

Commit

Permalink
fixed map containing null
Browse files Browse the repository at this point in the history
  • Loading branch information
bgalek committed Mar 20, 2020
1 parent 80c0374 commit 9296dc9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package pl.allegro.tech.opel;

import java.util.AbstractMap;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
Expand All @@ -18,7 +19,8 @@ public CompletableFuture<Map<Object, Object>> getValue(EvalContext context) {
.map(pair -> pair.getKey().getValue(context)
.thenCombine(pair.getValue().getValue(context), this::entry))
.collect(Collectors.toList()))
.thenApply(list -> list.stream().collect(Collectors.toMap(AbstractMap.SimpleImmutableEntry::getKey, AbstractMap.SimpleImmutableEntry::getValue)));
.thenApply(list -> list.stream()
.collect(HashMap::new, (hashMap, entry) -> hashMap.put(entry.getKey(), entry.getValue()), HashMap::putAll));
}

private AbstractMap.SimpleImmutableEntry entry(Object key, Object value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class OpelEngineListIntegrationSpec extends Specification {
input || expResult
"[]" || []
"([])" || []
"[null]" || [null]
"['a']" || ['a']
"['a', 'b']" || ['a', 'b']
"['a', 'b', 'c']" || ['a', 'b', 'c']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ class OpelEngineMapIntegrationSpec extends Specification {
engine.eval(input).get() == new HashMap(expResult)

where:
input || expResult
"{:}" || [:]
"{'x':2}" || [x: 2]
"({'x': 2 })" || [x: 2]
"{'x': 2, 'y':3 }" || [x: 2, y: 3]
input || expResult
"{:}" || [:]
"{'x':2}" || [x: 2]
"({'x': 2 })" || [x: 2]
"{'x': 2, 'y':3 }" || [x: 2, y: 3]
"{'x': 2, 'y':null }" || [x: 2, y: null]
"{'x': 2, 'null':2 }" || [x: 2, null: 2]
}

@Unroll
Expand All @@ -36,6 +38,7 @@ class OpelEngineMapIntegrationSpec extends Specification {
input || values || expResult
"{x: (6+7), 'y':3 }" || [x: CompletableFuture.completedFuture(2.0)] || [(2.0): 13, y: 3]
"{x: 6+7, 'y':3 }" || [x: CompletableFuture.completedFuture(2.0)] || [(2.0): 13, y: 3]
"{x: 6+7, 'y':3 }" || [x: CompletableFuture.completedFuture(null)] || [(null): 13, y: 3]
}

@Unroll
Expand Down

0 comments on commit 9296dc9

Please sign in to comment.