@Test void parseError() throws Exception { Parser parser = mock(Parser.class); when(this.componentManager.getInstance(Parser.class, XWIKI_2_1.toIdString())).thenReturn( parser); when(parser.parse(ArgumentMatchers.any(Reader.class))).thenThrow(new ParseException("")); Optional<XDOM> actual = this.xdomService.parse("ABC", XWIKI_2_1); assertEquals(1, this.logCapture.size()); assertEquals(Level.WARN, this.logCapture.getLogEvent(0).getLevel()); assertEquals("Failed to parse the payload [ABC]. Cause [ParseException: ].", this.logCapture.getMessage(0)); assertEquals(Optional.empty(), actual); }
@Override public Optional<XDOM> parse(String payload, Syntax syntax) { Optional<XDOM> oxdom; try { Parser instance = this.componentManager.get().getInstance(Parser.class, syntax.toIdString()); XDOM xdom = instance.parse(new StringReader(payload)); oxdom = Optional.of(xdom); } catch (ParseException e) { this.logger .warn("Failed to parse the payload [{}]. Cause [{}].", payload, ExceptionUtils.getRootCauseMessage(e)); oxdom = Optional.empty(); } catch (ComponentLookupException e) { this.logger .warn("Failed to get the parser instance [{}]. Cause [{}].", syntax, ExceptionUtils.getRootCauseMessage(e)); oxdom = Optional.empty(); } return oxdom; }
DefaultMentionXDOMService implements MentionXDOMService { @Override public Optional<XDOM> parse(String payload, Syntax syntax) { Optional<XDOM> oxdom; try { Parser instance = this.componentManager.get().getInstance(Parser.class, syntax.toIdString()); XDOM xdom = instance.parse(new StringReader(payload)); oxdom = Optional.of(xdom); } catch (ParseException e) { this.logger .warn("Failed to parse the payload [{}]. Cause [{}].", payload, ExceptionUtils.getRootCauseMessage(e)); oxdom = Optional.empty(); } catch (ComponentLookupException e) { this.logger .warn("Failed to get the parser instance [{}]. Cause [{}].", syntax, ExceptionUtils.getRootCauseMessage(e)); oxdom = Optional.empty(); } return oxdom; } }
DefaultMentionXDOMService implements MentionXDOMService { @Override public Optional<XDOM> parse(String payload, Syntax syntax) { Optional<XDOM> oxdom; try { Parser instance = this.componentManager.get().getInstance(Parser.class, syntax.toIdString()); XDOM xdom = instance.parse(new StringReader(payload)); oxdom = Optional.of(xdom); } catch (ParseException e) { this.logger .warn("Failed to parse the payload [{}]. Cause [{}].", payload, ExceptionUtils.getRootCauseMessage(e)); oxdom = Optional.empty(); } catch (ComponentLookupException e) { this.logger .warn("Failed to get the parser instance [{}]. Cause [{}].", syntax, ExceptionUtils.getRootCauseMessage(e)); oxdom = Optional.empty(); } return oxdom; }  }
DefaultMentionXDOMService implements MentionXDOMService { @Override public Optional<XDOM> parse(String payload, Syntax syntax) { Optional<XDOM> oxdom; try { Parser instance = this.componentManager.get().getInstance(Parser.class, syntax.toIdString()); XDOM xdom = instance.parse(new StringReader(payload)); oxdom = Optional.of(xdom); } catch (ParseException e) { this.logger .warn("Failed to parse the payload [{}]. Cause [{}].", payload, ExceptionUtils.getRootCauseMessage(e)); oxdom = Optional.empty(); } catch (ComponentLookupException e) { this.logger .warn("Failed to get the parser instance [{}]. Cause [{}].", syntax, ExceptionUtils.getRootCauseMessage(e)); oxdom = Optional.empty(); } return oxdom; }  @Override List<MacroBlock> listMentionMacros(XDOM xdom); @Override Map<DocumentReference, List<String>> groupAnchorsByUserReference(List<MacroBlock> mentions,
        WikiReference wikiReference); @Override Optional<XDOM> parse(String payload, Syntax syntax); }
DefaultMentionXDOMService implements MentionXDOMService { @Override public Optional<XDOM> parse(String payload, Syntax syntax) { Optional<XDOM> oxdom; try { Parser instance = this.componentManager.get().getInstance(Parser.class, syntax.toIdString()); XDOM xdom = instance.parse(new StringReader(payload)); oxdom = Optional.of(xdom); } catch (ParseException e) { this.logger .warn("Failed to parse the payload [{}]. Cause [{}].", payload, ExceptionUtils.getRootCauseMessage(e)); oxdom = Optional.empty(); } catch (ComponentLookupException e) { this.logger .warn("Failed to get the parser instance [{}]. Cause [{}].", syntax, ExceptionUtils.getRootCauseMessage(e)); oxdom = Optional.empty(); } return oxdom; }  @Override List<MacroBlock> listMentionMacros(XDOM xdom); @Override Map<DocumentReference, List<String>> groupAnchorsByUserReference(List<MacroBlock> mentions,
        WikiReference wikiReference); @Override Optional<XDOM> parse(String payload, Syntax syntax);  }