@Test public void get_resource_exception() throws Exception { String path = "/foo"; Throwable t = new MalformedURLException("/foo is not a URL."); ServletContext servletContext = newServletContext(); expect(servletContext.getResource(path)).andThrow(t); replay(); try { new ContextImpl(servletContext).getResource(path); unreachable(); } catch (RuntimeException ex) { assertEquals(ex.getMessage(), "java.net.MalformedURLException: /foo is not a URL."); assertSame(ex.getCause(), t); } verify(); }
public URL getResource(String path) { try { return servletContext.getResource(path); } catch (MalformedURLException ex) { throw new RuntimeException(ex); } }
ContextImpl implements Context { public URL getResource(String path) { try { return servletContext.getResource(path); } catch (MalformedURLException ex) { throw new RuntimeException(ex); } } }
ContextImpl implements Context { public URL getResource(String path) { try { return servletContext.getResource(path); } catch (MalformedURLException ex) { throw new RuntimeException(ex); } } ContextImpl(ServletContext servletContext); }
ContextImpl implements Context { public URL getResource(String path) { try { return servletContext.getResource(path); } catch (MalformedURLException ex) { throw new RuntimeException(ex); } } ContextImpl(ServletContext servletContext); URL getResource(String path); File getRealFile(String path); String getInitParameter(String name); @SuppressWarnings("unchecked") List<String> getResourcePaths(String path); Object getAttribute(String name); List<String> getAttributeNames(); String getMimeType(String file); }
ContextImpl implements Context { public URL getResource(String path) { try { return servletContext.getResource(path); } catch (MalformedURLException ex) { throw new RuntimeException(ex); } } ContextImpl(ServletContext servletContext); URL getResource(String path); File getRealFile(String path); String getInitParameter(String name); @SuppressWarnings("unchecked") List<String> getResourcePaths(String path); Object getAttribute(String name); List<String> getAttributeNames(); String getMimeType(String file);  }