casualjim
12/29/2011 - 3:11 PM

akkaContext.scala

package org.scala_tools.time

import akka.util.{ FiniteDuration, Duration ⇒ AkkaDuration }
import java.util.concurrent.TimeUnit
import org.joda.time.{Period, Duration}

trait AkkaImplicits {
  
  implicit def dur2akkadur(duration: Duration): AkkaDuration = {
    val max = Long.MaxValue
    val min = Long.MinValue
    val zero = 0
    duration.getMillis match {
      case `max` ⇒ AkkaDuration.Inf
      case `min` ⇒ AkkaDuration.MinusInf
      case `zero`            ⇒ new FiniteDuration(0, TimeUnit.NANOSECONDS)
      case v            ⇒ new FiniteDuration(v, TimeUnit.MILLISECONDS)
    }
  }
  
  implicit def per2akkadur(period: Period): AkkaDuration = {
    val max = Int.MaxValue
    val min = Int.MinValue
    val zero = 0
    period.getMillis match {
      case `max` ⇒ AkkaDuration.Inf
      case `min` ⇒ AkkaDuration.MinusInf
      case `zero`            ⇒ new FiniteDuration(0, TimeUnit.NANOSECONDS)
      case v            ⇒ new FiniteDuration(v, TimeUnit.MILLISECONDS)
    }
  }

  implicit def forceAkkaDuration(builder: DurationBuilder): AkkaDuration = {
    val max = Int.MaxValue
    val min = Int.MinValue
    val zero = 0
    builder.underlying.getMillis match {
      case `max` ⇒ AkkaDuration.Inf
      case `min` ⇒ AkkaDuration.MinusInf
      case `zero`            ⇒ new FiniteDuration(0, TimeUnit.NANOSECONDS)
      case v            ⇒ new FiniteDuration(v, TimeUnit.MILLISECONDS)
    }
  }

}
package mojolly.testing

import org.specs2.main.{ ArgumentsShortcuts, ArgumentsArgs }
import org.specs2.matcher.{ MatchResult, StandardMatchResults, ShouldThrownMatchers, MustThrownMatchers }
import org.specs2.execute.{ Result, PendingUntilFixed, StandardResults }
import org.specs2.specification._

trait MojollySpecification extends BaseSpecification
    with ArgumentsArgs
    with ArgumentsShortcuts
    with MustThrownMatchers
    with ShouldThrownMatchers
    with FormattingFragments
    with StandardResults
    with StandardMatchResults
    with PendingUntilFixed
    with Contexts {

  /** transform a context to a result to allow the implicit passing of a context to each example */
  implicit def contextToResult[T](t: MatchResult[T])(implicit context: Context = defaultContext): Result = context(asResult(t))
  /** use an available outside context to transform a function returning a MatchResult into a result */
  implicit def outsideFunctionToResult[T, S](implicit o: Outside[T]) = (f: T ⇒ MatchResult[S]) ⇒ { o((t1: T) ⇒ f(t1).toResult) }

}
package mojolly.testing

import org.specs2.specification._
import akka.actor._
import akka.testkit.TestKit

trait AkkaContext extends After {
  val testkit = new TestKit(ActorSystem(newUuid().toString))
  implicit def system = testkit.system

  def after = {
    testkit.system.shutdown()
  }
}