Skip to content

Commit 65500ca

Browse files
committed
Replace UITestCase with test rule in commands and datatransfer UI tests
1 parent 2bc4843 commit 65500ca

File tree

9 files changed

+137
-125
lines changed

9 files changed

+137
-125
lines changed

tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/adaptable/WorkingSetTestCase.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
package org.eclipse.ui.tests.adaptable;
1515

1616
import static org.eclipse.ui.PlatformUI.getWorkbench;
17+
import static org.junit.Assert.assertEquals;
18+
import static org.junit.Assert.assertFalse;
19+
import static org.junit.Assert.assertTrue;
1720

1821
import org.eclipse.core.internal.propertytester.ResourceMappingPropertyTester;
1922
import org.eclipse.core.resources.IProject;
@@ -27,20 +30,21 @@
2730
import org.eclipse.ui.IWorkingSet;
2831
import org.eclipse.ui.IWorkingSetManager;
2932
import org.eclipse.ui.model.IWorkbenchAdapter;
30-
import org.eclipse.ui.tests.harness.util.UITestCase;
33+
import org.eclipse.ui.tests.harness.util.CloseTestWindowsRule;
34+
import org.junit.Rule;
3135
import org.junit.Test;
32-
import org.junit.runner.RunWith;
33-
import org.junit.runners.JUnit4;
36+
import org.junit.rules.TestName;
3437

