Permalink
Browse files

Removed the String message from Failure

  • Loading branch information...
1 parent db8933a commit eaf3a4c2538f85eba67e4f42414660eeb879ef03 @johanflint johanflint committed Feb 27, 2012
@@ -114,26 +114,22 @@ private[boite] sealed abstract class BoiteVide extends Box[Nothing] {
case object Empty extends BoiteVide
-sealed case class Failure(message: String, exception: Throwable) extends BoiteVide {
+sealed case class Failure(exception: Throwable) extends BoiteVide {
type A = Nothing
override def map[B](f: A => B): Box[B] = this
override def flatMap[B](f: A => Box[B]): Box[B] = this
override final def equals(other: Any): Boolean = (this, other) match {
- case (Failure(x, y), Failure(a, b)) => (x, y) == (a, b)
+ case (Failure(x), Failure(a)) => (x) == (a)
case (x, y: AnyRef) => x eq y
case _ => false
}
- override final def hashCode: Int = exception.hashCode + (message match {
- case null => 0
- case m => 31 * m.hashCode
- })
+ override final def hashCode: Int = exception.hashCode
}
object Failure {
- def apply(message: String) = new Failure(message, new Exception)
- def apply(throwable: Throwable) = new Failure(throwable.getMessage, throwable)
+ def apply(message: String) = new Failure(new Exception(message))
}
@@ -21,7 +21,7 @@ class BoxTest extends FlatSpec with ShouldMatchers {
}
it should "return Failure when an exception is thrown while evaluating the expression passed to it" in {
- Box wrap { throw Exception } should equal (Failure("not supported", Exception))
+ Box wrap { throw Exception } should equal (Failure(Exception))
}
it should "let Errors pass through" in {
@@ -14,7 +14,7 @@ class FailureTest extends FlatSpec with ShouldMatchers with MockitoSugar {
val Throwable = new Exception
val FileNotFoundException = new FileNotFoundException(Message)
- val failure = new Failure(Message, Throwable)
+ val failure = Failure(Throwable)
"Failure" should "be empty" in {
failure.isEmpty should equal (true)
@@ -28,10 +28,6 @@ class FailureTest extends FlatSpec with ShouldMatchers with MockitoSugar {
failure.getOrElse(404) should equal (404)
}
- "Failure with a throwable" should "copy the message correctly" in {
- Failure(FileNotFoundException).message == Message should be (true)
- }
-
"map" should "return the same instance" in {
failure.map(s => s) should equal (failure)
}
@@ -50,8 +46,4 @@ class FailureTest extends FlatSpec with ShouldMatchers with MockitoSugar {
"toList" should "return an empty list" in {
Empty.toList should equal (List())
}
-
- "Failure.apply(message, throwable)" should "be equal to calling new with the same arguments" in {
- Failure(Message, Throwable) should equal (failure)
- }
}

0 comments on commit eaf3a4c

Please sign in to comment.