### Question:
Processor { public Gadget process(GadgetContext context) throws ProcessingException { Uri url = context.getUrl(); if (url == null) { throw new ProcessingException("Missing or malformed url parameter", HttpServletResponse.SC_BAD_REQUEST); } if (!"http".equalsIgnoreCase(url.getScheme()) && !"https".equalsIgnoreCase(url.getScheme())) { throw new ProcessingException("Unsupported scheme (must be http or https).", HttpServletResponse.SC_FORBIDDEN); } if (blacklist.isBlacklisted(context.getUrl())) { LOG.info("Attempted to render blacklisted gadget: " + context.getUrl()); throw new ProcessingException("The requested gadget is unavailable", HttpServletResponse.SC_FORBIDDEN); } try { GadgetSpec spec = gadgetSpecFactory.getGadgetSpec(context); spec = substituter.substitute(context, spec); return new Gadget() .setContext(context) .setGadgetFeatureRegistry(featureRegistry) .setSpec(spec) .setCurrentView(getView(context, spec)); } catch (GadgetException e) { throw new ProcessingException(e.getMessage(), e, e.getHttpStatusCode()); } } @Inject  Processor(GadgetSpecFactory gadgetSpecFactory,
                   VariableSubstituter substituter,
                   ContainerConfig containerConfig,
                   GadgetBlacklist blacklist,
                   FeatureRegistry featureRegistry); Gadget process(GadgetContext context);  }### Answer:
@Test public void normalProcessing() throws Exception { Gadget gadget = processor.process(makeContext("html")); assertEquals(BASIC_HTML_CONTENT, gadget.getCurrentView().getContent()); }
@Test(expected = ProcessingException.class) public void handlesGadgetExceptionGracefully() throws Exception { gadgetSpecFactory.exception = new GadgetException(GadgetException.Code.INVALID_PATH); processor.process(makeContext("url")); }
@Test public void doViewAliasing() throws Exception { Gadget gadget = processor.process(makeContext("aliased")); assertEquals(BASIC_HTML_CONTENT, gadget.getCurrentView().getContent()); }
@Test public void noSupportedViewHasNoCurrentView() throws Exception { Gadget gadget = processor.process(makeContext("not-real-view")); assertNull(gadget.getCurrentView()); }
@Test public void substitutionsPerformedTypeHtml() throws Exception { processor.process(makeContext("html")); assertTrue("Substitutions not performed", substituter.wasSubstituted); }
@Test public void substitutionsPerformedTypeUrl() throws Exception { processor.process(makeContext("url")); assertTrue("Substitutions not performed", substituter.wasSubstituted); }
@Test public void blacklistChecked() throws Exception { processor.process(makeContext("url")); assertTrue("Blacklist not checked", blacklist.wasChecked); }
@Test public void blacklistedGadgetThrows() throws Exception { blacklist.isBlacklisted = true; try { processor.process(makeContext("html")); fail("expected ProcessingException"); } catch (ProcessingException e) { assertEquals(HttpServletResponse.SC_FORBIDDEN, e.getHttpStatusCode()); } }
@Test public void nullUrlThrows() throws Exception { try { processor.process(makeContext("html", null)); fail("expected ProcessingException"); } catch (ProcessingException e) { assertEquals(HttpServletResponse.SC_BAD_REQUEST, e.getHttpStatusCode()); } }
@Test public void nonHttpOrHttpsThrows() throws Exception { try { processor.process(makeContext("html", Uri.parse("file: fail("expected ProcessingException"); } catch (ProcessingException e) { assertEquals(HttpServletResponse.SC_FORBIDDEN, e.getHttpStatusCode()); } }