diff options
author | Michael Valenta | 2007-04-13 16:25:58 +0000 |
---|---|---|
committer | Michael Valenta | 2007-04-13 16:25:58 +0000 |
commit | 7673d2acea9b5d0d8d630b382949b9acdef5ca10 (patch) | |
tree | 34bd4211e27050644d42657558f71139b407ae64 /tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/ui/EnablementTest.java | |
parent | bc763b7217e87a216f02c639167a3f0eef52b127 (diff) | |
download | eclipse.platform.team-7673d2acea9b5d0d8d630b382949b9acdef5ca10.tar.gz eclipse.platform.team-7673d2acea9b5d0d8d630b382949b9acdef5ca10.tar.xz eclipse.platform.team-7673d2acea9b5d0d8d630b382949b9acdef5ca10.zip |
Bug 173456 Convert the CVS action sets actions to the new menu support
Diffstat (limited to 'tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/ui/EnablementTest.java')
-rw-r--r-- | tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/ui/EnablementTest.java | 148 |
1 files changed, 148 insertions, 0 deletions
diff --git a/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/ui/EnablementTest.java b/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/ui/EnablementTest.java new file mode 100644 index 000000000..be33b1e83 --- /dev/null +++ b/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/ui/EnablementTest.java @@ -0,0 +1,148 @@ +package org.eclipse.team.tests.ccvs.ui; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.jface.action.Action; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.team.core.TeamException; +import org.eclipse.team.tests.ccvs.core.EclipseTest; +import org.eclipse.ui.IActionDelegate; + +public class EnablementTest extends EclipseTest { + + /** + * Constructor for CVSProviderTest + */ + public EnablementTest() { + super(); + } + + /** + * Constructor for CVSProviderTest + */ + public EnablementTest(String name) { + super(name); + } + + /** + * Create a test project for the given action delegate. The structure of + * this test project is used by the get resource methods to return resources + * of the proper type. + * + * @param actionDelegate + * @throws CoreException + * @throws TeamException + */ + protected IProject createTestProject(IActionDelegate actionDelegate) throws CoreException, TeamException { + String actionName = getName(actionDelegate); + return createProject(actionName, new String[] { "file.txt", "folder1/", "folder1/a.txt" }); + } + + protected List getManagedResources(IProject testProject, boolean includeFolders, boolean multiple) { + List result = new ArrayList(); + if (includeFolders) { + result.add(testProject.getFolder("folder1")); + } else { + result.add(testProject.getFile("folder1/a.txt")); + } + if (multiple) { + result.add(testProject.getFile("file.txt")); + } + return result; + } + + protected List getAddedResources(IProject testProject) throws CoreException, TeamException { + List result = new ArrayList(); + IFile file = testProject.getFile("added.txt"); + if (!file.exists()) { + addResources(testProject, new String[] {"added.txt"}, false); + } + result.add(file); + return result; + } + + protected List getIgnoredResources(IProject testProject) throws CoreException, TeamException { + List result = new ArrayList(); + IFile file = testProject.getFile("ignored.txt"); + if (!file.exists()) { + file.create(getRandomContents(), false, null); + } + result.add(file); + IFile ignoreFile = testProject.getFile(".cvsignore"); + InputStream contents = new ByteArrayInputStream("ignored.txt".getBytes()); + if (ignoreFile.exists()) { + ignoreFile.setContents(contents, false, false, null); + } else { + ignoreFile.create(contents, false, null); + } + return result; + } + + protected List getUnmanagedResources(IProject testProject) throws CoreException, TeamException { + List result = new ArrayList(); + IFile file = testProject.getFile("unmanaged.txt"); + if (!file.exists()) { + file.create(getRandomContents(), false, null); + } + result.add(file); + return result; + } + + /** + * Method getResourceWithUnmanagedParent. + * @param project + * @return Collection + */ + protected List getResourceWithUnmanagedParent(IProject project) throws CoreException { + List result = new ArrayList(); + IFolder folder = project.getFolder("newFolder"); + if(!folder.exists()) folder.create(false, true, null); + IFile file = folder.getFile("unmanaged.txt"); + if (!file.exists()) { + file.create(getRandomContents(), false, null); + } + result.add(file); + return result; + } + + protected List getOverlappingResources(IProject testProject, boolean includeFiles) { + List result = new ArrayList(); + result.add(testProject); + result.add(testProject.getFolder("folder1")); + if (includeFiles) { + result.add(testProject.getFile("folder1/a.txt")); + } + return result; + } + + protected ISelection asSelection(List resources) { + return new StructuredSelection(resources); + } + + protected String getName(IActionDelegate actionDelegate) { + return actionDelegate.getClass().getName(); + } + + /** + * Assert that the enablement for the given IActionDelegate and ISelection + * match that provided as expectedEnablement. + * + * @param actionDelegate + * @param selection + * @param expectedEnablement + */ + protected void assertEnablement(IActionDelegate actionDelegate, ISelection selection, boolean expectedEnablement) { + IAction action = new Action() {}; + actionDelegate.selectionChanged(action, selection); + assertEquals(getName(actionDelegate) + " enablement wrong!", expectedEnablement, action.isEnabled()); + } +} |