You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@samza.apache.org by "Jakob Homan (JIRA)" <ji...@apache.org> on 2014/03/19 07:11:43 UTC

[jira] [Commented] (SAMZA-195) Elucidate TestUtil:expect

    [ https://issues.apache.org/jira/browse/SAMZA-195?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13940221#comment-13940221 ] 

Jakob Homan commented on SAMZA-195:
-----------------------------------

Currently it is:
{code}  def expect[T](exception: Class[T], msg: Option[String] = None)(block: => Unit) = try {
    block
  } catch {
    case e => if (msg.isDefined) {
      assertEquals(msg.get, e.getMessage)
    }
    case _ => fail("Expected an NPE.")
  }
}{code}
Seems like it should be something like:{code}
  def expect[T](exception: Class[T], msg: Option[String] = None)(block: => Unit) = {
    var gotException = false
    try {
      block
    } catch {
      case e if (msg.isDefined) => assertEquals(msg.get, e.getMessage)
                                   assertEquals(exception.getClass, e.getClass)
                                   gotException = true
      case e => assertEquals(exception.getClass, e.getClass)
                gotException = true
    }
    assertTrue("Should have hit exception: " + exception, gotException)
  }
{code}
This way we fail if we don't get the *expect*ed exception and if we do and it has an expected string, check that string, or if in either case of failure, we verify that the exception we got was what we expected.

> Elucidate TestUtil:expect
> -------------------------
>
>                 Key: SAMZA-195
>                 URL: https://issues.apache.org/jira/browse/SAMZA-195
>             Project: Samza
>          Issue Type: Improvement
>            Reporter: Jakob Homan
>
> The TestUtil::expect method seems a bit odd, as discussed in SAMZA-161.  



--
This message was sent by Atlassian JIRA
(v6.2#6252)