vert-x / testtools

Vert.x 2.x is deprecated - use instead
http://vertx.io/docs/vertx-unit/java/
Other
10 stars 10 forks source link

@Test(expected = ...) annotation #1

Closed darylteo closed 11 years ago

darylteo commented 11 years ago

Expected parameter does not work if the exception is triggered on a different tick of the event loop.

Perhaps a way to get around this is to have a VertxAssert.expected(Class<? extends Exception>) method, and then compare any thrown exceptions with the expected exception in handleError().

Daryl

purplefox commented 11 years ago

It should work. Test case?

darylteo commented 11 years ago

Sorry, here you go.

  @Test(expected = StringIndexOutOfBoundsException.class)
  public void exceptionTest() {
    vertx.runOnLoop(new SimpleHandler() {
      @Override
      protected void handle() {
        "Hello World".charAt(50);
        testComplete();
      }
    });
  }
purplefox commented 11 years ago

Ummm.. that's because the exception isn't being thrown from the exceptionTest method, it's being thrown from the handle() method. Completely different methods.

darylteo commented 11 years ago

Fair enough. I'll leave this here just in case anyone peruses it.