Uploaded image for project: 'Arquillian'
  1. Arquillian
  2. ARQ-1038

Unwrap EJBException, expect nested exceptions

XMLWordPrintable

    • Icon: Feature Request Feature Request
    • Resolution: Unresolved
    • Icon: Minor Minor
    • 2.0.0.Beta1
    • 1.0.1.Final
    • Base Implementation
    • None

      I'm often testing EJBs and am finding that the automatic wrapping of unchecked exceptions makes for rather verbose and noisy tests.

      I'd like to write:

          @Test(expected=IllegalArgumentException.class)
          public void cannotGetNullId() {
          	someEJB.getById(null);
          }
      

      but it will fail because IllegalArgumentException is an unchecked exception so it'll get wrapped in an EJBException. That's OK if I don't mind accepting all EJBExceptions, but I'd usually prefer to be more specific.

      I frequently find myself writing verbose code to unwrap a thrown exception and test it manually:

          public void cannotGetNullId() {
          	try {
          		someEJB.getById(null);
          	} catch (EJBException ex) {
          		if (ex.getCause() instanceof IllegalArgumentException) {
          			return;
          		}
          		ex.printStackTrace();
          		Assert.fail("Unexpected exception: " +ex);
          	}
          	Assert.fail("Expected IllegalArgumentException");
          }
      

      It'd be wonderful if Arquillian were able to provide EJBException unwrapping to make this testing process less ... icky.

      The usual approach to solving this problem involves extending JUnit's TestRunner, which doesn't fit well when Arquillian takes over this role.

      It looks like it's possible using rules and matchers, as per:

      http://stackoverflow.com/questions/871216/junit-possible-to-expect-a-wrapped-exception

      ... but with exception wrapping so universal in the Java EE space, being able to "expect" a nested exception would be a big plus.

              Unassigned Unassigned
              ringerc_jira Craig Ringer (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated: