2012-01-19 14:38:44 +00:00
|
|
|
/**
|
|
|
|
|
* Copyright (C) 2009-2012 Typesafe Inc. <http://www.typesafe.com>
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package akka.camel.internal.component
|
|
|
|
|
|
2012-06-25 18:28:38 +02:00
|
|
|
import language.postfixOps
|
|
|
|
|
|
2012-01-19 14:38:44 +00:00
|
|
|
import org.scalatest.matchers.MustMatchers
|
2012-06-29 13:33:20 +02:00
|
|
|
import scala.concurrent.util.duration._
|
|
|
|
|
import scala.concurrent.util.Duration
|
2012-01-19 14:38:44 +00:00
|
|
|
import org.scalatest.WordSpec
|
2012-05-23 23:59:55 +02:00
|
|
|
import org.apache.camel.NoTypeConversionAvailableException
|
2012-01-19 14:38:44 +00:00
|
|
|
|
2012-05-23 23:59:55 +02:00
|
|
|
class DurationConverterSpec extends WordSpec with MustMatchers {
|
2012-01-19 14:38:44 +00:00
|
|
|
import DurationTypeConverter._
|
|
|
|
|
|
|
|
|
|
"DurationTypeConverter must convert '10 nanos'" in {
|
|
|
|
|
convertTo(classOf[Duration], "10 nanos") must be(10 nanos)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
"DurationTypeConverter must do the roundtrip" in {
|
|
|
|
|
convertTo(classOf[Duration], DurationTypeConverter.toString(10 seconds)) must be(10 seconds)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
"DurationTypeConverter must throw if invalid format" in {
|
2012-05-23 23:59:55 +02:00
|
|
|
convertTo(classOf[Duration], "abc nanos") must be === null
|
|
|
|
|
|
|
|
|
|
intercept[NoTypeConversionAvailableException] {
|
|
|
|
|
mandatoryConvertTo(classOf[Duration], "abc nanos") must be(10 nanos)
|
|
|
|
|
}.getValue must be === "abc nanos"
|
2012-01-19 14:38:44 +00:00
|
|
|
}
|
|
|
|
|
|
2012-05-23 23:59:55 +02:00
|
|
|
"DurationTypeConverter must throw if doesn't end with time unit" in {
|
|
|
|
|
convertTo(classOf[Duration], "10233") must be === null
|
|
|
|
|
|
|
|
|
|
intercept[NoTypeConversionAvailableException] {
|
|
|
|
|
mandatoryConvertTo(classOf[Duration], "10233") must be(10 nanos)
|
|
|
|
|
}.getValue must be === "10233"
|
2012-01-19 14:38:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|