Updated version of the "comparingReference" sample plugin.
[idea/community.git] / samples / comparingReferences / testSource / testPlugin / TestThisPlugin.java
1 package testPlugin;
2
3
4 import com.intellij.codeInsight.daemon.impl.HighlightInfo;
5 import com.intellij.codeInsight.intention.IntentionAction;
6 import com.intellij.codeInspection.ComparingReferencesInspection;
7 import com.intellij.testFramework.builders.JavaModuleFixtureBuilder;
8 import com.intellij.testFramework.fixtures.*;
9 import junit.framework.Assert;
10 import com.intellij.openapi.ui.Messages;
11 import org.junit.After;
12 import org.junit.Before;
13 import org.junit.Test;
14
15 import java.util.List;
16
17 public class TestThisPlugin {
18
19     protected CodeInsightTestFixture myFixture;
20     // Specify path to your test data directory
21     // e.g.  final String dataPath = "c:\\users\\john.doe\\idea\\community\\samples\\ComparingReferences/testData";
22     final String dataPath = "c:\\users\\John.Doe\\idea\\community\\samples\\comparingReferences/testData";
23
24
25     @Before
26
27     public void setUp() throws Exception {
28
29         final IdeaTestFixtureFactory fixtureFactory = IdeaTestFixtureFactory.getFixtureFactory();
30         final TestFixtureBuilder<IdeaProjectTestFixture> testFixtureBuilder = fixtureFactory.createFixtureBuilder();
31         myFixture = JavaTestFixtureFactory.getFixtureFactory().createCodeInsightFixture(testFixtureBuilder.getFixture());
32         myFixture.setTestDataPath(dataPath);
33         final JavaModuleFixtureBuilder builder = testFixtureBuilder.addModule(JavaModuleFixtureBuilder.class);
34
35         builder.addContentRoot(myFixture.getTempDirPath()).addSourceRoot("");
36         builder.setMockJdkLevel(JavaModuleFixtureBuilder.MockJdkLevel.jdk15);
37         myFixture.setUp();
38
39
40     }
41
42     @After
43     public void tearDown() throws Exception {
44         myFixture.tearDown();
45         myFixture = null;
46     }
47
48     protected void doTest(String testName, String hint) throws Throwable {
49         myFixture.configureByFile(testName + ".java");
50         myFixture.enableInspections(ComparingReferencesInspection.class);
51         List<HighlightInfo> highlightInfos = myFixture.doHighlighting();
52         Assert.assertTrue(!highlightInfos.isEmpty());
53
54         final IntentionAction action = myFixture.findSingleIntention(hint);
55
56         Assert.assertNotNull(action);
57         myFixture.launchAction(action);
58         myFixture.checkResultByFile(testName + ".after.java");
59
60     }
61
62     @Test
63     // Test the "==" case
64     public void test() throws Throwable {
65         doTest("before", "Use equals()");
66
67     }
68      @Test
69      // Test the "!=" case
70     public void test1() throws Throwable {
71         doTest("before1", "Use equals()");
72
73     }
74
75 }