Skip to content

Commit 4226895

Browse files
committed
Remove JUnit 3 fail operations from ResourceTest
Replaces fail(String, Throwable) operations in ResourceTest utility methods by rethrowing the exception in order to separate those methods to a utility class and prepare for a migration to JUnit 4/5.
1 parent bb9ed99 commit 4226895

29 files changed

+160
-165
lines changed

resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/BuilderTest.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import java.io.ByteArrayInputStream;
2121
import java.io.ByteArrayOutputStream;
22+
import java.io.IOException;
2223
import java.util.HashMap;
2324
import java.util.Map;
2425
import java.util.concurrent.atomic.AtomicReference;
@@ -834,7 +835,7 @@ public void testForgetLastBuiltState() throws CoreException {
834835
* Tests that a client invoking a manual incremental build before autobuild has had
835836
* a chance to run will block until the build completes. See bug 275879.
836837
*/
837-
public void testIncrementalBuildBeforeAutobuild() throws CoreException {
838+
public void testIncrementalBuildBeforeAutobuild() throws Exception {
838839
// Create some resource handles
839840
final IProject project = getWorkspace().getRoot().getProject("PROJECT");
840841
final IFile input = project.getFolder(SortBuilder.DEFAULT_UNSORTED_FOLDER).getFile("File.txt");
@@ -856,11 +857,19 @@ public void testIncrementalBuildBeforeAutobuild() throws CoreException {
856857

857858
//change the file and then immediately perform build
858859
final ByteArrayOutputStream out = new ByteArrayOutputStream();
860+
AtomicReference<IOException> exception = new AtomicReference<>();
859861
getWorkspace().run((IWorkspaceRunnable) monitor -> {
860862
input.setContents(new ByteArrayInputStream(new byte[] { 5, 4, 3, 2, 1 }), IResource.NONE, getMonitor());
861863
project.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, getMonitor());
862-
transferStreams(output.getContents(), out, null);
864+
try {
865+
transferStreams(output.getContents(), out, null);
866+
} catch (IOException e) {
867+
exception.set(e);
868+
}
863869
}, getMonitor());
870+
if (exception.get() != null) {
871+
throw exception.get();
872+
}
864873

865874
byte[] result = out.toByteArray();
866875
byte[] expected = new byte[] {1, 2, 3, 4, 5};

resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/RelaxedSchedRuleBuilderTest.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -305,13 +305,18 @@ public void testBuilderDeltaUsingRelaxedRuleBug343256() throws Throwable {
305305
project.build(IncrementalProjectBuilder.FULL_BUILD, getMonitor());
306306

307307
final TestBarrier2 tb = new TestBarrier2(TestBarrier2.STATUS_WAIT_FOR_START);
308-
AtomicReference<Throwable> error = new AtomicReference<>();
308+
AtomicReference<Throwable> errorInBuildTriggeringJob = new AtomicReference<>();
309+
AtomicReference<Throwable> errorInWorkspaceChangingJob = new AtomicReference<>();
309310

310311
Job workspaceChangingJob = new Job("Workspace Changing Job") {
311312
@Override
312313
protected IStatus run(IProgressMonitor monitor) {
313314
tb.setStatus(TestBarrier2.STATUS_WAIT_FOR_RUN);
314-
ensureExistsInWorkspace(foo, new ByteArrayInputStream(new byte[0]));
315+
try {
316+
ensureExistsInWorkspace(foo, new ByteArrayInputStream(new byte[0]));
317+
} catch (CoreException e) {
318+
errorInWorkspaceChangingJob.set(e);
319+
}
315320
return Status.OK_STATUS;
316321
}
317322
};
@@ -326,9 +331,9 @@ protected IStatus run(IProgressMonitor monitor) {
326331
IStatus status = e.getStatus();
327332
IStatus[] children = status.getChildren();
328333
if (children.length > 0) {
329-
error.set(children[0].getException());
334+
errorInBuildTriggeringJob.set(children[0].getException());
330335
} else {
331-
error.set(e);
336+
errorInBuildTriggeringJob.set(e);
332337
}
333338
}
334339
return Status.OK_STATUS;
@@ -403,8 +408,11 @@ public IProject[] build(int kind, Map<String, String> args, IProgressMonitor mon
403408

404409
workspaceChangingJob.join(timeout, null);
405410
buildTriggeringJob.join(timeout, null);
406-
if (error.get() != null) {
407-
throw error.get();
411+
if (errorInBuildTriggeringJob.get() != null) {
412+
throw errorInBuildTriggeringJob.get();
413+
}
414+
if (errorInWorkspaceChangingJob.get() != null) {
415+
throw errorInWorkspaceChangingJob.get();
408416
}
409417
tb.waitForStatus(TestBarrier2.STATUS_DONE);
410418
errorLogging.assertNoErrorsLogged();

resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/FileSystemResourceManagerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ public void testWriteDeletedFile() throws CoreException {
320320
}
321321

322322
@Test
323-
public void testWriteFileNotInWorkspace() {
323+
public void testWriteFileNotInWorkspace() throws CoreException {
324324
// Bug 571133
325325
IProject project = projects[0];
326326
IFile file = project.getFile("testWriteFile2");

resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/HistoryStoreTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ public void testAddStateAndPolicies() throws Exception {
296296
assertEquals("3.5", 0, states.length);
297297
}
298298

299-
public void testBug28238() {
299+
public void testBug28238() throws CoreException {
300300
// paths to mimic files in the workspace
301301
IProject project = getWorkspace().getRoot().getProject("myproject28238");
302302
IFolder folder = project.getFolder("myfolder");

resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/LocalSyncTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ private boolean existsInFileSystemWithNoContent(IResource resource) {
4040
return path.toFile().exists() && path.toFile().length() == 0;
4141
}
4242

43-
public void testProjectDeletion() {
43+
public void testProjectDeletion() throws CoreException {
4444
/* initialize common objects */
4545
Project project = (Project) projects[0];
4646

resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/properties/PropertyManagerTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ public void testConcurrentAccess() {
160160
* Tests concurrent access to the property store while the project is being
161161
* deleted.
162162
*/
163-
public void testConcurrentDelete() {
163+
public void testConcurrentDelete() throws CoreException {
164164
Thread[] threads;
165165
final IFile target = projects[0].getFile("target");
166166
final int REPEAT = 8;
@@ -403,7 +403,7 @@ public void testDeleteProperties() throws Throwable {
403403
/**
404404
* See bug 93849.
405405
*/
406-
public void testFileRename() {
406+
public void testFileRename() throws CoreException {
407407
IWorkspaceRoot root = getWorkspace().getRoot();
408408
IProject project = root.getProject("proj");
409409
IFolder folder = project.getFolder("folder");
@@ -442,7 +442,7 @@ public void testFileRename() {
442442
/**
443443
* See bug 93849.
444444
*/
445-
public void testFolderRename() {
445+
public void testFolderRename() throws CoreException {
446446
IWorkspaceRoot root = getWorkspace().getRoot();
447447
IProject project = root.getProject("proj");
448448
IFolder folder1a = project.getFolder("folder1");
@@ -515,7 +515,7 @@ public void testLargeProperty() {
515515
/**
516516
* See bug 93849.
517517
*/
518-
public void testProjectRename() {
518+
public void testProjectRename() throws CoreException {
519519
IWorkspaceRoot root = getWorkspace().getRoot();
520520
IProject project1a = root.getProject("proj1");
521521
ensureExistsInWorkspace(project1a, true);

resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/ProjectDynamicReferencesTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ public void testComputeProjectOrder() throws CoreException {
220220
assertFalse("No cycles", projectOrder.hasCycles);
221221
}
222222

223-
public void testBug543776() throws CoreException {
223+
public void testBug543776() throws Exception {
224224
IFile projectFile = project0.getFile(IProjectDescription.DESCRIPTION_FILE_NAME);
225225
String projectDescription = readStringInFileSystem(projectFile);
226226
projectDescription = projectDescription.replace(PROJECT_0_NAME, "anotherName");

resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/ProjectPreferencesTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public void preferenceChange(PreferenceChangeEvent event) {
112112
}
113113
}
114114

115-
public void testSimple() {
115+
public void testSimple() throws CoreException {
116116
IProject project = getProject("foo");
117117
String qualifier = "org.eclipse.core.tests.resources";
118118
String key = "key" + getUniqueString();

resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IFileTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public void generateInterestingFiles(IContainer container) {
142142
* Returns some interesting files. These files are created
143143
* during setup.
144144
*/
145-
public IFile[] interestingFiles() {
145+
public IFile[] interestingFiles() throws CoreException {
146146
refreshFiles();
147147
IFile[] result = new IFile[allFiles.size()];
148148
allFiles.toArray(result);
@@ -207,7 +207,7 @@ public boolean outOfSync(IFile file) {
207207
/**
208208
* Makes sure file requirements are met (out of sync, workspace only, etc).
209209
*/
210-
public void refreshFile(IFile file) {
210+
public void refreshFile(IFile file) throws CoreException {
211211
if (file.getName().equals(LOCAL_ONLY)) {
212212
ensureDoesNotExistInWorkspace(file);
213213
//project must exist to access file system store.
@@ -243,7 +243,7 @@ public void refreshFile(IFile file) {
243243
/**
244244
* Makes sure file requirements are met (out of sync, workspace only, etc).
245245
*/
246-
public void refreshFiles() {
246+
public void refreshFiles() throws CoreException {
247247
for (IFile file : allFiles) {
248248
refreshFile(file);
249249
}
@@ -360,7 +360,7 @@ public void testCreate() throws Exception {
360360
Object[][] inputs = new Object[][] {interestingFiles(), interestingStreams(), TRUE_AND_FALSE, PROGRESS_MONITORS};
361361
new TestPerformer("IFileTest.testCreate") {
362362
@Override
363-
public void cleanUp(Object[] args, int count) {
363+
public void cleanUp(Object[] args, int count) throws CoreException {
364364
IFile file = (IFile) args[0];
365365
refreshFile(file);
366366
}
@@ -597,7 +597,7 @@ public int read() throws IOException {
597597
}
598598

599599
@Test
600-
public void testFileCreation_Bug107188() {
600+
public void testFileCreation_Bug107188() throws CoreException {
601601
//create from stream that is canceled
602602
IFile target = projects[0].getFile("file1");
603603
ensureDoesNotExistInWorkspace(target);
@@ -718,7 +718,7 @@ public void testGetContents() throws Exception {
718718
Object[][] inputs = new Object[][] {interestingFiles()};
719719
new TestPerformer("IFileTest.testGetContents") {
720720
@Override
721-
public void cleanUp(Object[] args, int count) {
721+
public void cleanUp(Object[] args, int count) throws CoreException {
722722
IFile file = (IFile) args[0];
723723
refreshFile(file);
724724
}
@@ -860,7 +860,7 @@ public void testSetContents1() throws Exception {
860860
Object[][] inputs = new Object[][] {interestingFiles(), interestingStreams(), TRUE_AND_FALSE, PROGRESS_MONITORS};
861861
new TestPerformer("IFileTest.testSetContents1") {
862862
@Override
863-
public void cleanUp(Object[] args, int count) {
863+
public void cleanUp(Object[] args, int count) throws CoreException {
864864
IFile file = (IFile) args[0];
865865
refreshFile(file);
866866
}

resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IFolderTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public void testChangeCase() throws CoreException {
5757
assertExistsInWorkspace("1.1", afterFile);
5858
}
5959

60-
public void testCopyMissingFolder() {
60+
public void testCopyMissingFolder() throws CoreException {
6161
//tests copying a folder that is missing from the file system
6262
IProject project = getWorkspace().getRoot().getProject("Project");
6363
IFolder before = project.getFolder("OldFolder");

0 commit comments

Comments
 (0)