public void test_performOperation_whenException() throws Exception { Logger oldLogger = AnalysisEngine.getInstance().getLogger(); try { Error myException = new Error(); when(unit.accept(isA(AngularHtmlIndexContributor.class))).thenThrow(myException); // set mock Logger Logger logger = mock(Logger.class); AnalysisEngine.getInstance().setLogger(logger); // run operation operation.performOperation(); // verify that "myException" was logged verify(logger).logError(anyString(), same(myException)); } finally { AnalysisEngine.getInstance().setLogger(oldLogger); } }
/** * Build the HTML element for the given source. * * @param source the source describing the compilation unit * @param unit the AST structure representing the HTML * @throws AnalysisException if the analysis could not be performed */ public HtmlElementImpl buildHtmlElement(Source source, HtmlUnit unit) throws AnalysisException { HtmlElementImpl result = new HtmlElementImpl(context, source.getShortName()); result.setSource(source); htmlElement = result; unit.accept(this); htmlElement = null; unit.setElement(result); return result; }
@Override public Void visitHtmlUnit(HtmlUnit node) { scripts = new ArrayList<HtmlScriptElement>(); node.visitChildren(this); htmlElement.setScripts(scripts.toArray(new HtmlScriptElement[scripts.size()])); scripts = null; return null; }
@Override protected void setUp() throws Exception { super.setUp(); when(store.aboutToIndexHtml(context, htmlElement)).thenReturn(true); when(unit.getElement()).thenReturn(htmlElement); when(htmlElement.getSource()).thenReturn(unitSource); when(htmlElement.getAngularCompilationUnit()).thenReturn(unitElement); when(unitElement.getSource()).thenReturn(unitSource); operation = new IndexHtmlUnitOperation(store, context, unit); }