add JavaTestKit, see #1952

- it’s a completely new-written thing in pure Java, so that “protected”
  modifiers actually work and no ghost errors appear wrt. inheriting
  from PartialFunction or similar
- it also features integration with the EventFilter
- all closure-based constructs are modeled as inner classes of the
  JavaTestKit, where the user needs to override a single method which
  will then be executed
This commit is contained in:
Roland 2012-06-29 14:42:11 +02:00
parent be74eb835b
commit d7bed79730
15 changed files with 964 additions and 365 deletions

View file

@ -46,7 +46,9 @@ trait Creator[T] {
}
object PurePartialFunction {
case object NoMatch extends RuntimeException with NoStackTrace
sealed abstract class NoMatchException extends RuntimeException with NoStackTrace
case object NoMatch extends NoMatchException
final def noMatch(): RuntimeException = NoMatch
}
/**
@ -86,7 +88,16 @@ abstract class PurePartialFunction[A, B] extends scala.runtime.AbstractFunction1
final def isDefinedAt(x: A): Boolean = try { apply(x, true); true } catch { case NoMatch false }
final def apply(x: A): B = try apply(x, false) catch { case NoMatch throw new MatchError }
final def noMatch(): RuntimeException = NoMatch
}
abstract class CachingPartialFunction[A, B <: AnyRef] extends scala.runtime.AbstractFunction1[A, B] with PartialFunction[A, B] {
import PurePartialFunction._
def `match`(x: A): B
var cache: B = _
final def isDefinedAt(x: A): Boolean = try { cache = `match`(x); true } catch { case NoMatch cache = null.asInstanceOf[B]; false }
final def apply(x: A): B = cache
}
/**
@ -164,4 +175,6 @@ object Util {
def manifest[T](clazz: Class[T]): Manifest[T] = Manifest.classType(clazz)
def arrayToSeq[T](arr: Array[T]): Seq[T] = arr.toSeq
def arrayToSeq(classes: Array[Class[_]]): Seq[Class[_]] = classes.toSeq
}