@Test public void getVelocityEngineWhenNoVelocityEngineInCache() throws Exception { Execution execution = this.mocker.getInstance(Execution.class); ExecutionContext executionContext = new ExecutionContext(); when(execution.getContext()).thenReturn(executionContext); XWikiContext xwikiContext = mock(XWikiContext.class); Provider<XWikiContext> xcontextProvider = this.mocker.getInstance(XWikiContext.TYPE_PROVIDER); when(xcontextProvider.get()).thenReturn(xwikiContext); com.xpn.xwiki.XWiki xwiki = mock(com.xpn.xwiki.XWiki.class); when(xwikiContext.getWiki()).thenReturn(xwiki); when(xwiki.getSkin(any(XWikiContext.class))).thenReturn("testskin"); VelocityFactory velocityFactory = this.mocker.getInstance(VelocityFactory.class); when(velocityFactory.hasVelocityEngine("default")).thenReturn(false); VelocityConfiguration velocityConfiguration = this.mocker.getInstance(VelocityConfiguration.class); when(velocityConfiguration.getProperties()).thenReturn(new Properties()); VelocityEngine velocityEngine = mock(VelocityEngine.class); when(velocityFactory.createVelocityEngine(eq("default"), any(Properties.class))) .thenReturn(velocityEngine); Assert.assertSame(velocityEngine, this.mocker.getComponentUnderTest().getVelocityEngine()); }