diff options
author | Rocky Madden <git@rockymadden.com> | 2012-12-10 13:03:26 -0700 |
---|---|---|
committer | Rocky Madden <git@rockymadden.com> | 2012-12-10 13:03:26 -0700 |
commit | b49d899d7fedcda56c7d30e7cf43d8abd5d83d22 (patch) | |
tree | 734d3d9d0eb14bb906464722f5d4af9ce79ee61f /cli | |
parent | 2bd77a552f41da2db4c3944816396d9c6fad2178 (diff) | |
download | stringmetric-b49d899d7fedcda56c7d30e7cf43d8abd5d83d22.tar.gz stringmetric-b49d899d7fedcda56c7d30e7cf43d8abd5d83d22.tar.bz2 stringmetric-b49d899d7fedcda56c7d30e7cf43d8abd5d83d22.zip |
IllegalArgumentException thrown if implicit would return None.
Diffstat (limited to 'cli')
-rwxr-xr-x | cli/source/core/scala/org/hashtree/stringmetric/cli/OptionMapType.scala | 4 | ||||
-rwxr-xr-x | cli/source/test/scala/org/hashtree/stringmetric/cli/OptionMapTypeSpec.scala | 63 |
2 files changed, 66 insertions, 1 deletions
diff --git a/cli/source/core/scala/org/hashtree/stringmetric/cli/OptionMapType.scala b/cli/source/core/scala/org/hashtree/stringmetric/cli/OptionMapType.scala index 61c5542..b52cc9e 100755 --- a/cli/source/core/scala/org/hashtree/stringmetric/cli/OptionMapType.scala +++ b/cli/source/core/scala/org/hashtree/stringmetric/cli/OptionMapType.scala @@ -67,7 +67,9 @@ final case class OptionMapShort(shortString: String) extends OptionMapType[Short object OptionMapType { implicit def OptionMapTypeToOptionT[T](optionMapType: OptionMapType[T]): Option[T] = optionMapType.get - implicit def OptionMapTypeToT[T](optionMapType: OptionMapType[T]): T = optionMapType.get.get + implicit def OptionMapTypeToT[T](optionMapType: OptionMapType[T]): T = + if(!optionMapType.isDefined) throw new IllegalArgumentException("Expected successful type conversion.") + else optionMapType.get.get implicit def StringToOptionMapArray(string: String): OptionMapArray = new OptionMapArray(string) diff --git a/cli/source/test/scala/org/hashtree/stringmetric/cli/OptionMapTypeSpec.scala b/cli/source/test/scala/org/hashtree/stringmetric/cli/OptionMapTypeSpec.scala index 148e322..8f4d4bc 100755 --- a/cli/source/test/scala/org/hashtree/stringmetric/cli/OptionMapTypeSpec.scala +++ b/cli/source/test/scala/org/hashtree/stringmetric/cli/OptionMapTypeSpec.scala @@ -15,6 +15,13 @@ final class OptionMapTypeSpec extends ScalaTest { (OptionMapArray(""): Option[Array[String]]).isDefined should be (false) } } + "invalid argument accessed via implicit to type" should throws { + "IllegalArgumentException" in { + evaluating { + OptionMapArray(""): Array[String] + } should produce[IllegalArgumentException] + } + } "valid argument" should returns { "Array" in { OptionMapArray("1").get.get should equal (Array("1")) @@ -37,6 +44,13 @@ final class OptionMapTypeSpec extends ScalaTest { (OptionMapBigDecimal("one"): Option[BigDecimal]).isDefined should be (false) } } + "invalid argument accessed via implicit to type" should throws { + "IllegalArgumentException" in { + evaluating { + OptionMapBigDecimal("one"): BigDecimal + } should produce[IllegalArgumentException] + } + } "valid argument" should returns { "BigDecimal" in { OptionMapBigDecimal("1").get.get should equal (1: BigDecimal) @@ -57,6 +71,13 @@ final class OptionMapTypeSpec extends ScalaTest { (OptionMapBigInt("one"): Option[BigInt]).isDefined should be (false) } } + "invalid argument accessed via implicit to type" should throws { + "IllegalArgumentException" in { + evaluating { + OptionMapBigInt("one"): BigInt + } should produce[IllegalArgumentException] + } + } "valid argument" should returns { "BigInt" in { OptionMapBigInt("1").get.get should equal (1: BigInt) @@ -77,6 +98,13 @@ final class OptionMapTypeSpec extends ScalaTest { (OptionMapDouble("one"): Option[Double]).isDefined should be (false) } } + "invalid argument accessed via implicit to type" should throws { + "IllegalArgumentException" in { + evaluating { + OptionMapDouble("one"): Double + } should produce[IllegalArgumentException] + } + } "valid argument" should returns { "Double" in { OptionMapDouble("1").get.get should equal (1d) @@ -97,6 +125,13 @@ final class OptionMapTypeSpec extends ScalaTest { (OptionMapFloat("one"): Option[Float]).isDefined should be (false) } } + "invalid argument accessed via implicit to type" should throws { + "IllegalArgumentException" in { + evaluating { + OptionMapFloat("one"): Float + } should produce[IllegalArgumentException] + } + } "valid argument" should returns { "Float" in { OptionMapFloat("1").get.get should equal (1f) @@ -117,6 +152,13 @@ final class OptionMapTypeSpec extends ScalaTest { (OptionMapInt("one"): Option[Int]).isDefined should be (false) } } + "invalid argument accessed via implicit to type" should throws { + "IllegalArgumentException" in { + evaluating { + OptionMapInt("one"): Int + } should produce[IllegalArgumentException] + } + } "valid argument" should returns { "Int" in { OptionMapInt("1").get.get should equal (1) @@ -135,6 +177,13 @@ final class OptionMapTypeSpec extends ScalaTest { (OptionMapList(""): Option[List[String]]).isDefined should be (false) } } + "invalid argument accessed via implicit to type" should throws { + "IllegalArgumentException" in { + evaluating { + OptionMapList(""): List[String] + } should produce[IllegalArgumentException] + } + } "valid argument" should returns { "List" in { OptionMapList("1").get.get should equal (List("1")) @@ -157,6 +206,13 @@ final class OptionMapTypeSpec extends ScalaTest { (OptionMapLong("one"): Option[Long]).isDefined should be (false) } } + "invalid argument accessed via implicit to type" should throws { + "IllegalArgumentException" in { + evaluating { + OptionMapLong("one"): Long + } should produce[IllegalArgumentException] + } + } "valid argument" should returns { "Long" in { OptionMapLong("1").get.get should equal (1l) @@ -177,6 +233,13 @@ final class OptionMapTypeSpec extends ScalaTest { (OptionMapShort("one"): Option[Short]).isDefined should be (false) } } + "invalid argument accessed via implicit to type" should throws { + "IllegalArgumentException" in { + evaluating { + OptionMapShort("one"): Short + } should produce[IllegalArgumentException] + } + } "valid argument" should returns { "Short" in { OptionMapShort("1").get.get should equal (1: Short) |