diff options
12 files changed, 61 insertions, 406 deletions
diff --git a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/support/BugzillaFixture.java b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/support/BugzillaFixture.java index 35a96e120..26c0c130a 100644 --- a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/support/BugzillaFixture.java +++ b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/support/BugzillaFixture.java @@ -158,7 +158,7 @@ public class BugzillaFixture extends TestFixture { } public static File getFile(String filename) throws IOException { - return TestUtil.getFile("org.eclipse.mylyn.bugzilla.tests", BugzillaFixture.class, filename); + return TestUtil.getFile(BugzillaFixture.class, filename); } /** diff --git a/org.eclipse.mylyn.tasks.tests/META-INF/MANIFEST.MF b/org.eclipse.mylyn.tasks.tests/META-INF/MANIFEST.MF index b2af0ee17..554f036c1 100644 --- a/org.eclipse.mylyn.tasks.tests/META-INF/MANIFEST.MF +++ b/org.eclipse.mylyn.tasks.tests/META-INF/MANIFEST.MF @@ -28,6 +28,7 @@ Require-Bundle: org.eclipse.core.runtime, org.eclipse.ui.ide, org.eclipse.mylyn.tasks.bugs, org.eclipse.mylyn.commons.core, + org.eclipse.mylyn.commons.tests, org.eclipse.ui.browser, org.eclipse.core.expressions, org.eclipse.equinox.security diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskActivityTimingTest.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskActivityTimingTest.java index 62094fa7d..01d17a45c 100644 --- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskActivityTimingTest.java +++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskActivityTimingTest.java @@ -12,8 +12,6 @@ package org.eclipse.mylyn.tasks.tests; import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; @@ -21,8 +19,7 @@ import java.util.List; import junit.framework.TestCase; -import org.eclipse.core.runtime.Path; -import org.eclipse.mylyn.context.tests.support.FileTool; +import org.eclipse.mylyn.commons.tests.support.CommonTestUtil; import org.eclipse.mylyn.internal.context.core.ContextCorePlugin; import org.eclipse.mylyn.internal.context.core.InteractionContext; import org.eclipse.mylyn.internal.context.core.InteractionContextManager; @@ -75,17 +72,15 @@ public class TaskActivityTimingTest extends TestCase { } File backup = new File(contexts, ".activity.xml.zip"); - File good = FileTool.getFileInPlugin(TasksTestsPlugin.getDefault(), new Path( - "testdata/activityTests/.activity.xml.zip")); + File good = CommonTestUtil.getFile(this, "testdata/activityTests/.activity.xml.zip"); - copy(good, backup); + CommonTestUtil.copy(good, backup); File corrupt = new File(contexts, "activity.xml.zip"); - File corruptSource = FileTool.getFileInPlugin(TasksTestsPlugin.getDefault(), new Path( - "testdata/activityTests/activity.xml.zip")); + File corruptSource = CommonTestUtil.getFile(this, "testdata/activityTests/.activity.xml.zip"); - copy(corruptSource, corrupt); + CommonTestUtil.copy(corruptSource, corrupt); InteractionContextManager manager = ContextCorePlugin.getContextManager(); manager.loadActivityMetaContext(); @@ -101,10 +96,9 @@ public class TaskActivityTimingTest extends TestCase { } File backup = new File(contexts, ".activity.xml.zip"); - File good = FileTool.getFileInPlugin(TasksTestsPlugin.getDefault(), new Path( - "testdata/activityTests/.activity.xml.zip")); + File good = CommonTestUtil.getFile(this, "testdata/activityTests/.activity.xml.zip"); - copy(good, backup); + CommonTestUtil.copy(good, backup); InteractionContextManager manager = ContextCorePlugin.getContextManager(); manager.loadActivityMetaContext(); @@ -119,20 +113,6 @@ public class TaskActivityTimingTest extends TestCase { } - private void copy(File inFile, File outFile) throws Exception { - - FileOutputStream outStream = new FileOutputStream(outFile); - FileInputStream inStream = new FileInputStream(inFile); - - byte[] buffer = new byte[1024]; - while (inStream.read(buffer) != -1) { - outStream.write(buffer); - } - inStream.close(); - outStream.close(); - - } - public void testActivityWithNoTaskActive() { Calendar start = Calendar.getInstance(); Calendar end = Calendar.getInstance(); diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskDataExportTest.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskDataExportTest.java index a1b7fcccd..6aa414a6a 100644 --- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskDataExportTest.java +++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskDataExportTest.java @@ -18,7 +18,7 @@ import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.mylyn.commons.tests.support.CommonsTestUtil; +import org.eclipse.mylyn.commons.tests.support.CommonTestUtil; import org.eclipse.mylyn.context.tests.AbstractContextTest; import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin; import org.eclipse.mylyn.internal.tasks.ui.util.TaskDataExportOperation; @@ -57,7 +57,7 @@ public class TaskDataExportTest extends AbstractContextTest { // Create test export destination directory mylynFolder = new File(TasksUiPlugin.getDefault().getDataDirectory()); destinationDir = new File(mylynFolder.getParent(), "TestDir"); - CommonsTestUtil.deleteFolder(destinationDir); + CommonTestUtil.deleteFolder(destinationDir); destinationDir.mkdir(); // Create folder/file structure @@ -98,7 +98,7 @@ public class TaskDataExportTest extends AbstractContextTest { protected void tearDown() throws Exception { wizard.dispose(); wizardPage.dispose(); - CommonsTestUtil.deleteFolder(destinationDir); + CommonTestUtil.deleteFolder(destinationDir); // Create folder/file structure File tasklist = new File(mylynFolder, "tasks.xml.zip"); tasklist.delete(); @@ -107,9 +107,9 @@ public class TaskDataExportTest extends AbstractContextTest { File tasks = new File(mylynFolder, "tasksandstuff"); File tasksSubDir = new File(tasks, "sub"); File backup = new File(mylynFolder, "backup"); - CommonsTestUtil.deleteFolder(backup); - CommonsTestUtil.deleteFolder(tasksSubDir); - CommonsTestUtil.deleteFolder(tasks); + CommonTestUtil.deleteFolder(backup); + CommonTestUtil.deleteFolder(tasksSubDir); + CommonTestUtil.deleteFolder(tasks); super.tearDown(); } diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskListBackupManagerTest.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskListBackupManagerTest.java index 674c74704..ed119bf20 100644 --- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskListBackupManagerTest.java +++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskListBackupManagerTest.java @@ -15,7 +15,7 @@ import java.io.File; import junit.framework.TestCase; -import org.eclipse.mylyn.commons.tests.support.CommonsTestUtil; +import org.eclipse.mylyn.commons.tests.support.CommonTestUtil; import org.eclipse.mylyn.internal.tasks.core.AbstractTask; import org.eclipse.mylyn.internal.tasks.core.LocalTask; import org.eclipse.mylyn.internal.tasks.ui.TaskListBackupManager; @@ -33,7 +33,7 @@ public class TaskListBackupManagerTest extends TestCase { @Override protected void setUp() throws Exception { backupManager = TasksUiPlugin.getBackupManager(); - CommonsTestUtil.deleteFolder(new File(TasksUiPlugin.getDefault().getBackupFolderPath())); + CommonTestUtil.deleteFolder(new File(TasksUiPlugin.getDefault().getBackupFolderPath())); TaskTestUtil.resetTaskList(); } diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/ui/ContextPerspectiveManagerTest.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/ui/ContextPerspectiveManagerTest.java index d5cdb70c4..0d7f3cc8b 100644 --- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/ui/ContextPerspectiveManagerTest.java +++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/ui/ContextPerspectiveManagerTest.java @@ -13,7 +13,7 @@ package org.eclipse.mylyn.tasks.tests.ui; import junit.framework.TestCase; -import org.eclipse.mylyn.context.tests.support.TestUtil; +import org.eclipse.mylyn.context.tests.support.ContextTestUtil; import org.eclipse.mylyn.internal.context.ui.ContextUiPlugin; import org.eclipse.mylyn.internal.context.ui.IContextUiPreferenceContstants; import org.eclipse.mylyn.internal.tasks.core.TaskTask; @@ -35,7 +35,7 @@ public class ContextPerspectiveManagerTest extends TestCase { @Override protected void setUp() throws Exception { - TestUtil.triggerContextUiLazyStart(); + ContextTestUtil.triggerContextUiLazyStart(); TaskTestUtil.resetTaskListAndRepositories(); previousSetting = ContextUiPlugin.getDefault().getPreferenceStore().getBoolean( diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/ui/TaskListFilterTest.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/ui/TaskListFilterTest.java index 234da0a62..5cda5fa22 100644 --- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/ui/TaskListFilterTest.java +++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/ui/TaskListFilterTest.java @@ -21,7 +21,7 @@ import java.util.Set; import junit.framework.TestCase; import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.mylyn.context.tests.UiTestUtil; +import org.eclipse.mylyn.commons.tests.support.UiTestUtil; import org.eclipse.mylyn.internal.tasks.core.AbstractTask; import org.eclipse.mylyn.internal.tasks.core.LocalTask; import org.eclipse.mylyn.internal.tasks.core.TaskActivityUtil; diff --git a/org.eclipse.mylyn.tests.util/.classpath b/org.eclipse.mylyn.tests.util/.classpath index c9c6503f7..a915bf753 100644 --- a/org.eclipse.mylyn.tests.util/.classpath +++ b/org.eclipse.mylyn.tests.util/.classpath @@ -4,6 +4,7 @@ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"> <accessrules> <accessrule kind="accessible" pattern="**/internal/**"/> + <accessrule kind="accessible" pattern="**/tests/**"/> </accessrules> </classpathentry> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"> diff --git a/org.eclipse.mylyn.tests.util/META-INF/MANIFEST.MF b/org.eclipse.mylyn.tests.util/META-INF/MANIFEST.MF index fb7323477..b61dfd2bc 100644 --- a/org.eclipse.mylyn.tests.util/META-INF/MANIFEST.MF +++ b/org.eclipse.mylyn.tests.util/META-INF/MANIFEST.MF @@ -10,6 +10,7 @@ Require-Bundle: org.eclipse.core.resources, org.eclipse.ui, org.eclipse.mylyn.commons.core, org.eclipse.mylyn.commons.net, + org.eclipse.mylyn.commons.tests, org.eclipse.mylyn.tasks.core, org.eclipse.mylyn.tasks.ui Bundle-ClassPath: . diff --git a/org.eclipse.mylyn.tests.util/src/org/eclipse/mylyn/tests/util/FileUtil.java b/org.eclipse.mylyn.tests.util/src/org/eclipse/mylyn/tests/util/FileUtil.java deleted file mode 100644 index 84208ff67..000000000 --- a/org.eclipse.mylyn.tests.util/src/org/eclipse/mylyn/tests/util/FileUtil.java +++ /dev/null @@ -1,253 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.mylyn.tests.util; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.Reader; -import java.io.Writer; -import java.util.Enumeration; -import java.util.zip.ZipEntry; -import java.util.zip.ZipFile; - -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Plugin; - -public class FileUtil { - - private final static int MAX_RETRY = 5; - - /** - * A buffer. - */ - private static byte[] buffer = new byte[8192]; - - /** - * Unzips the given zip file to the given destination directory extracting only those entries the pass through the - * given filter. - * - * @param zipFile - * the zip file to unzip - * @param dstDir - * the destination directory - * @throws IOException - * in case of problem - */ - public static void unzip(ZipFile zipFile, File dstDir) throws IOException { - unzip(zipFile, dstDir, dstDir, 0); - } - - private static void unzip(ZipFile zipFile, File rootDstDir, File dstDir, int depth) throws IOException { - - Enumeration<? extends ZipEntry> entries = zipFile.entries(); - - try { - while (entries.hasMoreElements()) { - ZipEntry entry = entries.nextElement(); - if (entry.isDirectory()) { - continue; - } - String entryName = entry.getName(); - File file = new File(dstDir, changeSeparator(entryName, '/', File.separatorChar)); - file.getParentFile().mkdirs(); - InputStream src = null; - OutputStream dst = null; - try { - src = zipFile.getInputStream(entry); - dst = new FileOutputStream(file); - transferData(src, dst); - } finally { - if (dst != null) { - try { - dst.close(); - } catch (IOException e) { - // don't need to catch this - } - } - if (src != null) { - try { - src.close(); - } catch (IOException e) { - // don't need to catch this - } - } - } - } - } finally { - try { - zipFile.close(); - } catch (IOException e) { - // don't need to catch this - } - } - } - - /** - * Returns the given file path with its separator character changed from the given old separator to the given new - * separator. - * - * @param path - * a file path - * @param oldSeparator - * a path separator character - * @param newSeparator - * a path separator character - * @return the file path with its separator character changed from the given old separator to the given new - * separator - */ - public static String changeSeparator(String path, char oldSeparator, char newSeparator) { - return path.replace(oldSeparator, newSeparator); - } - - /** - * Copies all bytes in the given source file to the given destination file. - * - * @param source - * the given source file - * @param destination - * the given destination file - * @throws IOException - * in case of error - */ - public static void transferData(File source, File destination) throws IOException { - destination.getParentFile().mkdirs(); - InputStream is = null; - OutputStream os = null; - try { - is = new FileInputStream(source); - os = new FileOutputStream(destination); - transferData(is, os); - } finally { - if (os != null) { - try { - os.close(); - } catch (IOException e) { - // don't need to catch this - } - } - if (is != null) { - try { - is.close(); - } catch (IOException e) { - // don't need to catch this - } - } - } - } - - /** - * Copies all bytes in the given source stream to the given destination stream. Neither streams are closed. - * - * @param source - * the given source stream - * @param destination - * the given destination stream - * @throws IOException - * in case of error - */ - public static void transferData(InputStream source, OutputStream destination) throws IOException { - int bytesRead = 0; - while (bytesRead != -1) { - bytesRead = source.read(buffer, 0, buffer.length); - if (bytesRead != -1) { - destination.write(buffer, 0, bytesRead); - } - } - } - - /** - * Copies the given source file to the given destination file. - * - * @param src - * the given source file - * @param dst - * the given destination file - * @throws IOException - * in case of error - */ - public static void copy(File src, File dst) throws IOException { - if (src.isDirectory()) { - String[] srcChildren = src.list(); - for (int i = 0; i < srcChildren.length; ++i) { - File srcChild = new File(src, srcChildren[i]); - File dstChild = new File(dst, srcChildren[i]); - copy(srcChild, dstChild); - } - } else { - transferData(src, dst); - } - } - - public static File createTempFileInPlugin(Plugin plugin, IPath path) { - IPath stateLocation = plugin.getStateLocation(); - stateLocation = stateLocation.append(path); - return stateLocation.toFile(); - } - - public static StringBuffer read(String fileName) throws IOException { - return read(new FileReader(fileName)); - } - - public static StringBuffer read(Reader reader) throws IOException { - StringBuffer s = new StringBuffer(); - try { - char[] charBuffer = new char[8196]; - int chars = reader.read(charBuffer); - while (chars != -1) { - s.append(charBuffer, 0, chars); - chars = reader.read(charBuffer); - } - } finally { - try { - reader.close(); - } catch (IOException e) { - // don't need to catch this - } - } - return s; - } - - public static void write(String fileName, StringBuffer content) throws IOException { - Writer writer = new FileWriter(fileName); - try { - writer.write(content.toString()); - } finally { - try { - writer.close(); - } catch (IOException e) { - // don't need to catch this - } - } - } - - public static void delete(File file) { - if (file.exists()) { - for (int i = 0; i < MAX_RETRY; i++) { - if (file.delete()) { - i = MAX_RETRY; - } else { - try { - Thread.sleep(1000); // sleep a second - } catch (InterruptedException e) { - // don't need to catch this - } - } - } - } - } -} diff --git a/org.eclipse.mylyn.tests.util/src/org/eclipse/mylyn/tests/util/TestUtil.java b/org.eclipse.mylyn.tests.util/src/org/eclipse/mylyn/tests/util/TestUtil.java index 86d3f94f5..b0eb3d490 100644 --- a/org.eclipse.mylyn.tests.util/src/org/eclipse/mylyn/tests/util/TestUtil.java +++ b/org.eclipse.mylyn.tests.util/src/org/eclipse/mylyn/tests/util/TestUtil.java @@ -14,15 +14,11 @@ package org.eclipse.mylyn.tests.util; import java.io.File; import java.io.FileInputStream; import java.io.IOException; -import java.net.URL; import java.util.Properties; -import junit.framework.Assert; import junit.framework.AssertionFailedError; -import org.eclipse.core.runtime.FileLocator; -import org.eclipse.core.runtime.Platform; -import org.osgi.framework.Bundle; +import org.eclipse.mylyn.commons.tests.support.CommonTestUtil; /** * @author Steffen Pingel @@ -66,7 +62,7 @@ public class TestUtil { File file; String filename = System.getProperty(KEY_CREDENTIALS_FILE); if (filename == null) { - file = getFile("org.eclipse.mylyn.context.tests", TestUtil.class, "credentials.properties"); + file = getFile(TestUtil.class, "credentials.properties"); if (!file.exists()) { // lookup may have reverted to this plug-in, try to lookup file in org.eclipse.context.tests plug-in File path = new File(file.getParentFile().getParentFile(), "org.eclipse.mylyn.context.tests"); @@ -118,38 +114,42 @@ public class TestUtil { return new Credentials(username, password); } - public static File getFile(String bundleId, Class<?> clazz, String filename) throws IOException { - Bundle bundle = Platform.getBundle(bundleId); - if (bundle != null) { - URL localURL = FileLocator.toFileURL(bundle.getEntry(filename)); - filename = localURL.getFile(); - } else { - URL localURL = clazz.getResource(""); - String path = localURL.getFile(); - int i = path.indexOf("!"); - if (i != -1) { - int j = path.lastIndexOf(File.separatorChar, i); - if (j != -1) { - path = path.substring(0, j) + File.separator; - } else { - Assert.fail("Unable to determine location for '" + filename + "' at '" + path + "'"); - } - // class file is nested in jar, use jar path as base - if (path.startsWith("file:")) { - path = path.substring(5); - } - } else { - // create relative path to base of class file location - String[] tokens = clazz.getName().split("\\."); - for (int j = 0; j < tokens.length - 1; j++) { - path += ".." + File.separator; - } - if (path.contains("bin" + File.separator)) { - path += ".." + File.separator; - } - } - filename = path + filename.replaceAll("/", File.separator); - } - return new File(filename).getCanonicalFile(); + public static File getFile(Object source, String filename) throws IOException { + return CommonTestUtil.getFile(source, filename); } + +// public static File getFile(String bundleId, Class<?> clazz, String filename) throws IOException { +// Bundle bundle = Platform.getBundle(bundleId); +// if (bundle != null) { +// URL localURL = FileLocator.toFileURL(bundle.getEntry(filename)); +// filename = localURL.getFile(); +// } else { +// URL localURL = clazz.getResource(""); +// String path = localURL.getFile(); +// int i = path.indexOf("!"); +// if (i != -1) { +// int j = path.lastIndexOf(File.separatorChar, i); +// if (j != -1) { +// path = path.substring(0, j) + File.separator; +// } else { +// Assert.fail("Unable to determine location for '" + filename + "' at '" + path + "'"); +// } +// // class file is nested in jar, use jar path as base +// if (path.startsWith("file:")) { +// path = path.substring(5); +// } +// } else { +// // create relative path to base of class file location +// String[] tokens = clazz.getName().split("\\."); +// for (int j = 0; j < tokens.length - 1; j++) { +// path += ".." + File.separator; +// } +// if (path.contains("bin" + File.separator)) { +// path += ".." + File.separator; +// } +// } +// filename = path + filename.replaceAll("/", File.separator); +// } +// return new File(filename).getCanonicalFile(); +// } } diff --git a/org.eclipse.mylyn.tests.util/src/org/eclipse/mylyn/tests/util/UiTestUtil.java b/org.eclipse.mylyn.tests.util/src/org/eclipse/mylyn/tests/util/UiTestUtil.java deleted file mode 100644 index f58068409..000000000 --- a/org.eclipse.mylyn.tests.util/src/org/eclipse/mylyn/tests/util/UiTestUtil.java +++ /dev/null @@ -1,75 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2009 Tasktop Technologies and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Tasktop Technologies - initial API and implementation - *******************************************************************************/ - -package org.eclipse.mylyn.tests.util; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import org.eclipse.swt.widgets.Tree; -import org.eclipse.swt.widgets.TreeItem; -import org.eclipse.ui.IViewPart; -import org.eclipse.ui.IViewReference; -import org.eclipse.ui.PartInitException; -import org.eclipse.ui.PlatformUI; - -/** - * @author Mik Kersten - */ -public class UiTestUtil { - - public static int countItemsInTree(Tree tree) { - List<TreeItem> collectedItems = new ArrayList<TreeItem>(); - collectTreeItemsInView(tree.getItems(), collectedItems); - return collectedItems.size(); - } - - public static void collectTreeItemsInView(TreeItem[] items, List<TreeItem> collectedItems) { - if (items.length > 0) { - for (TreeItem childItem : Arrays.asList(items)) { - collectedItems.add(childItem); - collectTreeItemsInView(childItem.getItems(), collectedItems); - } - } - } - - public static List<Object> getAllData(Tree tree) { - List<TreeItem> items = new ArrayList<TreeItem>(); - collectTreeItemsInView(tree.getItems(), items); - List<Object> dataList = new ArrayList<Object>(); - for (TreeItem item : items) { - dataList.add(item.getData()); - } - return dataList; - } - - /** - * Ensures that the editor area is visible. - */ - public static void closeWelcomeView() { - IViewReference[] views = PlatformUI.getWorkbench() - .getActiveWorkbenchWindow() - .getActivePage() - .getViewReferences(); - for (IViewReference view : views) { - if ("org.eclipse.ui.internal.introview".equals(view.getId())) { - PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().hideView(view); - PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().resetPerspective(); - return; - } - } - } - - public static IViewPart openView(String id) throws PartInitException { - return PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(id); - } -} |