Skip to content

Commit 1813a1a

Browse files
committed
Migrate assertions in org.eclipse.core.tests.harness to JUnit 5 #903
All consumers of functionality in org.eclipse.core.tests.harness use JUnit 5. Thus the used assertions within that functionality can be migrated to JUnit 5 as well. This change replaces all assertions accordingly. Contributes to #903
1 parent cb088f5 commit 1813a1a

File tree

5 files changed

+21
-15
lines changed

5 files changed

+21
-15
lines changed

resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/alias/BasicAliasTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,7 @@ public void testBug256837(@TempDir Path tempDirectory) throws Throwable {
427427
link2TempFolder.createLink(tempStore.toURI(), IResource.NONE, createTestMonitor());
428428
// change the location of p2 project to the temp folder
429429
replaceProject(p2, tempStore.toURI());
430+
return null;
430431
});
431432

432433
// now p2 and link2TempFolder should be aliases

runtime/tests/org.eclipse.core.tests.harness/src/org/eclipse/core/tests/harness/FileSystemComparator.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
*******************************************************************************/
1515
package org.eclipse.core.tests.harness;
1616

17+
import static org.junit.jupiter.api.Assertions.assertEquals;
18+
import static org.junit.jupiter.api.Assertions.assertNotNull;
19+
1720
import java.io.BufferedOutputStream;
1821
import java.io.BufferedReader;
1922
import java.io.File;
@@ -24,7 +27,6 @@
2427
import java.nio.file.Files;
2528
import java.util.HashMap;
2629
import java.util.Map;
27-
import org.junit.Assert;
2830

2931
/**
3032
* A utility class that compares file system states. It is able to take snapshot of the file system and save it into a
@@ -90,17 +92,19 @@ public void compareSnapshots(String tag, Object oldOne, Object newOne) {
9092
for (Object element : newSnapshot.values()) {
9193
FileSummary newElement = (FileSummary) element;
9294
FileSummary oldElement = (FileSummary) oldSnapshot.get(newElement.getPath());
93-
Assert.assertNotNull(tag + " - " + newElement.getPath() + " was added", oldElement);
94-
Assert.assertEquals(tag + " - " + newElement.getPath() + " changed timestamp ", oldElement.getTimestamp(), newElement.getTimestamp());
95-
Assert.assertEquals(tag + " - " + newElement.getPath() + " changed size ", oldElement.getSize(), newElement.getSize());
95+
assertNotNull(oldElement, tag + " - " + newElement.getPath() + " was added");
96+
assertEquals(oldElement.getTimestamp(), newElement.getTimestamp(),
97+
tag + " - " + newElement.getPath() + " changed timestamp ");
98+
assertEquals(oldElement.getSize(), newElement.getSize(),
99+
tag + " - " + newElement.getPath() + " changed size ");
96100
}
97101
// one or more entries were removed
98102
// need to do the reverse (take the old snapshot as basis) to figure out what are the missing entries
99103
if (!sameSize) {
100104
for (Object element : oldSnapshot.values()) {
101105
FileSummary oldElement = (FileSummary) element;
102106
FileSummary newElement = (FileSummary) newSnapshot.get(oldElement.getPath());
103-
Assert.assertNotNull(tag + " - " + oldElement.getPath() + " was removed", newElement);
107+
assertNotNull(newElement, tag + " - " + oldElement.getPath() + " was removed");
104108
}
105109
}
106110
}

runtime/tests/org.eclipse.core.tests.harness/src/org/eclipse/core/tests/harness/FileSystemHelper.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@
2323
import java.io.InputStreamReader;
2424
import java.nio.file.Files;
2525
import java.nio.file.Path;
26+
import java.util.concurrent.Callable;
2627
import org.eclipse.core.runtime.ILog;
2728
import org.eclipse.core.runtime.IPath;
2829
import org.eclipse.core.runtime.IStatus;
2930
import org.eclipse.core.runtime.Platform;
3031
import org.eclipse.core.runtime.Status;
31-
import org.junit.function.ThrowingRunnable;
3232

3333
/**
3434
* Home for file system-related utility methods.
@@ -243,9 +243,9 @@ public static void deleteOnShutdownRecursively(Path path) {
243243
* @param operationToExecute the operation to execute
244244
* @throws Throwable if a throwable is thrown in the operation to execute
245245
*/
246-
public static void deleteAfterExecution(Path pathToDelete, ThrowingRunnable operationToExecute) throws Throwable {
246+
public static <T> T deleteAfterExecution(Path pathToDelete, Callable<T> operationToExecute) throws Throwable {
247247
try {
248-
operationToExecute.run();
248+
return operationToExecute.call();
249249
} finally {
250250
FileSystemHelper.deleteRecursively(pathToDelete);
251251
}

runtime/tests/org.eclipse.core.tests.harness/src/org/eclipse/core/tests/harness/TestBarrier2.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@
1313
*******************************************************************************/
1414
package org.eclipse.core.tests.harness;
1515

16+
import static org.junit.jupiter.api.Assertions.fail;
17+
1618
import java.text.SimpleDateFormat;
1719
import java.util.Comparator;
1820
import java.util.Date;
1921
import java.util.Map;
2022
import java.util.Map.Entry;
2123
import java.util.concurrent.atomic.AtomicIntegerArray;
2224
import java.util.stream.Collectors;
23-
import org.junit.Assert;
2425

2526
/**
2627
* This class acts as an implementation of a barrier that is appropriate for
@@ -92,10 +93,10 @@ private static void doWaitForStatus(AtomicIntegerArray statuses, int index, int
9293
if (!condition) {
9394
String dump = getThreadDump();
9495
if (statuses.get(index) > status) {
95-
Assert.fail("Timeout after " + elapsed + "ms - Status already in state "
96+
fail("Timeout after " + elapsed + "ms - Status already in state "
9697
+ getStatus(statuses.get(index)) + " - waiting for " + getStatus(status) + "\n" + dump);
9798
} else {
98-
Assert.fail("Timeout after " + elapsed + "ms waiting for status to change from "
99+
fail("Timeout after " + elapsed + "ms waiting for status to change from "
99100
+ getStatus(statuses.get(index)) + " to " + getStatus(status) + "\n" + dump);
100101
}
101102
}

runtime/tests/org.eclipse.core.tests.harness/src/org/eclipse/core/tests/harness/session/customization/CustomSessionConfigurationImpl.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212

1313
import static org.assertj.core.api.Assertions.assertThat;
1414
import static org.eclipse.core.tests.harness.FileSystemHelper.deleteOnShutdownRecursively;
15-
import static org.junit.Assert.assertTrue;
15+
import static org.junit.jupiter.api.Assertions.assertNotNull;
16+
import static org.junit.jupiter.api.Assertions.assertTrue;
1617

1718
import java.io.File;
1819
import java.io.IOException;
@@ -32,7 +33,6 @@
3233
import org.eclipse.core.runtime.Platform;
3334
import org.eclipse.core.tests.harness.session.CustomSessionConfiguration;
3435
import org.eclipse.core.tests.session.Setup;
35-
import org.junit.Assert;
3636
import org.osgi.framework.Bundle;
3737
import org.osgi.framework.Constants;
3838
import org.osgi.framework.FrameworkUtil;
@@ -255,7 +255,7 @@ public CustomSessionConfiguration addBundle(Class<?> classFromBundle) {
255255

256256
private void addBundle(Class<?> classFromBundle, String suffix) {
257257
Bundle bundle = FrameworkUtil.getBundle(classFromBundle);
258-
Assert.assertNotNull("Class is not from a bundle: " + classFromBundle, bundle);
258+
assertNotNull(bundle, "Class is not from a bundle: " + classFromBundle);
259259
addBundle(bundle, suffix);
260260
}
261261

@@ -294,7 +294,7 @@ private record BundleReference(Bundle bundle, String suffix) {
294294

295295
String toURL() {
296296
Optional<File> location = FileLocator.getBundleFileLocation(bundle);
297-
assertTrue("Unable to locate bundle with id: " + bundle.getSymbolicName(), location.isPresent());
297+
assertTrue(location.isPresent(), "Unable to locate bundle with id: " + bundle.getSymbolicName());
298298
String externalForm;
299299
try {
300300
externalForm = location.get().toURI().toURL().toExternalForm();

0 commit comments

Comments
 (0)