- Revision
- 556
- Author
- mward
- Date
- 2008-01-17 11:16:09 -0600 (Thu, 17 Jan 2008)
Log Message
WAFFLE-57 : now wrapping any pico exception thrown in a WaffleException.
Modified Paths
Added Paths
Diff
Modified: trunk/waffle-core/src/main/java/org/codehaus/waffle/context/pico/PicoContextContainer.java (555 => 556)
--- trunk/waffle-core/src/main/java/org/codehaus/waffle/context/pico/PicoContextContainer.java 2008-01-17 15:29:02 UTC (rev 555) +++ trunk/waffle-core/src/main/java/org/codehaus/waffle/context/pico/PicoContextContainer.java 2008-01-17 17:16:09 UTC (rev 556) @@ -10,14 +10,16 @@ *****************************************************************************/ package org.codehaus.waffle.context.pico; +import org.codehaus.waffle.WaffleException; import org.codehaus.waffle.context.ContextContainer; import org.picocontainer.MutablePicoContainer; import org.picocontainer.PicoContainer; +import org.picocontainer.PicoException; import org.picocontainer.defaults.DefaultPicoContainer; +import java.util.ArrayList; import java.util.Collection; import java.util.List; -import java.util.ArrayList; public class PicoContextContainer implements ContextContainer { private final MutablePicoContainer delegate; @@ -47,7 +49,11 @@ } public Object getComponentInstance(Object key) { - return delegate.getComponentInstance(key); + try { + return delegate.getComponentInstance(key); + } catch (PicoException e) { + throw new WaffleException("Unable to construct component '" + key +"'.", e); + } } @SuppressWarnings({"unchecked"})
Added: trunk/waffle-core/src/test/java/org/codehaus/waffle/context/pico/PicoContextContainerTest.java (0 => 556)
--- trunk/waffle-core/src/test/java/org/codehaus/waffle/context/pico/PicoContextContainerTest.java (rev 0) +++ trunk/waffle-core/src/test/java/org/codehaus/waffle/context/pico/PicoContextContainerTest.java 2008-01-17 17:16:09 UTC (rev 556) @@ -0,0 +1,42 @@ +package org.codehaus.waffle.context.pico; + +import org.codehaus.waffle.WaffleException; +import org.jmock.Expectations; +import org.jmock.Mockery; +import org.jmock.integration.junit4.JMock; +import org.junit.Assert; +import org.junit.Test; +import static org.junit.Assert.fail; +import org.junit.runner.RunWith; +import org.picocontainer.MutablePicoContainer; +import org.picocontainer.PicoException; + +/** + * + * @author Michael Ward + */ [EMAIL PROTECTED](JMock.class) +public class PicoContextContainerTest { + private Mockery mockery = new Mockery(); + + @SuppressWarnings({"ThrowableInstanceNeverThrown"}) + @Test + public void getComponentInstanceShouldWrapAnyPicoException() { + final MutablePicoContainer mutablePicoContainer = mockery.mock(MutablePicoContainer.class); + mockery.checking(new Expectations() { + { + one(mutablePicoContainer).getComponentInstance("foo"); + will(throwException(new PicoException("fake from test") {})); + } + }); + + PicoContextContainer picoContextContainer = new PicoContextContainer(mutablePicoContainer); + + try { + picoContextContainer.getComponentInstance("foo"); + fail("WaffleException expected"); + } catch (WaffleException expected) { + Assert.assertEquals("Unable to construct component 'foo'.", expected.getMessage()); + } + } +}
To unsubscribe from this list please visit:
