Skip to content

Commit 3c1ef00

Browse files
committed
[scala#10765] Add test coverage for TrieMaps with null values, fixes scala/bug#10765
1 parent ca5a07d commit 3c1ef00

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

test/junit/scala/collection/concurrent/TrieMapTest.scala

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package scala.collection.concurrent
22

3-
import org.junit.{Assert, Test}
3+
import org.junit.Test
4+
import org.junit.Assert.assertEquals
5+
6+
import scala.collection.immutable.TreeMap
47
import scala.util.hashing.Hashing
58

69
class TrieMapTest {
@@ -9,8 +12,8 @@ class TrieMapTest {
912
val m = TrieMap[String, String]()
1013
val values = f(m)
1114
m.put("k", "v")
12-
Assert.assertEquals(Nil, values.toList)
13-
Assert.assertEquals(result2, f(m).toList)
15+
assertEquals(Nil, values.toList)
16+
assertEquals(result2, f(m).toList)
1417
}
1518

1619
@Test
@@ -59,11 +62,22 @@ class TrieMapTest {
5962
val e = new Equiv[Int] { def equiv(x: Int, y: Int) = (x % 8) == (y % 8) }
6063
val xs = new TrieMap[Int, String](h, e)
6164
xs.put(0, "zero")
62-
Assert.assertEquals(Some("zero"), xs.get(0))
63-
Assert.assertEquals(Some("zero"), xs.get(8)) // 8 and 0 are equivalent keys according to our custom equiv
65+
assertEquals(Some("zero"), xs.get(0))
66+
assertEquals(Some("zero"), xs.get(8)) // 8 and 0 are equivalent keys according to our custom equiv
6467
xs.put(4, "four") // 4 and 0 have the same hash according to our custom hashing, but they
6568
// are different keys (collision)
66-
Assert.assertEquals(Some("zero"), xs.get(8))
67-
Assert.assertEquals(Some("four"), xs.get(4))
69+
assertEquals(Some("zero"), xs.get(8))
70+
assertEquals(Some("four"), xs.get(4))
71+
}
72+
73+
@Test
74+
def nullValues_t10765: Unit = {
75+
val trieMap = TreeMap[String, String]("a" -> null)
76+
assertEquals(null, trieMap("a"))
77+
assertEquals(Some(null), trieMap.get("a"))
78+
assertEquals(true, trieMap.contains("a"))
79+
assertEquals(1, trieMap.size)
80+
assertEquals(true, trieMap.iterator.hasNext)
81+
assertEquals(("a", null), trieMap.iterator.next())
6882
}
6983
}

0 commit comments

Comments
 (0)