Added Scalatest specs for ExtensionFunctions and ImplicitMethods

master
Abhinav Sarkar 2010-05-28 03:13:45 +05:30
부모 293a0dffda
커밋 5b4e39a2fe
4개의 변경된 파일90개의 추가작업 그리고 1개의 파일을 삭제

파일 보기

@ -17,10 +17,12 @@
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/target/generated-sources/annotations" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/target/generated-sources/test-annotations" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/scala" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/target/classes" />
<excludeFolder url="file://$MODULE_DIR$/target/site" />
<excludeFolder url="file://$MODULE_DIR$/target/surefire-reports" />
<excludeFolder url="file://$MODULE_DIR$/target/test-classes" />
</content>

파일 보기

@ -87,7 +87,7 @@ final class ImplicitMethodResolver implements MethodResolver {
newArgumentTypes);
MethodExecutor wrappedExecutor = executor == null ? null
: new ImplicitMethodExecutor(executor);
if(wrappedExecutor == null) {
if (wrappedExecutor == null) {
CACHE.putIfAbsent(cacheKey, NULL_ME);
}
return wrappedExecutor;

파일 보기

@ -0,0 +1,35 @@
package net.abhinavsarkar.spelhelper
import org.scalatest.junit.JUnitRunner
import org.junit.runner.RunWith
import org.scalatest.FlatSpec
import org.scalatest.junit.ShouldMatchersForJUnit
import java.util.{Set => JSet, HashSet,
List => JList, ArrayList,
Map => JMap, HashMap}
@RunWith(classOf[JUnitRunner])
class ExtensionFunctionsSpec extends FlatSpec with ShouldMatchersForJUnit {
"Extension Function 'list'" should "return a java.util.List " in {
val list: JList[String] = new ArrayList
List("a", "b", "c") foreach { list add _ }
new SpelHelper().evalExpression("#list('a','b','c')",
new {}, classOf[JList[String]]) should equal(list)
}
"Extension Function 'set'" should "return a java.util.Set " in {
val set: JSet[String] = new HashSet
List("a", "b", "c") foreach { set add _ }
new SpelHelper().evalExpression("#set('a','b','c')",
new {}, classOf[JSet[String]]) should equal(set)
}
"Extension Function 'map'" should "return a java.util.Map " in {
val map: JMap[String,Int] = new HashMap
List("a", "b", "c").zipWithIndex.foreach { x => map.put(x._1, x._2) }
new SpelHelper().evalExpression("#map(#list('a','b','c'),#list(0,1,2))",
new {}, classOf[JMap[String,Int]]) should equal(map)
}
}

파일 보기

@ -0,0 +1,52 @@
package net.abhinavsarkar.spelhelper
import org.scalatest.junit.JUnitRunner
import org.junit.runner.RunWith
import org.scalatest.FlatSpec
import org.scalatest.junit.ShouldMatchersForJUnit
import java.util.{HashSet, Set => JSet, List => JList, ArrayList}
@RunWith(classOf[JUnitRunner])
class ImplicitMethodsSpec extends FlatSpec with ShouldMatchersForJUnit {
"Implicit Function 'distinct' on List" should
"return distinct items in a list " in {
val set: JSet[String] = new HashSet
set add "a"; set add "b"
new SpelHelper().evalExpression("#list('a','b','a').distinct()",
new {}, classOf[JSet[String]]) should equal(set)
}
"Implicit Function 'sorted' on List" should
"return a sorted list " in {
val list: JList[String] = new ArrayList
List("a", "b", "c") foreach { list add _ }
new SpelHelper().evalExpression("#list('c','b','a').sorted()",
new {}, classOf[JList[String]]) should equal(list)
}
"Implicit Function 'reversed' on List" should
"return a reversed list " in {
val list: JList[String] = new ArrayList
List("a", "b", "c") foreach { list add _ }
new SpelHelper().evalExpression("#list('c','b','a').reversed()",
new {}, classOf[JList[String]]) should equal(list)
}
"Implicit Function 'take' on List" should
"return a list containing first n items of a list " in {
val list: JList[String] = new ArrayList
List("a", "b", "c") foreach { list add _ }
new SpelHelper().evalExpression("#list('a','b','c','d').take(3)",
new {}, classOf[JList[String]]) should equal(list)
}
"Implicit Function 'drop' on List" should
"return a list containing items after the first n items of a list " in {
val list: JList[String] = new ArrayList
List("c", "d") foreach { list add _ }
new SpelHelper().evalExpression("#list('a','b','c','d').drop(2)",
new {}, classOf[JList[String]]) should equal(list)
}
}