title: Cucumber JVM: Test if the correct exception is thrown
body: <p>How to test that the correct exception is thrown when using Cucumber JVM? When using JUnit, I would do something like this:</p>
  
  <pre><code>@Test(expected = NullPointerException.class)
  public void testExceptionThrown(){
      taskCreater.createTask(null);
  }
  </code></pre>
  
  <p>As you can see, this is very elegant. But how can I achieve the same elegance, when using cucumber JVM? My test looks like this right now:</p>
  
  <pre><code>@Then("the user gets a Null pointer exception$")
  public void null_exception_thrown() {
      boolean result = false;
      try {
          taskCreater.createTask(null);
      } catch (NullPointerException e) {
          result = true;
      }
      assertTrue(result);
  }
  </code></pre>
  
  <p>Note the need for a <code>try</code>..<code>catch</code> followed by an <code>assertTrue</code> on a flag.</p>