### Question:
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();  }### Answer:
@Test public void createStubContext() { XWikiContext xcontext1 = this.provider.createStubContext(); XWikiContext xcontext2 = this.provider.createStubContext(); assertNotSame(xcontext1, xcontext2); assertNotSame(xcontext1.getRequest(), xcontext2.getRequest()); assertNotSame(xcontext1.getResponse(), xcontext2.getResponse()); assertNotSame(xcontext1.getURLFactory(), xcontext2.getURLFactory()); }
@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); }
@Test public void createStubContextWithNoExecutionContext() { when(this.execution.getContext()).thenReturn(null); assertNotNull(this.provider.createStubContext()); }