@Test public void getAutoCompletionHintsForScriptServiceProperty() throws Exception { MockitoComponentMockingRule cm = mocker.getInstance(ComponentManager.class); AutoCompletionMethodFinder scriptServiceFinder = cm.registerMockComponent(AutoCompletionMethodFinder.class, "services"); ScriptServiceManager scriptServiceManager = mock(ScriptServiceManager.class); setupMocks("$services.t", createTestVelocityContext("services", scriptServiceManager)); when(scriptServiceFinder.findMethods(scriptServiceManager.getClass(), "t")) .thenReturn(new Hints().withHints(new HintData("test", "test"))); String velocity = "{{velocity}}$services.t"; Hints hints = mocker .getComponentUnderTest() .getAutoCompletionHints(velocity.length(), "xwiki/2.0", velocity); assertEquals(1, hints.getHints().size()); assertTrue(hints.getHints().contains(new HintData("test", "test"))); }
@Test public void getAutoCompletionHintsForScriptServicePropertyWhenNestedCalls() throws Exception { MockitoComponentMockingRule cm = mocker.getInstance(ComponentManager.class); AutoCompletionMethodFinder scriptServiceFinder = cm.registerMockComponent(AutoCompletionMethodFinder.class, "services"); ScriptServiceManager scriptServiceManager = mock(ScriptServiceManager.class); setupMocks("$services.query.m", createTestVelocityContext("services", scriptServiceManager)); when(scriptServiceFinder.findMethodReturnTypes(scriptServiceManager.getClass(), "query")) .thenReturn(Arrays.asList((Class) TestClass.class)); AutoCompletionMethodFinder defaultMethodFinder = mocker.getInstance(AutoCompletionMethodFinder.class); when(defaultMethodFinder.findMethods(TestClass.class, "m")) .thenReturn(new Hints().withHints(new HintData("method", "method"))); String velocity = "{{velocity}}$services.query.m"; Hints hints = this.mocker .getComponentUnderTest() .getAutoCompletionHints(velocity.length(), "xwiki/2.0", velocity); assertEquals(1, hints.getHints().size()); assertTrue(hints.getHints().contains(new HintData("method", "method"))); }