Skip to content

Commit 40c9740

Browse files
committed
Migrate save participant tests to JUnit 5 #903
This migrates the SaveManagerTest to JUnit 5, using the SessionTestExtension with the CustomSessionWorkspace. It consists of the following changes: - the individual test suites in the subclasses of SaveManagerTest were unused and are thus removed - further unused functionality in those subclasses is removed - JUnit 4 dependencies are replaced with JUnit 5 dependencies in the plug-in org.eclipse.core.tests.resources.saveparticipant - the plug-in org.eclipse.core.tests.resources.saveparticipant is declared as a test plug-in and tests are enabled for the Maven build - the SaveParticipantTest, which executed the SaveManagerTest from the central org.eclipse.core.tests.resources plug-in, is removed as it was not part of any test suite (and thus not executed) anyway Contributes to #903
1 parent e47558e commit 40c9740

File tree

8 files changed

+184
-328
lines changed

8 files changed

+184
-328
lines changed

resources/tests/org.eclipse.core.tests.resources.saveparticipant/META-INF/MANIFEST.MF

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ Export-Package: org.eclipse.core.tests.resources.saveparticipant
99
Require-Bundle: org.eclipse.core.resources,
1010
org.eclipse.core.tests.harness,
1111
org.eclipse.core.runtime,
12-
org.junit,
1312
org.eclipse.core.tests.resources,
1413
org.eclipse.core.tests.resources.saveparticipant1,
1514
org.eclipse.core.tests.resources.saveparticipant2,
1615
org.eclipse.core.tests.resources.saveparticipant3,
1716
org.eclipse.core.filesystem
17+
Import-Package: org.junit.jupiter.api,
18+
org.junit.jupiter.api.extension
1819
Bundle-RequiredExecutionEnvironment: JavaSE-17
1920
Bundle-ActivationPolicy: lazy

resources/tests/org.eclipse.core.tests.resources.saveparticipant/build.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,5 @@ bin.includes = .,\
1919
about.html
2020
src.includes = about.html
2121

22+
pom.model.packaging = eclipse-test-plugin
23+
pom.model.property.testClass = org.eclipse.core.tests.resources.saveparticipant.SaveManagerTest

resources/tests/org.eclipse.core.tests.resources.saveparticipant/pom.xml

Lines changed: 0 additions & 29 deletions
This file was deleted.

resources/tests/org.eclipse.core.tests.resources.saveparticipant/src/org/eclipse/core/tests/resources/saveparticipant/SaveManager1Test.java

Lines changed: 96 additions & 160 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,37 @@
1313
*******************************************************************************/
1414
package org.eclipse.core.tests.resources.saveparticipant;
1515

16-
import junit.framework.Test;
17-
import junit.framework.TestSuite;
18-
19-
import org.eclipse.core.resources.*;
20-
import org.eclipse.core.runtime.*;
16+
import static org.eclipse.core.resources.ResourcesPlugin.getWorkspace;
17+
import static org.eclipse.core.tests.resources.ResourceTestUtil.assertExistsInFileSystem;
18+
import static org.eclipse.core.tests.resources.ResourceTestUtil.assertExistsInWorkspace;
19+
import static org.eclipse.core.tests.resources.ResourceTestUtil.buildResources;
20+
import static org.eclipse.core.tests.resources.ResourceTestUtil.createInWorkspace;
21+
import static org.eclipse.core.tests.resources.ResourceTestUtil.createRandomContentsStream;
22+
import static org.eclipse.core.tests.resources.ResourceTestUtil.createTestMonitor;
23+
import static org.eclipse.core.tests.resources.ResourceTestUtil.setAutoBuilding;
24+
import static org.eclipse.core.tests.resources.ResourceTestUtil.waitForBuild;
25+
import static org.junit.jupiter.api.Assertions.assertFalse;
26+
import static org.junit.jupiter.api.Assertions.assertNotNull;
27+
import static org.junit.jupiter.api.Assertions.assertTrue;
28+
29+
import org.eclipse.core.resources.ICommand;
30+
import org.eclipse.core.resources.IFile;
31+
import org.eclipse.core.resources.IProject;
32+
import org.eclipse.core.resources.IProjectDescription;
33+
import org.eclipse.core.resources.IResource;
34+
import org.eclipse.core.resources.IResourceDelta;
35+
import org.eclipse.core.resources.ISaveContext;
36+
import org.eclipse.core.resources.IncrementalProjectBuilder;
37+
import org.eclipse.core.runtime.CoreException;
38+
import org.eclipse.core.runtime.IStatus;
39+
import org.eclipse.core.runtime.Platform;
2140
import org.eclipse.core.tests.internal.builders.DeltaVerifierBuilder;
2241
import org.eclipse.core.tests.resources.regression.SimpleBuilder;
2342
import org.eclipse.core.tests.resources.saveparticipant1.SaveParticipant1Plugin;
2443
import org.eclipse.core.tests.resources.saveparticipant2.SaveParticipant2Plugin;
2544
import org.eclipse.core.tests.resources.saveparticipant3.SaveParticipant3Plugin;
2645
import org.osgi.framework.Bundle;
2746
import org.osgi.framework.BundleException;
28-
import static org.eclipse.core.resources.ResourcesPlugin.getWorkspace;
29-
import static org.eclipse.core.tests.resources.ResourceTestUtil.assertExistsInFileSystem;
30-
import static org.eclipse.core.tests.resources.ResourceTestUtil.assertExistsInWorkspace;
31-
import static org.eclipse.core.tests.resources.ResourceTestUtil.createTestMonitor;
32-
import static org.eclipse.core.tests.resources.ResourceTestUtil.buildResources;
33-
import static org.eclipse.core.tests.resources.ResourceTestUtil.waitForBuild;
34-
import static org.eclipse.core.tests.resources.ResourceTestUtil.*;
3547

