title: Test if an exception is caught with Junit
body: <p>I'll begin with a code example; I have to test a function, which handles data-packets. In this function, the data-packet is opened and when it doesn't contain all expected data, an InvalidParameterExeption is thrown which is logged. </p>
  
  <pre><code>public void handleData(dataPacket) {
      try {
          analyseData(dataPacket);
      } catch (InvalidParameterException e) {
          e.printStackTrace()
      }
  }
  </code></pre>
  
  <p>So, if everything goes well, my exception is printed in my terminal.
  But how can I test this? I can't use this: (because the exception is caught)</p>
  
  <pre><code>@Test(expected = InvalidParameterExeption.class)
  public void testIfFaultyDataPacketIsRecognised {
      handleData(faultyDataPacket);
  }
  </code></pre>
  
  <p>How can I test that the InvalidParameterExeption is thrown?</p>