[arquillian-issues] [JBoss JIRA] (ARQ-1038) Unwrap EJBException, expect nested exceptions

Aslak Knutsen (JIRA) jira-events at lists.jboss.org
Mon Jul 23 07:28:06 EDT 2012


    [ https://issues.jboss.org/browse/ARQ-1038?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12707251#comment-12707251 ] 

Aslak Knutsen commented on ARQ-1038:
------------------------------------

The current problem with this is that the 'expected' handling is very internal in JUnit and not much we can hook into. But we can look at potentially just reading the same information as JUnit and adjust what we throw based on what it expects(if found in chain).
                
> Unwrap EJBException, expect nested exceptions
> ---------------------------------------------
>
>                 Key: ARQ-1038
>                 URL: https://issues.jboss.org/browse/ARQ-1038
>             Project: Arquillian
>          Issue Type: Feature Request
>      Security Level: Public(Everyone can see) 
>          Components: Base Implementation
>    Affects Versions: 1.0.1.Final
>         Environment: n/a
>            Reporter: Craig Ringer
>            Priority: Minor
>             Fix For: 1.1.0.Beta1
>
>
> 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:
> {code}
>     @Test(expected=IllegalArgumentException.class)
>     public void cannotGetNullId() {
>     	someEJB.getById(null);
>     }
> {code}
> 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:
> {code}
>     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");
>     }
> {code}
> 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.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.jboss.org/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the arquillian-issues mailing list