|
4 | 4 |
|
5 | 5 | import com.hubspot.jinjava.Jinjava; |
6 | 6 | import com.hubspot.jinjava.interpret.JinjavaInterpreter; |
| 7 | +import java.util.AbstractMap; |
| 8 | +import java.util.Collections; |
7 | 9 | import java.util.HashMap; |
8 | 10 | import java.util.Map; |
| 11 | +import java.util.Set; |
9 | 12 | import org.junit.Before; |
10 | 13 | import org.junit.Test; |
11 | 14 |
|
12 | 15 | public class CollectionMembershipOperatorTest { |
13 | 16 |
|
| 17 | + static class NoKeySetMap<K, V> extends AbstractMap<K, V> { |
| 18 | + |
| 19 | + @Override |
| 20 | + public boolean isEmpty() { |
| 21 | + return false; |
| 22 | + } |
| 23 | + |
| 24 | + @Override |
| 25 | + public Set<K> keySet() { |
| 26 | + return Collections.emptySet(); |
| 27 | + } |
| 28 | + |
| 29 | + @Override |
| 30 | + public Set<Entry<K, V>> entrySet() { |
| 31 | + return Collections.emptySet(); |
| 32 | + } |
| 33 | + } |
| 34 | + |
14 | 35 | private JinjavaInterpreter interpreter; |
15 | 36 |
|
16 | 37 | @Before |
@@ -49,4 +70,12 @@ public void itChecksIfDictionaryContainsNullKey() { |
49 | 70 | assertThat(interpreter.resolveELExpression("null in map", -1)).isEqualTo(true); |
50 | 71 | assertThat(interpreter.resolveELExpression("'b' in map", -1)).isEqualTo(false); |
51 | 72 | } |
| 73 | + |
| 74 | + @Test |
| 75 | + public void itCheckEmptyKeySet() { |
| 76 | + // The map is "not" empty, but keySet() is empty. |
| 77 | + Map<String, Object> map = new NoKeySetMap<>(); |
| 78 | + interpreter.getContext().put("map", map); |
| 79 | + assertThat(interpreter.resolveELExpression("'a' in map", -1)).isEqualTo(false); |
| 80 | + } |
52 | 81 | } |
0 commit comments