|
@@ -0,0 +1,52 @@
|
|
1
|
+package net.abhinavsarkar.spelhelper
|
|
2
|
+
|
|
3
|
+import org.scalatest.junit.JUnitRunner
|
|
4
|
+import org.junit.runner.RunWith
|
|
5
|
+import org.scalatest.FlatSpec
|
|
6
|
+import org.scalatest.junit.ShouldMatchersForJUnit
|
|
7
|
+import java.util.{HashSet, Set => JSet, List => JList, ArrayList}
|
|
8
|
+
|
|
9
|
+@RunWith(classOf[JUnitRunner])
|
|
10
|
+class ImplicitMethodsSpec extends FlatSpec with ShouldMatchersForJUnit {
|
|
11
|
+
|
|
12
|
+ "Implicit Function 'distinct' on List" should
|
|
13
|
+ "return distinct items in a list " in {
|
|
14
|
+ val set: JSet[String] = new HashSet
|
|
15
|
+ set add "a"; set add "b"
|
|
16
|
+ new SpelHelper().evalExpression("#list('a','b','a').distinct()",
|
|
17
|
+ new {}, classOf[JSet[String]]) should equal(set)
|
|
18
|
+ }
|
|
19
|
+
|
|
20
|
+ "Implicit Function 'sorted' on List" should
|
|
21
|
+ "return a sorted list " in {
|
|
22
|
+ val list: JList[String] = new ArrayList
|
|
23
|
+ List("a", "b", "c") foreach { list add _ }
|
|
24
|
+ new SpelHelper().evalExpression("#list('c','b','a').sorted()",
|
|
25
|
+ new {}, classOf[JList[String]]) should equal(list)
|
|
26
|
+ }
|
|
27
|
+
|
|
28
|
+ "Implicit Function 'reversed' on List" should
|
|
29
|
+ "return a reversed list " in {
|
|
30
|
+ val list: JList[String] = new ArrayList
|
|
31
|
+ List("a", "b", "c") foreach { list add _ }
|
|
32
|
+ new SpelHelper().evalExpression("#list('c','b','a').reversed()",
|
|
33
|
+ new {}, classOf[JList[String]]) should equal(list)
|
|
34
|
+ }
|
|
35
|
+
|
|
36
|
+ "Implicit Function 'take' on List" should
|
|
37
|
+ "return a list containing first n items of a list " in {
|
|
38
|
+ val list: JList[String] = new ArrayList
|
|
39
|
+ List("a", "b", "c") foreach { list add _ }
|
|
40
|
+ new SpelHelper().evalExpression("#list('a','b','c','d').take(3)",
|
|
41
|
+ new {}, classOf[JList[String]]) should equal(list)
|
|
42
|
+ }
|
|
43
|
+
|
|
44
|
+ "Implicit Function 'drop' on List" should
|
|
45
|
+ "return a list containing items after the first n items of a list " in {
|
|
46
|
+ val list: JList[String] = new ArrayList
|
|
47
|
+ List("c", "d") foreach { list add _ }
|
|
48
|
+ new SpelHelper().evalExpression("#list('a','b','c','d').drop(2)",
|
|
49
|
+ new {}, classOf[JList[String]]) should equal(list)
|
|
50
|
+ }
|
|
51
|
+
|
|
52
|
+}
|