3648
/**
3749
* This class needs to be used with SaveManager2Test. Basically this
@@ -42,124 +54,108 @@
4254
* @see SaveManager2Test
4355
* @see SaveManager3Test
4456
*/
45-
public class SaveManager1Test extends SaveManagerTest {
57+
public class SaveManager1Test {
58+
4659
/**
47-
* Need a zero argument constructor to satisfy the test harness.
48-
* This constructor should not do any real work nor should it be
49-
* called by user code.
60+
* Create some resources and save the workspace.
5061
*/
51-
public SaveManager1Test() {
52-
}
62+
public void testCreateMyProject() throws CoreException {
63+
IProject project = getWorkspace().getRoot().getProject(SaveManagerTest.PROJECT_1);
64+
project.create(null);
65+
project.open(null);
66+
assertTrue(project.exists());
67+
assertTrue(project.isOpen());
5368

54-
public SaveManager1Test(String name) {
55-
super(name);
56-
}
69+
project.close(null);
70+
assertTrue(project.exists());
71+
assertFalse(project.isOpen());
72+
73+
// when closing and opening the project again, it should still exist
74+
project = getWorkspace().getRoot().getProject(SaveManagerTest.PROJECT_1);
75+
project.open(null);
76+
assertTrue(project.exists());
77+
assertTrue(project.isOpen());
5778

58-
// copy and paste into the scrapbook
59-
public static void doIt() throws Exception {
60-
String[] testIds = {"saveparticipant.SaveManager1Test", "saveparticipant.SaveManager2Test", "saveparticipant.SaveManager3Test"};
61-
for (int i = 0; i < testIds.length; i++) {
62-
Process p = Runtime.getRuntime().exec(new String[] {"java", "org.eclipse.core.tests.harness.launcher.Main", "-test", testIds[i], "-data", "c:/temp/save_manager", (i < (testIds.length - 1) ? "-nocleanup" : "")});
63-
p.waitFor();
64-
java.io.InputStream input = p.getInputStream();
65-
int c;
66-
while ((c = input.read()) != -1)
67-
System.out.print((char) c);
68-
input.close();
69-
input = p.getErrorStream();
70-
while ((c = input.read()) != -1)
71-
System.out.print((char) c);
72-
input.close();
73-
}
74-
System.exit(-1);
79+
// create some children
80+
IResource[] resources = buildResources(project, SaveManagerTest.defineHierarchy(SaveManagerTest.PROJECT_1));
81+
createInWorkspace(resources);
82+
assertExistsInFileSystem(resources);
83+
assertExistsInWorkspace(resources);
84+
85+
project.close(null);
86+
project.open(null);
87+
assertExistsInFileSystem(resources);
88+
assertExistsInWorkspace(resources);
7589
}
7690

77-
public static Test suite() {
78-
// we do not add the whole class because the order is important
79-
TestSuite suite = new TestSuite();
80-
suite.addTest(new SaveManager1Test("saveWorkspace"));
81-
suite.addTest(new SaveManager1Test("testCreateMyProject"));
82-
suite.addTest(new SaveManager1Test("testCreateProject2"));
83-
suite.addTest(new SaveManager1Test("testAddSaveParticipant"));
84-
suite.addTest(new SaveManager1Test("testBuilder"));
85-
suite.addTest(new SaveManager1Test("saveWorkspace"));
86-
suite.addTest(new SaveManager1Test("testPostSave"));
87-
return suite;
91+
/**
92+
* Create another project and leave it closed for next session.
93+
*/
94+
public void testCreateProject2() throws CoreException {
95+
IProject project = getWorkspace().getRoot().getProject(SaveManagerTest.PROJECT_2);
96+
project.create(null);
97+
project.open(null);
98+
assertTrue(project.exists());
99+
assertTrue(project.isOpen());
100+
101+
// create some children
102+
IResource[] resources = buildResources(project, SaveManagerTest.defineHierarchy(SaveManagerTest.PROJECT_2));
103+
createInWorkspace(resources);
104+
assertExistsInFileSystem(resources);
105+
assertExistsInWorkspace(resources);
106+
107+
// add a builder to this project
108+
IProjectDescription description = project.getDescription();
109+
ICommand command = description.newCommand();
110+
command.setBuilderName(SimpleBuilder.BUILDER_ID);
111+
description.setBuildSpec(new ICommand[] { command });
112+
project.setDescription(description, null);
113+
project.build(IncrementalProjectBuilder.FULL_BUILD, null);
114+
115+
project.close(null);
116+
assertTrue(project.exists());
117+
assertFalse(project.isOpen());
88118
}
89119

90120
public void testAddSaveParticipant() throws Exception {
91121
// get plugin
92-
Bundle bundle = Platform.getBundle(PI_SAVE_PARTICIPANT_1);
93-
assertTrue("0.1", bundle != null);
122+
Bundle bundle = Platform.getBundle(SaveManagerTest.PI_SAVE_PARTICIPANT_1);
123+
assertNotNull(bundle);
94124
bundle.start();
95125
SaveParticipant1Plugin plugin1 = SaveParticipant1Plugin.getInstance();
96126

97127
// prepare plugin to the save operation
98128
plugin1.resetDeltaVerifier();
99129
IStatus status;
100130
status = plugin1.registerAsSaveParticipant();
101-
assertTrue("Registering save participant failed with message: " + status.getMessage(), status.isOK());
131+
assertTrue(status.isOK(), "Registering save participant failed with message: " + status.getMessage());
102132
plugin1.setExpectedSaveKind(ISaveContext.FULL_SAVE);
103133

104134
// SaveParticipant2Plugin
105-
bundle = Platform.getBundle(PI_SAVE_PARTICIPANT_2);
106-
assertTrue("5.1", bundle != null);
135+
bundle = Platform.getBundle(SaveManagerTest.PI_SAVE_PARTICIPANT_2);
136+
assertNotNull(bundle);
107137
bundle.start();
108138
SaveParticipant2Plugin plugin2 = SaveParticipant2Plugin.getInstance();
109139

110140
// prepare plugin to the save operation
111141
plugin2.getDeltaVerifier().reset();
112142
status = plugin2.registerAsSaveParticipant();
113-
assertTrue("Registering save participant failed with message: " + status.getMessage(), status.isOK());
143+
assertTrue(status.isOK(), "Registering save participant failed with message: " + status.getMessage());
114144
plugin1.setExpectedSaveKind(ISaveContext.FULL_SAVE);
115145

116146
// SaveParticipant3Plugin
117-
bundle = Platform.getBundle(PI_SAVE_PARTICIPANT_3);
118-
assertTrue("7.1", bundle != null);
147+
bundle = Platform.getBundle(SaveManagerTest.PI_SAVE_PARTICIPANT_3);
148+
assertNotNull(bundle);
119149
bundle.start();
120150
SaveParticipant3Plugin plugin3 = SaveParticipant3Plugin.getInstance();
121151

122152
status = plugin3.registerAsSaveParticipant();
123-
assertTrue("Registering save participant failed with message: " + status.getMessage(), status.isOK());
124-
}
125-
126-
/**
127-
* Create another project and leave it closed for next session.
128-
*/
129-
public void testAnotherProject() throws CoreException {
130-
IProject project = getWorkspace().getRoot().getProject(PROJECT_1);
131-
project.create(null);
132-
project.open(null);
133-
assertTrue("0.1", project.exists());
134-
assertTrue("0.2", project.isOpen());
135-
136-
project.close(null);
137-
assertTrue("1.1", project.exists());
138-
assertTrue("1.2", !project.isOpen());
139-
140-
// when closing and opening the project again, it should still exist
141-
project = getWorkspace().getRoot().getProject(PROJECT_1);
142-
project.open(null);
143-
assertTrue("2.1", project.exists());
144-
assertTrue("2.2", project.isOpen());
145-
146-
// create some children
147-
IResource[] resources = buildResources(project, defineHierarchy(PROJECT_1));
148-
createInWorkspace(resources);
149-
assertExistsInFileSystem(resources);
150-
assertExistsInWorkspace(resources);
151-
152-
project.close(null);
153-
project.open(null);
154-
assertExistsInFileSystem(resources);
155-
assertExistsInWorkspace(resources);
156-
157-
getWorkspace().save(true, null);
153+
assertTrue(status.isOK(), "Registering save participant failed with message: " + status.getMessage());
158154
}
159155

160156
public void testBuilder() throws CoreException {
161-
IProject project = getWorkspace().getRoot().getProject(PROJECT_1);
162-
assertTrue("0.0", project.isAccessible());
157+
IProject project = getWorkspace().getRoot().getProject(SaveManagerTest.PROJECT_1);
158+
assertTrue(project.isAccessible());
163159

164160
setAutoBuilding(true);
165161
// Create and set a build spec for the project
@@ -180,82 +176,22 @@ public void testBuilder() throws CoreException {
180176
verifier.addExpectedChange(added, project, IResourceDelta.ADDED, 0);
181177
added.create(createRandomContentsStream(), true, null);
182178
waitForBuild();
183-
assertTrue("3.2", verifier.wasAutoBuild());
184-
assertTrue("3.3", verifier.isDeltaValid());
179+
assertTrue(verifier.wasAutoBuild());
180+
assertTrue(verifier.isDeltaValid());
185181
// remove the file because we don't want it to affect any other delta in the test
186182
added.delete(true, false, null);
187183
}
188184

189-
/**
190-
* Create some resources and save the workspace.
191-
*/
192-
public void testCreateMyProject() throws CoreException {
193-
IProject project = getWorkspace().getRoot().getProject(PROJECT_1);
194-
project.create(null);
195-
project.open(null);
196-
assertTrue("0.1", project.exists());
197-
assertTrue("0.2", project.isOpen());
198-
199-
project.close(null);
200-
assertTrue("1.1", project.exists());
201-
assertTrue("1.2", !project.isOpen());
202-
203-
// when closing and opening the project again, it should still exist
204-
project = getWorkspace().getRoot().getProject(PROJECT_1);
205-
project.open(null);
206-
assertTrue("2.1", project.exists());
207-
assertTrue("2.2", project.isOpen());
208-
209-
// create some children
210-
IResource[] resources = buildResources(project, defineHierarchy(PROJECT_1));
211-
createInWorkspace(resources);
212-
assertExistsInFileSystem(resources);
213-
assertExistsInWorkspace(resources);
214-
215-
project.close(null);
216-
project.open(null);
217-
assertExistsInFileSystem(resources);
218-
assertExistsInWorkspace(resources);
219-
}
220-
221-
/**
222-
* Create another project and leave it closed for next session.
223-
*/
224-
public void testCreateProject2() throws CoreException {
225-
IProject project = getWorkspace().getRoot().getProject(PROJECT_2);
226-
project.create(null);
227-
project.open(null);
228-
assertTrue("0.1", project.exists());
229-
assertTrue("0.2", project.isOpen());
230-
231-
// create some children
232-
IResource[] resources = buildResources(project, defineHierarchy(PROJECT_2));
233-
createInWorkspace(resources);
234-
assertExistsInFileSystem(resources);
235-
assertExistsInWorkspace(resources);
236-
237-
// add a builder to this project
238-
IProjectDescription description = project.getDescription();
239-
ICommand command = description.newCommand();
240-
command.setBuilderName(SimpleBuilder.BUILDER_ID);
241-
description.setBuildSpec(new ICommand[] {command});
242-
project.setDescription(description, null);
243-
project.build(IncrementalProjectBuilder.FULL_BUILD, null);
244-
245-
project.close(null);
246-
assertTrue("5.1", project.exists());
247-
assertTrue("5.2", !project.isOpen());
248-
}
249-
250185
public void testPostSave() throws BundleException {
251186
// get plugin
252-
Bundle bundle = Platform.getBundle(PI_SAVE_PARTICIPANT_1);
253-
assertTrue("0.1", bundle != null);
187+
Bundle bundle = Platform.getBundle(SaveManagerTest.PI_SAVE_PARTICIPANT_1);
188+
assertNotNull(bundle);
254189
bundle.start();
255190
SaveParticipant1Plugin plugin = SaveParticipant1Plugin.getInstance();
256191

257192
// look at the plugin save lifecycle
258193
IStatus status = plugin.getSaveLifecycleLog();
259-
assertTrue("Getting lifecycle log failed with message: " + status.getMessage(), status.isOK());
194+
assertTrue(status.isOK(), "Getting lifecycle log failed with message: " + status.getMessage());
260195
}
196+
261197
}

0 commit comments

Comments
 (0)