@Test public void createStubContextWithLoopProtection() { XWikiContext[] subContext = new XWikiContext[1]; when(this.urlFactoryService.createURLFactory(anyInt(), any())).then(new Answer<XWikiURLFactory>() { @Override public XWikiURLFactory answer(InvocationOnMock invocation) throws Throwable { subContext[0] = provider.createStubContext(); return null; } }); XWikiContext xcontext = this.provider.createStubContext(); assertNotNull(xcontext); assertSame(subContext[0], xcontext); assertNotSame(this.oldcore.getXWikiContext(), xcontext); }
@Override public XWikiContext createStubContext() { XWikiContext stubContext; if (this.initialContext != null) { ExecutionContext econtext = this.execution.getContext(); if (econtext != null) { stubContext = (XWikiContext) econtext.getProperty(XCONTEXT_STUB); if (stubContext != null) { return stubContext; } } try { stubContext = this.initialContext.clone(); if (econtext != null) { econtext.setProperty(XCONTEXT_STUB, stubContext); } initiazeXWikiContext(stubContext); } finally { if (econtext != null) { econtext.removeProperty(XCONTEXT_STUB); } } } else { stubContext = null; } return stubContext; }
DefaultXWikiStubContextProvider implements XWikiStubContextProvider { @Override public XWikiContext createStubContext() { XWikiContext stubContext; if (this.initialContext != null) { ExecutionContext econtext = this.execution.getContext(); if (econtext != null) { stubContext = (XWikiContext) econtext.getProperty(XCONTEXT_STUB); if (stubContext != null) { return stubContext; } } try { stubContext = this.initialContext.clone(); if (econtext != null) { econtext.setProperty(XCONTEXT_STUB, stubContext); } initiazeXWikiContext(stubContext); } finally { if (econtext != null) { econtext.removeProperty(XCONTEXT_STUB); } } } else { stubContext = null; } return stubContext; } }
DefaultXWikiStubContextProvider implements XWikiStubContextProvider { @Override public XWikiContext createStubContext() { XWikiContext stubContext; if (this.initialContext != null) { ExecutionContext econtext = this.execution.getContext(); if (econtext != null) { stubContext = (XWikiContext) econtext.getProperty(XCONTEXT_STUB); if (stubContext != null) { return stubContext; } } try { stubContext = this.initialContext.clone(); if (econtext != null) { econtext.setProperty(XCONTEXT_STUB, stubContext); } initiazeXWikiContext(stubContext); } finally { if (econtext != null) { econtext.removeProperty(XCONTEXT_STUB); } } } else { stubContext = null; } return stubContext; }  }
DefaultXWikiStubContextProvider implements XWikiStubContextProvider { @Override public XWikiContext createStubContext() { XWikiContext stubContext; if (this.initialContext != null) { ExecutionContext econtext = this.execution.getContext(); if (econtext != null) { stubContext = (XWikiContext) econtext.getProperty(XCONTEXT_STUB); if (stubContext != null) { return stubContext; } } try { stubContext = this.initialContext.clone(); if (econtext != null) { econtext.setProperty(XCONTEXT_STUB, stubContext); } initiazeXWikiContext(stubContext); } finally { if (econtext != null) { econtext.removeProperty(XCONTEXT_STUB); } } } else { stubContext = null; } return stubContext; }  @Override void initialize(XWikiContext context); @Override XWikiContext createStubContext(); }
DefaultXWikiStubContextProvider implements XWikiStubContextProvider { @Override public XWikiContext createStubContext() { XWikiContext stubContext; if (this.initialContext != null) { ExecutionContext econtext = this.execution.getContext(); if (econtext != null) { stubContext = (XWikiContext) econtext.getProperty(XCONTEXT_STUB); if (stubContext != null) { return stubContext; } } try { stubContext = this.initialContext.clone(); if (econtext != null) { econtext.setProperty(XCONTEXT_STUB, stubContext); } initiazeXWikiContext(stubContext); } finally { if (econtext != null) { econtext.removeProperty(XCONTEXT_STUB); } } } else { stubContext = null; } return stubContext; }  @Override void initialize(XWikiContext context); @Override XWikiContext createStubContext();  }