test++
[idea/community.git] / java / java-tests / testSrc / com / intellij / dependencies / DependenciesPanelTest.java
1 /*
2  * Copyright (c) 2004 JetBrains s.r.o. All  Rights Reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * -Redistributions of source code must retain the above copyright
9  *  notice, this list of conditions and the following disclaimer.
10  *
11  * -Redistribution in binary form must reproduct the above copyright
12  *  notice, this list of conditions and the following disclaimer in
13  *  the documentation and/or other materials provided with the distribution.
14  *
15  * Neither the name of JetBrains or IntelliJ IDEA
16  * may be used to endorse or promote products derived from this software
17  * without specific prior written permission.
18  *
19  * This software is provided "AS IS," without a warranty of any kind. ALL
20  * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
21  * ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
22  * OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. JETBRAINS AND ITS LICENSORS SHALL NOT
23  * BE LIABLE FOR ANY DAMAGES OR LIABILITIES SUFFERED BY LICENSEE AS A RESULT
24  * OF OR RELATING TO USE, MODIFICATION OR DISTRIBUTION OF THE SOFTWARE OR ITS
25  * DERIVATIVES. IN NO EVENT WILL JETBRAINS OR ITS LICENSORS BE LIABLE FOR ANY LOST
26  * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
27  * INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY
28  * OF LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE SOFTWARE, EVEN
29  * IF JETBRAINS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
30  *
31  */
32 package com.intellij.dependencies;
33
34 import com.intellij.JavaTestUtil;
35 import com.intellij.analysis.AnalysisScope;
36 import com.intellij.openapi.util.Disposer;
37 import com.intellij.packageDependencies.DependenciesBuilder;
38 import com.intellij.packageDependencies.DependencyUISettings;
39 import com.intellij.packageDependencies.ForwardDependenciesBuilder;
40 import com.intellij.packageDependencies.ui.DependenciesPanel;
41 import com.intellij.packageDependencies.ui.PackagePatternProvider;
42 import com.intellij.psi.*;
43 import com.intellij.testFramework.IdeaTestUtil;
44 import com.intellij.testFramework.TestSourceBasedTestCase;
45 import junit.framework.Assert;
46
47 import javax.swing.*;
48
49 public class DependenciesPanelTest extends TestSourceBasedTestCase{
50   public void testDependencies(){
51     DependenciesPanel dependenciesPanel = null;
52     try {
53       final PsiDirectory psiDirectory = getPackageDirectory("com/package1");
54       Assert.assertNotNull(psiDirectory);
55       final PsiPackage psiPackage = JavaDirectoryService.getInstance().getPackage(psiDirectory);
56       Assert.assertNotNull(psiPackage);
57       final PsiClass[] classes = psiPackage.getClasses();
58       final PsiFile file = classes[0].getContainingFile();
59       final AnalysisScope scope = new AnalysisScope(file);
60       final DependenciesBuilder builder = new ForwardDependenciesBuilder(myProject, scope);
61       builder.analyze();
62       DependencyUISettings.getInstance().SCOPE_TYPE = PackagePatternProvider.PACKAGES;
63       dependenciesPanel = new DependenciesPanel(myProject, builder);
64       JTree leftTree = dependenciesPanel.getLeftTree();
65       IdeaTestUtil.assertTreeEqual(leftTree, "-Root\n" +
66                             " Library Classes\n" +
67                             " -Production Classes\n" +
68                             "  -" + myModule.getName() + "\n" +
69                             "   -com.package1\n" +
70                             "    [Class1.java]\n" +
71                                 " Test Classes\n", true);
72
73       JTree rightTree = dependenciesPanel.getRightTree();
74       IdeaTestUtil.assertTreeEqual(rightTree, "-Root\n" +
75                              " Library Classes\n" +
76                              " -Production Classes\n" +
77                              "  -" + myModule.getName() + "\n" +
78                              "   -com.package1\n" +
79                              "    Class2.java\n" +
80                              " Test Classes\n", true);
81     }
82     finally {
83       if (dependenciesPanel != null) {
84         Disposer.dispose(dependenciesPanel);
85       }
86     }
87   }
88
89   protected String getTestPath() {
90     return "dependencies";
91   }
92
93   @Override
94   protected String getTestDataPath() {
95     return JavaTestUtil.getJavaTestDataPath();
96   }
97
98 }