Skip to content

Commit 70607f3

Browse files
committed
Migrate resources regression tests to JUnit 5
Migrates the tests in org.eclipse.core.tests.resources.regresison to JUnit 5. - Exchange JUnit test annotations - Replace JUnit 4 WorkspaceTestRule with JUnit 5 WorkspaceResetExtension - Replace JUnit 4 assertions with JUnit 5 assertions - Replace resource cleanup via WorkspaceTestRule with usage of temp directories or explicit cleanups Contributes to #903
1 parent a4eb5f3 commit 70607f3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+416
-495
lines changed

resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_006708.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,13 @@
2323
import org.eclipse.core.resources.IWorkspaceRoot;
2424
import org.eclipse.core.resources.ResourcesPlugin;
2525
import org.eclipse.core.runtime.CoreException;
26-
import org.eclipse.core.tests.resources.WorkspaceTestRule;
27-
import org.junit.Rule;
28-
import org.junit.Test;
26+
import org.eclipse.core.tests.resources.util.WorkspaceResetExtension;
27+
import org.junit.jupiter.api.Test;
28+
import org.junit.jupiter.api.extension.ExtendWith;
2929

30+
@ExtendWith(WorkspaceResetExtension.class)
3031
public class Bug_006708 {
3132

32-
@Rule
33-
public WorkspaceTestRule workspaceRule = new WorkspaceTestRule();
34-
3533
@Test
3634
public void testBug() throws CoreException {
3735
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();

resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_025457.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
import static org.eclipse.core.tests.resources.ResourceTestUtil.createRandomString;
2121
import static org.eclipse.core.tests.resources.ResourceTestUtil.createTestMonitor;
2222
import static org.eclipse.core.tests.resources.ResourceTestUtil.isReadOnlySupported;
23-
import static org.junit.Assert.assertThrows;
2423
import static org.junit.Assume.assumeTrue;
2524
import static org.junit.jupiter.api.Assertions.assertEquals;
25+
import static org.junit.jupiter.api.Assertions.assertThrows;
2626

2727
import java.io.IOException;
2828
import java.io.InputStream;
@@ -32,9 +32,9 @@
3232
import org.eclipse.core.resources.IResource;
3333
import org.eclipse.core.runtime.CoreException;
3434
import org.eclipse.core.runtime.Platform.OS;
35-
import org.eclipse.core.tests.resources.WorkspaceTestRule;
36-
import org.junit.Rule;
37-
import org.junit.Test;
35+
import org.eclipse.core.tests.resources.util.WorkspaceResetExtension;
36+
import org.junit.jupiter.api.Test;
37+
import org.junit.jupiter.api.extension.ExtendWith;
3838

3939
/**
4040
* Tests regression of bug 25457. In this case, attempting to move a project
@@ -44,11 +44,9 @@
4444
* Note: this is similar to Bug_32076, which deals with failure to move in
4545
* the non case-change scenario.
4646
*/
47+
@ExtendWith(WorkspaceResetExtension.class)
4748
public class Bug_025457 {
4849

49-
@Rule
50-
public WorkspaceTestRule workspaceRule = new WorkspaceTestRule();
51-
5250
@Test
5351
public void testFile() throws Exception {
5452
assumeTrue("only relevant on Windows", OS.isWindows());

resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_026294.java

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
import static org.eclipse.core.tests.resources.ResourceTestUtil.createUniqueString;
2626
import static org.eclipse.core.tests.resources.ResourceTestUtil.isReadOnlySupported;
2727
import static org.eclipse.core.tests.resources.ResourceTestUtil.setReadOnly;
28-
import static org.junit.Assert.assertThrows;
2928
import static org.junit.Assume.assumeTrue;
29+
import static org.junit.jupiter.api.Assertions.assertThrows;
3030

3131
import java.io.InputStream;
3232
import java.util.function.Predicate;
@@ -38,15 +38,16 @@
3838
import org.eclipse.core.runtime.CoreException;
3939
import org.eclipse.core.runtime.IPath;
4040
import org.eclipse.core.runtime.Platform.OS;
41-
import org.eclipse.core.tests.resources.WorkspaceTestRule;
42-
import org.junit.Rule;
43-
import org.junit.Test;
41+
import org.eclipse.core.tests.resources.util.WorkspaceResetExtension;
42+
import org.junit.jupiter.api.Test;
43+
import org.junit.jupiter.api.extension.ExtendWith;
4444

4545
/**
4646
* A parent container (projects and folders) would become out-of-sync if any of
4747
* its children could not be deleted for some reason. These platform-
4848
* specific test cases ensure that it does not happen.
4949
*/
50+
@ExtendWith(WorkspaceResetExtension.class)
5051
public class Bug_026294 {
5152

5253
private static final Predicate<IResource> isSynchronizedDepthInfinite = resource -> resource
@@ -55,9 +56,6 @@ public class Bug_026294 {
5556
private static final Predicate<IResource> isSynchronizedDepthZero = resource -> resource
5657
.isSynchronized(IResource.DEPTH_ZERO);
5758

58-
@Rule
59-
public WorkspaceTestRule workspaceRule = new WorkspaceTestRule();
60-
6159
/**
6260
* Tries to delete an open project containing an unremovable file.
6361
* Works only for Windows.
@@ -76,7 +74,6 @@ public void testDeleteOpenProjectWindows() throws Exception {
7674

7775
createInWorkspace(new IResource[] { file1, file2, file3 });
7876
IPath projectRoot = project.getLocation();
79-
workspaceRule.deleteOnTearDown(projectRoot);
8077

8178
assertExistsInFileSystem(file1);
8279
assertExistsInFileSystem(file2);
@@ -145,7 +142,6 @@ public void testDeleteOpenProjectLinux() throws CoreException {
145142

146143
createInWorkspace(new IResource[] { file1, file2 });
147144
IPath projectRoot = project.getLocation();
148-
workspaceRule.deleteOnTearDown(projectRoot);
149145

150146
try {
151147
// marks folder as read-only so its files cannot be deleted on Linux
@@ -195,7 +191,6 @@ public void testDeleteClosedProjectWindows() throws Exception {
195191

196192
createInWorkspace(new IResource[] { file1, file2, file3 });
197193
IPath projectRoot = project.getLocation();
198-
workspaceRule.deleteOnTearDown(projectRoot);
199194

200195
// opens a file so it cannot be removed on Windows
201196
try (InputStream input = file1.getContents()) {
@@ -229,10 +224,8 @@ public void testDeleteClosedProjectLinux() throws CoreException {
229224
IFile file1 = folder.getFile("file1.txt");
230225
IFile file2 = project.getFile("file2.txt");
231226
IFile projectFile = project.getFile(IPath.fromOSString(".project"));
232-
233227
createInWorkspace(new IResource[] { file1, file2 });
234228
IPath projectRoot = project.getLocation();
235-
workspaceRule.deleteOnTearDown(projectRoot);
236229

237230
try {
238231
// marks folder as read-only so its files cannot be removed on Linux
@@ -273,10 +266,7 @@ public void testDeleteFolderWindows() throws Exception {
273266
IFolder folder = project.getFolder("a_folder");
274267
IFile file1 = folder.getFile("file1.txt");
275268
IFile file3 = folder.getFile("file3.txt");
276-
277269
createInWorkspace(new IResource[] { file1, file3 });
278-
IPath projectRoot = project.getLocation();
279-
workspaceRule.deleteOnTearDown(projectRoot);
280270

281271
// opens a file so it cannot be removed on Windows
282272
try (InputStream input = file1.getContents()) {
@@ -309,10 +299,7 @@ public void testDeleteFolderLinux() throws CoreException {
309299
IFolder subFolder = folder.getFolder("sub-folder");
310300
IFile file1 = subFolder.getFile("file1.txt");
311301
IFile file3 = folder.getFile("file3.txt");
312-
313302
createInWorkspace(new IResource[] { file1, file3 });
314-
IPath projectRoot = project.getLocation();
315-
workspaceRule.deleteOnTearDown(projectRoot);
316303

317304
try {
318305
// marks sub-folder as read-only so its files cannot be removed on Linux

resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_027271.java

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,38 +15,35 @@
1515

1616
import static org.assertj.core.api.Assertions.assertThat;
1717
import static org.eclipse.core.resources.ResourcesPlugin.getWorkspace;
18-
import static org.junit.Assert.assertFalse;
1918
import static org.junit.Assume.assumeTrue;
19+
import static org.junit.jupiter.api.Assertions.assertFalse;
2020

2121
import org.eclipse.core.resources.IPathVariableManager;
2222
import org.eclipse.core.resources.ResourcesPlugin;
2323
import org.eclipse.core.runtime.IPath;
2424
import org.eclipse.core.runtime.Platform.OS;
2525
import org.eclipse.core.runtime.Preferences;
26-
import org.eclipse.core.tests.resources.WorkspaceTestRule;
27-
import org.junit.After;
28-
import org.junit.Before;
29-
import org.junit.Rule;
30-
import org.junit.Test;
26+
import org.eclipse.core.tests.resources.util.WorkspaceResetExtension;
27+
import org.junit.jupiter.api.AfterEach;
28+
import org.junit.jupiter.api.BeforeEach;
29+
import org.junit.jupiter.api.Test;
30+
import org.junit.jupiter.api.extension.ExtendWith;
3131

3232
/**
3333
* Tests how changes in the underlying preference store may affect the path
3434
* variable manager.
3535
*/
36-
36+
@ExtendWith(WorkspaceResetExtension.class)
3737
public class Bug_027271 {
3838

39-
@Rule
40-
public WorkspaceTestRule workspaceRule = new WorkspaceTestRule();
41-
4239
static final String VARIABLE_PREFIX = "pathvariable."; //$NON-NLS-1$
4340

44-
@Before
41+
@BeforeEach
4542
public void setUp() {
4643
clearPathVariablesProperties();
4744
}
4845

49-
@After
46+
@AfterEach
5047
public void tearDown() {
5148
clearPathVariablesProperties();
5249
}

resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_028981.java

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
import static org.eclipse.core.resources.ResourcesPlugin.getWorkspace;
1919
import static org.eclipse.core.tests.resources.ResourceTestUtil.createInWorkspace;
2020
import static org.eclipse.core.tests.resources.ResourceTestUtil.createRandomString;
21-
import static org.junit.Assert.assertThrows;
22-
import static org.junit.Assert.assertTrue;
21+
import static org.junit.jupiter.api.Assertions.assertThrows;
22+
import static org.junit.jupiter.api.Assertions.assertTrue;
2323

2424
import org.eclipse.core.resources.IContainer;
2525
import org.eclipse.core.resources.IFile;
@@ -31,19 +31,16 @@
3131
import org.eclipse.core.runtime.CoreException;
3232
import org.eclipse.core.runtime.QualifiedName;
3333
import org.eclipse.core.tests.resources.ResourceVisitorVerifier;
34-
import org.eclipse.core.tests.resources.WorkspaceTestRule;
35-
import org.junit.Rule;
36-
import org.junit.Test;
34+
import org.eclipse.core.tests.resources.util.WorkspaceResetExtension;
35+
import org.junit.jupiter.api.Test;
36+
import org.junit.jupiter.api.extension.ExtendWith;
3737

3838
/**
3939
* Resource#accept doesn't obey member flags for the traversal entry point.
4040
*/
41-
41+
@ExtendWith(WorkspaceResetExtension.class)
4242
public class Bug_028981 {
4343

44-
@Rule
45-
public WorkspaceTestRule workspaceRule = new WorkspaceTestRule();
46-
4744
@Test
4845
public void testBug() throws CoreException {
4946
final QualifiedName partner = new QualifiedName("org.eclipse.core.tests.resources", "myTarget");
@@ -77,25 +74,25 @@ public void testBug() throws CoreException {
7774
verifier.addExpected(settings);
7875
verifier.addExpected(prefs);
7976
project.accept(verifier);
80-
assertTrue(verifier.getMessage(), verifier.isValid());
77+
assertTrue(verifier.isValid(), verifier.getMessage());
8178

8279
verifier.reset();
8380
assertThrows(CoreException.class, () -> phantomFile.accept(verifier));
8481

8582
verifier.reset();
8683
verifier.addExpected(phantomFile);
8784
phantomFile.accept(verifier, IResource.DEPTH_INFINITE, IContainer.INCLUDE_PHANTOMS);
88-
assertTrue(verifier.getMessage(), verifier.isValid());
85+
assertTrue(verifier.isValid(), verifier.getMessage());
8986

9087
verifier.reset();
9188
// no resources should be visited
9289
teamPrivateFile.accept(verifier);
93-
assertTrue(verifier.getMessage(), verifier.isValid());
90+
assertTrue(verifier.isValid(), verifier.getMessage());
9491

9592
verifier.reset();
9693
verifier.addExpected(teamPrivateFile);
9794
teamPrivateFile.accept(verifier, IResource.DEPTH_INFINITE, IContainer.INCLUDE_TEAM_PRIVATE_MEMBERS);
98-
assertTrue(verifier.getMessage(), verifier.isValid());
95+
assertTrue(verifier.isValid(), verifier.getMessage());
9996
}
10097

10198
}

resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_029116.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,17 @@
2020
import org.eclipse.core.resources.IProject;
2121
import org.eclipse.core.resources.IProjectDescription;
2222
import org.eclipse.core.runtime.CoreException;
23-
import org.eclipse.core.tests.resources.WorkspaceTestRule;
24-
import org.junit.Rule;
25-
import org.junit.Test;
23+
import org.eclipse.core.tests.resources.util.WorkspaceResetExtension;
24+
import org.junit.jupiter.api.Test;
25+
import org.junit.jupiter.api.extension.ExtendWith;
2626

2727
/**
2828
* Test regression of bug 29116. In this bug, triggering a builder during
2929
* installation of a nature caused an assertion failure.
3030
*/
31+
@ExtendWith(WorkspaceResetExtension.class)
3132
public class Bug_029116 {
3233

33-
@Rule
34-
public WorkspaceTestRule workspaceRule = new WorkspaceTestRule();
35-
3634
@Test
3735
public void testBug() throws CoreException {
3836
// Create some resource handles

resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_029671.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,16 @@
2929
import org.eclipse.core.resources.IWorkspace;
3030
import org.eclipse.core.runtime.CoreException;
3131
import org.eclipse.core.runtime.QualifiedName;
32-
import org.eclipse.core.tests.resources.WorkspaceTestRule;
33-
import org.junit.Rule;
34-
import org.junit.Test;
32+
import org.eclipse.core.tests.resources.util.WorkspaceResetExtension;
33+
import org.junit.jupiter.api.Test;
34+
import org.junit.jupiter.api.extension.ExtendWith;
3535

3636
/**
3737
* When a container was moved, its children were not added to phantom space.
3838
*/
39+
@ExtendWith(WorkspaceResetExtension.class)
3940
public class Bug_029671 {
4041

41-
@Rule
42-
public WorkspaceTestRule workspaceRule = new WorkspaceTestRule();
43-
4442
@Test
4543
public void testBug() throws CoreException {
4644
final QualifiedName partner = new QualifiedName("org.eclipse.core.tests.resources", "myTarget");

resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_029851.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,18 @@
2525
import org.eclipse.core.runtime.CoreException;
2626
import org.eclipse.core.runtime.IPath;
2727
import org.eclipse.core.runtime.QualifiedName;
28-
import org.eclipse.core.tests.resources.WorkspaceTestRule;
29-
import org.junit.Rule;
30-
import org.junit.Test;
28+
import org.eclipse.core.tests.resources.util.WorkspaceResetExtension;
29+
import org.junit.jupiter.api.Test;
30+
import org.junit.jupiter.api.extension.ExtendWith;
3131

3232
/**
3333
* Tests regression of bug 25457. In this case, attempting to move a project
3434
* that is only a case change, where the move fails due to another handle being
3535
* open on a file in the hierarchy, would cause deletion of the source.
3636
*/
37+
@ExtendWith(WorkspaceResetExtension.class)
3738
public class Bug_029851 {
3839

39-
@Rule
40-
public WorkspaceTestRule workspaceRule = new WorkspaceTestRule();
41-
4240
private Collection<String> createChildren(int breadth, int depth, IPath prefix) {
4341
ArrayList<String> result = new ArrayList<>();
4442
for (int i = 0; i < breadth; i++) {

0 commit comments

Comments
 (0)