-
Notifications
You must be signed in to change notification settings - Fork 13
/
test_java_util.nim
39 lines (36 loc) · 1.09 KB
/
test_java_util.nim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import ../jnim,
../jnim/java/util,
../jnim/java/lang,
common,
unittest
import sequtils except toSeq
suite "java.util":
setup:
if not isJNIThreadInitialized():
initJNIForTests()
test "java.util.List":
let xs = ArrayList[string].new()
discard xs.add("Hello")
xs.add(1, "world")
check: xs.get(0) == "Hello"
check: xs.get(1) == "world"
expect JavaException:
discard xs.get(3)
var s = newSeq[string]()
let it = xs.toIterator
while it.hasNext:
s.add it.next
check: s == @["Hello", "world"]
discard xs.removeAll(ArrayList[string].new(["world", "!"]))
check: xs.toSeq == @["Hello"]
test "java.util.Map":
let m = HashMap[Integer, string].new()
discard m.put(1.jint, "A")
discard m.put(2.jint, "B")
discard m.put(3.jint, "C")
check: m.get(1.jint) == "A"
check: m.get(2.jint) == "B"
check: m.get(3.jint) == "C"
check: m.keySet.toSeq.mapIt(it.intValue) == @[1.jint, 2, 3]
check: m.keySet.toSeq == @[1.jint, 2, 3].mapIt(Integer.new(it))
check: m.values.toSeq == @["A", "B", "C"]