3538
/**
3639
* Test that Working Sets adapt to resource mappings
3740
*/
38-
@RunWith(JUnit4.class)
39-
public class WorkingSetTestCase extends UITestCase {
41+
public class WorkingSetTestCase {
4042

41-
public WorkingSetTestCase() {
42-
super(WorkingSetTestCase.class.getSimpleName());
43-
}
43+
@Rule
44+
public final CloseTestWindowsRule closeTestWindowsRule = new CloseTestWindowsRule();
45+
46+
@Rule
47+
public final TestName testName = new TestName();
4448

4549
private ResourceMapping getResourceMapping(IWorkingSet set) {
4650
return set.getAdapter(ResourceMapping.class);
@@ -67,7 +71,7 @@ private void assertMatches(ResourceMapping mapping, IResource[] resources) throw
6771
}
6872

6973
private IProject createProject(String name) throws CoreException {
70-
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(getName() + name);
74+
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(testName.getMethodName() + name);
7175
project.create(null);
7276
project.open(IResource.NONE, null);
7377
return project;

tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/commands/CommandCallbackTest.java

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package org.eclipse.ui.tests.commands;
1717

1818
import static org.eclipse.ui.tests.harness.util.UITestUtil.openTestWindow;
19+
import static org.junit.Assert.assertEquals;
1920
import static org.junit.Assert.assertThrows;
2021

2122
import java.util.HashMap;
@@ -40,16 +41,19 @@
4041
import org.eclipse.ui.menus.UIElement;
4142
import org.eclipse.ui.services.IServiceLocator;
4243
import org.eclipse.ui.services.IServiceScopes;
43-
import org.eclipse.ui.tests.harness.util.UITestCase;
44+
import org.eclipse.ui.tests.harness.util.CloseTestWindowsRule;
45+
import org.junit.After;
46+
import org.junit.Before;
47+
import org.junit.Rule;
4448
import org.junit.Test;
45-
import org.junit.runner.RunWith;
46-
import org.junit.runners.JUnit4;
4749

4850
/**
4951
* @since 3.3
5052
*/
51-
@RunWith(JUnit4.class)
52-
public class CommandCallbackTest extends UITestCase {
53+
public class CommandCallbackTest {
54+
55+
@Rule
56+
public final CloseTestWindowsRule closeTestWindowsRule = new CloseTestWindowsRule();
5357

5458
private static final String HOST_PARAM_ID = "host";
5559
private static final String PROT_PARAM_ID = "protocol";
@@ -67,13 +71,8 @@ public class CommandCallbackTest extends UITestCase {
6771
private CallbackHandler cmd1Handler;
6872
private CallbackHandler cmd2Handler;
6973

70-
public CommandCallbackTest() {
71-
super(CommandCallbackTest.class.getSimpleName());
72-
}
73-
74-
@Override
75-
protected void doSetUp() throws Exception {
76-
super.doSetUp();
74+
@Before
75+
public final void setUp() throws Exception {
7776
workbench = PlatformUI.getWorkbench();
7877
commandService = workbench.getService(ICommandService.class);
7978
cmd1 = commandService.getCommand(CMD1_ID);
@@ -85,8 +84,8 @@ protected void doSetUp() throws Exception {
8584
cmd2Activation = handlerService.activateHandler(CMD2_ID, cmd2Handler);
8685
}
8786

88-
@Override
89-
protected void doTearDown() throws Exception {
87+
@After
88+
public final void tearDown() throws Exception {
9089
if (cmd1Activation != null) {
9190
handlerService.deactivateHandler(cmd1Activation);
9291
cmd1Activation = null;
@@ -96,7 +95,6 @@ protected void doTearDown() throws Exception {
9695
cmd2Activation = null;
9796
}
9897
workbench = null;
99-
super.doTearDown();
10098
}
10199

102100
private static class CallbackHandler extends AbstractHandler implements

tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/commands/HandlerActivationTest.java

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
package org.eclipse.ui.tests.commands;
1616

1717
import static org.eclipse.ui.tests.harness.util.UITestUtil.openTestWindow;
18+
import static org.junit.Assert.assertEquals;
19+
import static org.junit.Assert.assertFalse;
1820
import static org.junit.Assert.assertThrows;
21+
import static org.junit.Assert.assertTrue;
1922

2023
import java.util.HashMap;
2124
import java.util.Map;
@@ -45,19 +48,23 @@
4548
import org.eclipse.ui.handlers.IHandlerActivation;
4649
import org.eclipse.ui.handlers.IHandlerService;
4750
import org.eclipse.ui.services.IServiceLocator;
48-
import org.eclipse.ui.tests.harness.util.UITestCase;
51+
import org.eclipse.ui.tests.harness.util.CloseTestWindowsRule;
4952
import org.eclipse.ui.views.contentoutline.ContentOutline;
53+
import org.junit.After;
54+
import org.junit.Before;
55+
import org.junit.Rule;
5056
import org.junit.Test;
51-
import org.junit.runner.RunWith;
52-
import org.junit.runners.JUnit4;
5357

5458
/**
5559
* Tests various aspects of command state.
5660
*
5761
* @since 3.2
5862
*/
59-
@RunWith(JUnit4.class)
60-
public class HandlerActivationTest extends UITestCase {
63+
public class HandlerActivationTest {
64+
65+
@Rule
66+
public final CloseTestWindowsRule closeTestWindowsRule = new CloseTestWindowsRule();
67+
6168
static class ActTestHandler extends AbstractHandler {
6269
public String contextId;
6370

@@ -146,7 +153,6 @@ public void setEnabled(Object evaluationContext) {
146153
* Constructor for <code>HandlerActivationTest</code>.
147154
*/
148155
public HandlerActivationTest() {
149-
super(HandlerActivationTest.class.getSimpleName());
150156
services = PlatformUI.getWorkbench();
151157
contextService = services
152158
.getService(IContextService.class);
@@ -179,8 +185,8 @@ private void createHandlerActivation(String contextId, String handlerId,
179185
makeHandler(handlerId, contextId, expression);
180186
}
181187

182-
@Override
183-
protected void doSetUp() throws Exception {
188+
@Before
189+
public final void setUp() throws Exception {
184190
for (final String[] contextInfo : CREATE_CONTEXTS) {
185191
final Context context = contextService.getContext(contextInfo[0]);
186192
if (!context.isDefined()) {
@@ -197,13 +203,12 @@ protected void doSetUp() throws Exception {
197203

198204
}
199205

200-
@Override
201-
protected void doTearDown() throws Exception {
206+
@After
207+
public final void tearDown() throws Exception {
202208
handlerService.deactivateHandlers(testHandlerActivations.values());
203209
testHandlerActivations.clear();
204210
contextService.deactivateContexts(testContextActivations.values());
205211
testContextActivations.clear();
206-
super.doTearDown();
207212
}
208213

209214
private void doTestForBreak() throws ExecutionException,

tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/datatransfer/ExportArchiveFileOperationTest.java

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
*******************************************************************************/
1414
package org.eclipse.ui.tests.datatransfer;
1515

16+
import static org.junit.Assert.assertFalse;
17+
import static org.junit.Assert.assertTrue;
18+
1619
import java.io.ByteArrayInputStream;
1720
import java.io.File;
1821
import java.io.FileInputStream;
@@ -41,15 +44,21 @@
4144
import org.eclipse.ui.internal.wizards.datatransfer.TarEntry;
4245
import org.eclipse.ui.internal.wizards.datatransfer.TarException;
4346
import org.eclipse.ui.internal.wizards.datatransfer.TarFile;
47+
import org.eclipse.ui.tests.harness.util.CloseTestWindowsRule;
4448
import org.eclipse.ui.tests.harness.util.FileUtil;
45-
import org.eclipse.ui.tests.harness.util.UITestCase;
49+
import org.junit.After;
50+
import org.junit.Before;
51+
import org.junit.Rule;
4652
import org.junit.Test;
47-
import org.junit.runner.RunWith;
48-
import org.junit.runners.JUnit4;
53+
import org.junit.rules.TestName;
54+
55+
public class ExportArchiveFileOperationTest implements IOverwriteQuery {
4956

50-
@RunWith(JUnit4.class)
51-
public class ExportArchiveFileOperationTest extends UITestCase implements
52-
IOverwriteQuery {
57+
@Rule
58+
public final CloseTestWindowsRule closeTestWindowsRule = new CloseTestWindowsRule();
59+
60+
@Rule
61+
public final TestName testName = new TestName();
5362

5463
private static final String FILE_NAME = "test";
5564
private static final String ZIP_FILE_EXT = "zip";
@@ -67,10 +76,6 @@ public class ExportArchiveFileOperationTest extends UITestCase implements
6776
private boolean flattenPaths = false;
6877
private boolean excludeProjectPath = false;
6978

70-
public ExportArchiveFileOperationTest() {
71-
super(ExportArchiveFileOperationTest.class.getSimpleName());
72-
}
73-
7479
@Override
7580
public String queryOverwrite(String pathString) {
7681
return "";
@@ -320,10 +325,9 @@ public void testExportTarCreateSelectedDirectoriesCompressed() throws Exception
320325

321326
}
322327

323-
@Override
324-
protected void doSetUp() throws Exception {
325-
super.doSetUp();
326-
project = FileUtil.createProject("Export" + getName());
328+
@Before
329+
public final void setUp() throws Exception {
330+
project = FileUtil.createProject("Export" + testName.getMethodName());
327331
File destination =
328332
new File(FileSystemHelper.getRandomLocation(FileSystemHelper.getTempDir())
329333
.toOSString());
@@ -334,9 +338,8 @@ protected void doSetUp() throws Exception {
334338
excludeProjectPath = false;
335339
}
336340

337-
@Override
338-
protected void doTearDown() throws Exception {
339-
super.doTearDown();
341+
@After
342+
public final void tearDown() throws Exception {
340343
// delete exported data
341344
File root = new File(localDirectory);
342345
if (root.exists()){

tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/datatransfer/ExportFileSystemOperationTest.java

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
package org.eclipse.ui.tests.datatransfer;
1515

1616
import static org.eclipse.ui.tests.harness.util.UITestUtil.openTestWindow;
17+
import static org.junit.Assert.assertEquals;
18+
import static org.junit.Assert.assertTrue;
1719

1820
import java.io.ByteArrayInputStream;
1921
import java.io.File;
@@ -38,16 +40,22 @@
3840
import org.eclipse.core.tests.harness.FileSystemHelper;
3941
import org.eclipse.ui.dialogs.IOverwriteQuery;
4042
import org.eclipse.ui.internal.wizards.datatransfer.FileSystemExportOperation;
43+
import org.eclipse.ui.tests.harness.util.CloseTestWindowsRule;
4144
import org.eclipse.ui.tests.harness.util.FileUtil;
42-
import org.eclipse.ui.tests.harness.util.UITestCase;
4345
import org.eclipse.ui.tests.internal.VirtualTestFileSystem;
46+
import org.junit.After;
47+
import org.junit.Before;
48+
import org.junit.Rule;
4449
import org.junit.Test;
45-
import org.junit.runner.RunWith;
46-
import org.junit.runners.JUnit4;
50+
import org.junit.rules.TestName;
4751

48-
@RunWith(JUnit4.class)
49-
public class ExportFileSystemOperationTest extends UITestCase implements
50-
IOverwriteQuery {
52+
public class ExportFileSystemOperationTest implements IOverwriteQuery {
53+
54+
@Rule
55+
public final CloseTestWindowsRule closeTestWindowsRule = new CloseTestWindowsRule();
56+
57+
@Rule
58+
public final TestName testName = new TestName();
5159

5260
private static final String[] directoryNames = { "dir1", "dir2" };
5361

@@ -57,19 +65,14 @@ public class ExportFileSystemOperationTest extends UITestCase implements
5765

5866
private IProject project;
5967

60-
public ExportFileSystemOperationTest() {
61-
super(ExportFileSystemOperationTest.class.getSimpleName());
62-
}
63-
6468
@Override
6569
public String queryOverwrite(String pathString) {
6670
return "";
6771
}
6872

69-
@Override
70-
protected void doSetUp() throws Exception {
71-
super.doSetUp();
72-
project = FileUtil.createProject("Export" + getName());
73+
@Before
74+
public final void setUp() throws Exception {
75+
project = FileUtil.createProject("Export" + testName.getMethodName());
7376
File destination =
7477
new File(FileSystemHelper.getRandomLocation(FileSystemHelper.getTempDir())
7578
.toOSString());
@@ -90,9 +93,8 @@ private void setUpData() throws CoreException {
9093
}
9194
}
9295

93-
@Override
94-
protected void doTearDown() throws Exception {
95-
super.doTearDown();
96+
@After
97+
public final void tearDown() throws Exception {
9698
// delete exported data
9799
File root = new File(localDirectory);
98100
if (root.exists()){

tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/datatransfer/ImportExistingArchiveProjectFilterTest.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616

1717
import static org.eclipse.ui.PlatformUI.getWorkbench;
1818
import static org.eclipse.ui.tests.harness.util.UITestUtil.processEvents;
19+
import static org.junit.Assert.assertEquals;
20+
import static org.junit.Assert.assertFalse;
21+
import static org.junit.Assert.assertNotNull;
22+
import static org.junit.Assert.assertTrue;
1923

2024
import java.io.IOException;
2125
import java.net.URL;
@@ -50,25 +54,23 @@
5054
import org.eclipse.ui.internal.wizards.datatransfer.WizardProjectsImportPage.ProjectRecord;
5155
import org.eclipse.ui.navigator.resources.ProjectExplorer;
5256
import org.eclipse.ui.tests.TestPlugin;
57+
import org.eclipse.ui.tests.harness.util.CloseTestWindowsRule;
5358
import org.eclipse.ui.tests.harness.util.EmptyPerspective;
5459
import org.eclipse.ui.tests.harness.util.FileUtil;
55-
import org.eclipse.ui.tests.harness.util.UITestCase;
60+
import org.junit.After;
61+
import org.junit.Rule;
5662
import org.junit.Test;
57-
import org.junit.runner.RunWith;
58-
import org.junit.runners.JUnit4;
5963

60-
@RunWith(JUnit4.class)
61-
public class ImportExistingArchiveProjectFilterTest extends UITestCase {
64+
public class ImportExistingArchiveProjectFilterTest {
65+
66+
@Rule
67+
public final CloseTestWindowsRule closeTestWindowsRule = new CloseTestWindowsRule();
6268

6369
private static final String DATA_PATH_PREFIX = "data/org.eclipse.datatransferArchives/";
6470
private static final String ARCHIVE_JAVA_PROJECT = "ExcludeFilter_Import";
6571

66-
public ImportExistingArchiveProjectFilterTest() {
67-
super(ImportExistingArchiveProjectFilterTest.class.getName());
68-
}
69-
70-
@Override
71-
protected void doTearDown() throws Exception {
72+
@After
73+
public final void tearDown() throws Exception {
7274
if (dialog != null) {
7375
dialog.close();
7476
dialog = null;
@@ -78,7 +80,6 @@ protected void doTearDown() throws Exception {
7880
for (int i = projects.length - 1; i >= 0; i--) {
7981
FileUtil.deleteProject(projects[i]);
8082
}
81-
super.doTearDown();
8283
}
8384

8485
// Testcase for GitHub Issue

0 commit comments

Comments
 (0)