9bf5e5a9ee89421f42b94fe2a42c5b1f1c46fae6
[idea/community.git] / idea-tests / src / 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.analysis.AnalysisScope;
35 import com.intellij.testFramework.IdeaTestUtil;
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.TestSourceBasedTestCase;
44 import junit.framework.Assert;
45
46 import javax.swing.*;
47
48 public class DependenciesPanelTest extends TestSourceBasedTestCase{
49   public void testDependencies(){
50     DependenciesPanel dependenciesPanel = null;
51     try {
52       final PsiDirectory psiDirectory = getPackageDirectory("com/package1");
53       Assert.assertNotNull(psiDirectory);
54       final PsiPackage psiPackage = JavaDirectoryService.getInstance().getPackage(psiDirectory);
55       Assert.assertNotNull(psiPackage);
56       final PsiClass[] classes = psiPackage.getClasses();
57       final PsiFile file = classes[0].getContainingFile();
58       final AnalysisScope scope = new AnalysisScope(file);
59       final DependenciesBuilder builder = new ForwardDependenciesBuilder(myProject, scope);
60       builder.analyze();
61       DependencyUISettings.getInstance().SCOPE_TYPE = PackagePatternProvider.PACKAGES;
62       dependenciesPanel = new DependenciesPanel(myProject, builder);
63       JTree leftTree = dependenciesPanel.getLeftTree();
64       IdeaTestUtil.assertTreeEqual(leftTree, "-Root\n" +
65                             " Library Classes\n" +
66                             " -Production Classes\n" +
67                             "  -" + myModule.getName() + "\n" +
68                             "   -com.package1\n" +
69                             "    [Class1.java]\n" +
70                                 " Test Classes\n", true);
71
72       JTree rightTree = dependenciesPanel.getRightTree();
73       IdeaTestUtil.assertTreeEqual(rightTree, "-Root\n" +
74                              " Library Classes\n" +
75                              " -Production Classes\n" +
76                              "  -" + myModule.getName() + "\n" +
77                              "   -com.package1\n" +
78                              "    Class2.java\n" +
79                              " Test Classes\n", true);
80     }
81     finally {
82       if (dependenciesPanel != null) {
83         Disposer.dispose(dependenciesPanel);
84       }
85     }
86   }
87
88   protected String getTestPath() {
89     return "dependencies";
90   }
91 }