Author: mwringe
Date: 2010-02-16 14:04:13 -0500 (Tue, 16 Feb 2010)
New Revision: 1756
Modified:
components/wci/trunk/test/core/src/main/java/org/gatein/wci/container/ServletContainerTestCase.java
components/wci/trunk/wci/src/main/java/org/gatein/wci/impl/DefaultServletContainer.java
Log:
GTNWCI-14: throw WebAppListener errors instead of just printing the stacktrace. Tests
updated to check for this.
Modified:
components/wci/trunk/test/core/src/main/java/org/gatein/wci/container/ServletContainerTestCase.java
===================================================================
---
components/wci/trunk/test/core/src/main/java/org/gatein/wci/container/ServletContainerTestCase.java 2010-02-16
16:59:00 UTC (rev 1755)
+++
components/wci/trunk/test/core/src/main/java/org/gatein/wci/container/ServletContainerTestCase.java 2010-02-16
19:04:13 UTC (rev 1756)
@@ -276,7 +276,7 @@
public void onEvent(WebAppEvent event)
{
called.set(true);
- throw new RuntimeException("Expected : don't freak out");
+ throw new RuntimeException("Expected Exception: don't freak
out");
}
});
@@ -285,4 +285,37 @@
assertTrue(called.get());
assertEquals(Tools.toSet("/foo"), registry.getKeys());
}
+
+ @Test
+ public void testListenerError()
+ {
+ ServletContainer container = new DefaultServletContainer();
+ ServletContainerContextImpl scc = new ServletContainerContextImpl();
+ WebAppRegistry registry = new WebAppRegistry();
+
+ //
+ final SynchronizedBoolean called = new SynchronizedBoolean(false);
+ container.register(scc);
+ container.addWebAppListener(registry);
+ container.addWebAppListener(new WebAppListener()
+ {
+ public void onEvent(WebAppEvent event)
+ {
+ called.set(true);
+ throw new Error("Expected Error: don't freak out");
+ }
+ });
+
+ //
+ try
+ {
+ scc.registration.registerWebApp(new WebAppContextImpl("/foo"));
+ fail("Was expecting an error to be thrown");
+ }
+ catch (Throwable t)
+ {
+ }
+ assertTrue(called.get());
+ assertEquals(Tools.toSet("/foo"), registry.getKeys());
+ }
}
Modified:
components/wci/trunk/wci/src/main/java/org/gatein/wci/impl/DefaultServletContainer.java
===================================================================
---
components/wci/trunk/wci/src/main/java/org/gatein/wci/impl/DefaultServletContainer.java 2010-02-16
16:59:00 UTC (rev 1755)
+++
components/wci/trunk/wci/src/main/java/org/gatein/wci/impl/DefaultServletContainer.java 2010-02-16
19:04:13 UTC (rev 1756)
@@ -146,9 +146,16 @@
{
listener.onEvent(event);
}
- catch (Exception e)
+ catch (Throwable t)
{
- e.printStackTrace();
+ if (t instanceof Error)
+ {
+ throw (Error)t;
+ }
+ else
+ {
+ t.printStackTrace();
+ }
}
}
Show replies by date