get rid of intellij.build.toolbox.litegen parameter and use BuildOptions.TOOLBOX_LITE...
[idea/community.git] / java / java-tests / testSrc / com / intellij / java / codeInsight / template / LiveTemplateAutoPopupTest.java
1 // Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
2 package com.intellij.java.codeInsight.template;
3
4
5 import com.intellij.codeInsight.completion.CompletionAutoPopupTestCase;
6 import com.intellij.codeInsight.template.JavaCodeContextType;
7 import com.intellij.codeInsight.template.TemplateContextType;
8 import com.intellij.codeInsight.template.TemplateManager;
9 import com.intellij.codeInsight.template.impl.LiveTemplateCompletionContributor;
10 import com.intellij.codeInsight.template.impl.TemplateImpl;
11 import com.intellij.codeInsight.template.impl.TemplateSettings;
12 import com.intellij.testFramework.fixtures.CodeInsightTestUtil;
13 import com.intellij.util.containers.ContainerUtil;
14
15 public class LiveTemplateAutoPopupTest extends CompletionAutoPopupTestCase {
16   @Override
17   protected void setUp() throws Exception {
18     super.setUp();
19     LiveTemplateCompletionContributor.setShowTemplatesInTests(true, myFixture.getTestRootDisposable());
20   }
21
22   public void testDoNotShowTemplateWithoutShortcutInAutoPopup() {
23     myFixture.configureByText("a.java", "<caret>");
24     createTemplate("z").setShortcutChar(TemplateSettings.NONE_CHAR);
25     type("z");
26     assertNull(myFixture.getLookup());
27   }
28
29   public void testShowTemplateWithShortcutInAutoPopup() {
30     myFixture.configureByText("a.java", "<caret>");
31     createTemplate("z").setShortcutChar(TemplateSettings.TAB_CHAR);
32     type("z");
33     assertNotNull(myFixture.getLookup());
34   }
35
36   public void testNoPrematureLookupHidingWhenTemplateNameContainsDash() {
37     myFixture.configureByText("a.java", "class C { int aaaA; { <caret> }}");
38     createTemplate("aaa-bbb");
39     type("aaa");
40     assertOrderedEquals(myFixture.getLookupElementStrings(), "aaaA", "aaa-bbb");
41     type("-");
42     assertOrderedEquals(myFixture.getLookupElementStrings(), "aaa-bbb");
43
44     myFixture.configureByText("a.java", "class C { { <caret> }}");
45     type("aaa");
46     assertOrderedEquals(myFixture.getLookupElementStrings(), "aaa-bbb");
47     type("-");
48     assertOrderedEquals(myFixture.getLookupElementStrings(), "aaa-bbb");
49   }
50
51   private TemplateImpl createTemplate(String key) {
52     TemplateManager manager = TemplateManager.getInstance(getProject());
53     TemplateImpl template = (TemplateImpl)manager.createTemplate(key, "user", "");
54     TemplateContextType contextType = ContainerUtil.findInstance(TemplateContextType.EP_NAME.getExtensions(), JavaCodeContextType.class);
55     template.getTemplateContext().setEnabled(contextType, true);
56     CodeInsightTestUtil.addTemplate(template, myFixture.getTestRootDisposable());
57     return template;
58   }
59 }