Source Code Cross Referenced for TreeContentProviderTest.java in  » IDE-Eclipse » jdt » org » eclipse » jdt » ui » tests » search » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Eclipse » jdt » org.eclipse.jdt.ui.tests.search 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2000, 2005 IBM Corporation and others.
003:         * All rights reserved. This program and the accompanying materials
004:         * are made available under the terms of the Eclipse Public License v1.0
005:         * which accompanies this distribution, and is available at
006:         * http://www.eclipse.org/legal/epl-v10.html
007:         *
008:         * Contributors:
009:         *     IBM Corporation - initial API and implementation
010:         *******************************************************************************/package org.eclipse.jdt.ui.tests.search;
011:
012:        import java.util.List;
013:        import junit.framework.Test;
014:        import junit.framework.TestCase;
015:        import junit.framework.TestSuite;
016:        import org.eclipse.jdt.core.IJavaProject;
017:        import org.eclipse.jdt.core.IMethod;
018:        import org.eclipse.jdt.core.IPackageFragment;
019:        import org.eclipse.jdt.core.IPackageFragmentRoot;
020:        import org.eclipse.jdt.core.IType;
021:        import org.eclipse.jdt.internal.ui.search.JavaSearchResult;
022:        import org.eclipse.jdt.internal.ui.search.JavaSearchResultPage;
023:        import org.eclipse.jdt.internal.ui.search.LevelTreeContentProvider;
024:        import org.eclipse.jface.viewers.AbstractTreeViewer;
025:        import org.eclipse.jface.viewers.StructuredViewer;
026:        import org.eclipse.search.ui.text.AbstractTextSearchResult;
027:        import org.eclipse.search.ui.text.Match;
028:        import org.eclipse.swt.events.TreeListener;
029:        import org.eclipse.swt.widgets.Control;
030:        import org.eclipse.swt.widgets.Item;
031:        import org.eclipse.swt.widgets.Widget;
032:
033:        /**
034:         */
035:        public class TreeContentProviderTest extends TestCase {
036:            private LevelTreeContentProvider fProvider;
037:            private JavaSearchResult fResult;
038:
039:            public static Test allTests() {
040:                return new JUnitSourceSetup(new TestSuite(
041:                        TreeContentProviderTest.class));
042:            }
043:
044:            public static Test suite() {
045:                return allTests();
046:            }
047:
048:            static class MockTreeViewer extends AbstractTreeViewer {
049:
050:                protected void addTreeListener(Control control,
051:                        TreeListener listener) {
052:                    // ignore
053:                }
054:
055:                protected void doUpdateItem(Item item, Object element) {
056:                    // ignore
057:                }
058:
059:                protected Item[] getChildren(Widget widget) {
060:                    return new Item[0];
061:                }
062:
063:                protected boolean getExpanded(Item item) {
064:                    return false;
065:                }
066:
067:                protected int getItemCount(Control control) {
068:                    return 0;
069:                }
070:
071:                protected int getItemCount(Item item) {
072:                    return 0;
073:                }
074:
075:                protected Item[] getItems(Item item) {
076:                    return new Item[0];
077:                }
078:
079:                protected Item getParentItem(Item item) {
080:                    return null;
081:                }
082:
083:                protected Item[] getSelection(Control control) {
084:                    return new Item[0];
085:                }
086:
087:                protected Item newItem(Widget parent, int style, int index) {
088:                    return null;
089:                }
090:
091:                protected void removeAll(Control control) {
092:                    // ignore
093:                }
094:
095:                protected void setExpanded(Item item, boolean expand) {
096:                    // ignore
097:                }
098:
099:                protected void setSelection(List items) {
100:                    // ignore
101:                }
102:
103:                protected void showItem(Item item) {
104:                    // ignore
105:                }
106:
107:                public Control getControl() {
108:                    return null;
109:                }
110:            }
111:
112:            public TreeContentProviderTest(String name) {
113:                super (name);
114:                // TODO Auto-generated constructor stub
115:            }
116:
117:            protected void setUp() throws Exception {
118:                super .setUp();
119:                fProvider = new LevelTreeContentProvider(
120:                        new JavaSearchResultPage() {
121:                            StructuredViewer fViewer = new MockTreeViewer();
122:
123:                            protected StructuredViewer getViewer() {
124:                                return fViewer;
125:                            }
126:
127:                            public AbstractTextSearchResult getInput() {
128:                                return fResult;
129:                            }
130:                        }, LevelTreeContentProvider.LEVEL_PACKAGE);
131:                fResult = new JavaSearchResult(null);
132:                fProvider.inputChanged(null, null, fResult);
133:            }
134:
135:            protected void tearDown() throws Exception {
136:                super .tearDown();
137:            }
138:
139:            public void testSimpleAdd() throws Exception {
140:                IMethod method = SearchTestHelper.getMethod(
141:                        "junit.framework.TestCase", "getName", new String[0]);
142:                addMatch(new Match(method, 0, 1));
143:                IType type = SearchTestHelper
144:                        .getType("junit.framework.TestCase");
145:                IPackageFragment pkg = type.getPackageFragment();
146:                IJavaProject project = pkg.getJavaProject();
147:                IPackageFragmentRoot root = (IPackageFragmentRoot) pkg
148:                        .getParent();
149:
150:                fProvider.setLevel(LevelTreeContentProvider.LEVEL_TYPE);
151:                assertEquals(type, fProvider.getParent(method));
152:                assertEquals(fProvider.getParent(type), null);
153:
154:                fProvider.setLevel(LevelTreeContentProvider.LEVEL_PACKAGE);
155:                assertEquals(type, fProvider.getParent(method));
156:                assertEquals(fProvider.getParent(type), pkg);
157:                assertEquals(fProvider.getParent(pkg), null);
158:
159:                fProvider.setLevel(LevelTreeContentProvider.LEVEL_PROJECT);
160:                assertEquals(type, fProvider.getParent(method));
161:                assertEquals(fProvider.getParent(type), pkg);
162:                assertEquals(fProvider.getParent(pkg), root);
163:                assertEquals(fProvider.getParent(root), project);
164:                assertEquals(fProvider.getParent(project), null);
165:            }
166:
167:            public void testRemove() throws Exception {
168:                IMethod method = SearchTestHelper.getMethod(
169:                        "junit.framework.TestCase", "getName", new String[0]);
170:                IType type = method.getDeclaringType();
171:                IPackageFragment pkg = type.getPackageFragment();
172:                Match match = new Match(method, 0, 1);
173:                addMatch(match);
174:                Match match2 = new Match(method, 0, 1);
175:                addMatch(match2);
176:                removeMatch(match);
177:                assertEquals(1, fProvider.getChildren(type).length);
178:                assertEquals(1, fProvider.getChildren(pkg).length);
179:                assertEquals(1, fProvider.getElements(fResult).length);
180:
181:                removeMatch(match2);
182:
183:                assertEquals(0, fProvider.getChildren(type).length);
184:                assertEquals(0, fProvider.getChildren(pkg).length);
185:                assertEquals(0, fProvider.getElements(fResult).length);
186:            }
187:
188:            public void testRemoveParentFirst() throws Exception {
189:                IMethod method = SearchTestHelper.getMethod(
190:                        "junit.framework.TestCase", "getName", new String[0]);
191:                IType type = method.getDeclaringType();
192:                IPackageFragment pkg = type.getPackageFragment();
193:
194:                Match match1 = new Match(method, 0, 1);
195:                addMatch(match1);
196:
197:                Match match2 = new Match(type, 0, 1);
198:                addMatch(match2);
199:
200:                removeMatch(match2);
201:
202:                assertEquals(1, fProvider.getChildren(type).length);
203:                assertEquals(1, fProvider.getChildren(pkg).length);
204:                assertEquals(1, fProvider.getElements(fResult).length);
205:
206:                removeMatch(match1);
207:                assertEquals(0, fProvider.getChildren(type).length);
208:                assertEquals(0, fProvider.getChildren(pkg).length);
209:                assertEquals(0, fProvider.getElements(fResult).length);
210:            }
211:
212:            public void testRemoveParentLast() throws Exception {
213:                IMethod method = SearchTestHelper.getMethod(
214:                        "junit.framework.TestCase", "getName", new String[0]);
215:                IType type = method.getDeclaringType();
216:                IPackageFragment pkg = type.getPackageFragment();
217:
218:                Match match1 = new Match(method, 0, 1);
219:                addMatch(match1);
220:
221:                Match match2 = new Match(type, 0, 1);
222:                addMatch(match2);
223:
224:                removeMatch(match1);
225:
226:                assertEquals(0, fProvider.getChildren(type).length);
227:                assertEquals(1, fProvider.getChildren(pkg).length);
228:                assertEquals(1, fProvider.getElements(fResult).length);
229:
230:                removeMatch(match2);
231:
232:                assertEquals(0, fProvider.getChildren(type).length);
233:                assertEquals(0, fProvider.getChildren(pkg).length);
234:                assertEquals(0, fProvider.getElements(fResult).length);
235:            }
236:
237:            private void removeMatch(Match match) {
238:                fResult.removeMatch(match);
239:                fProvider.elementsChanged(new Object[] { match.getElement() });
240:            }
241:
242:            private void addMatch(Match match) {
243:                fResult.addMatch(match);
244:                fProvider.elementsChanged(new Object[] { match.getElement() });
245:            }
246:
247:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.