diff options
author | Aleksandar Pokopec <aleksandar.prokopec@epfl.ch> | 2010-01-13 23:42:33 +0000 |
---|---|---|
committer | Aleksandar Pokopec <aleksandar.prokopec@epfl.ch> | 2010-01-13 23:42:33 +0000 |
commit | 34fe81a8a91aeb63f6316211ac9212899ec14116 (patch) | |
tree | d386b071a657b01e37f3e3450e0dcc8f38392db3 /test/files | |
parent | 1e828fdbf04402dc53e897f6a7201bad00388b70 (diff) | |
download | scala-34fe81a8a91aeb63f6316211ac9212899ec14116.tar.gz scala-34fe81a8a91aeb63f6316211ac9212899ec14116.tar.bz2 scala-34fe81a8a91aeb63f6316211ac9212899ec14116.zip |
Added ConcurrentMap and Properties conversion c...
Added ConcurrentMap and Properties conversion classes and test.
Diffstat (limited to 'test/files')
-rw-r--r-- | test/files/run/map_java_conversions.scala | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/test/files/run/map_java_conversions.scala b/test/files/run/map_java_conversions.scala new file mode 100644 index 0000000000..4f9f8a915a --- /dev/null +++ b/test/files/run/map_java_conversions.scala @@ -0,0 +1,60 @@ + + + + + +object Test { + + def main(args: Array[String]) { + import collection.JavaConversions._ + + test(new java.util.HashMap[String, String]) + test(new java.util.Properties) + testConcMap + } + + def testConcMap { + import collection.JavaConversions._ + + val concMap = new java.util.concurrent.ConcurrentHashMap[String, String] + + test(concMap) + val cmap = asConcurrentMap(concMap) + cmap.putIfAbsent("absentKey", "absentValue") + cmap.put("somekey", "somevalue") + assert(cmap.remove("somekey", "somevalue") == true) + assert(cmap.replace("absentKey", "newAbsentValue") == Some("absentValue")) + assert(cmap.replace("absentKey", "newAbsentValue", ".......") == true) + } + + def test(m: collection.mutable.Map[String, String]) { + m.clear + assert(m.size == 0) + + m.put("key", "value") + assert(m.size == 1) + + assert(m.put("key", "anotherValue") == Some("value")) + assert(m.put("key2", "value2") == None) + assert(m.size == 2) + + m += (("key3", "value3")) + assert(m.size == 3) + + m -= "key2" + assert(m.size == 2) + assert(m.nonEmpty) + assert(m.remove("key") == Some("anotherValue")) + + m.clear + for (i <- 0 until 10) m += (("key" + i, "value" + i)) + for ((k, v) <- m) assert(k.startsWith("key")) + } + +} + + + + + + |