Skip to content

Commit c5b7c43

Browse files
committed
Migrate org.eclipse.ui.monitoring.tests from JUnit 4 to JUnit 5
1 parent 126085a commit c5b7c43

File tree

5 files changed

+166
-141
lines changed

5 files changed

+166
-141
lines changed

tests/org.eclipse.ui.monitoring.tests/META-INF/MANIFEST.MF

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ Manifest-Version: 1.0
22
Bundle-ManifestVersion: 2
33
Bundle-Name: %Bundle-Name
44
Import-Package: org.junit.jupiter.api;version="[5.14.0,6.0.0)",
5+
org.junit.jupiter.api.extension;version="[5.14.0,6.0.0)",
6+
org.junit.jupiter.api.function;version="[5.14.0,6.0.0)",
7+
org.junit.jupiter.engine;version="[5.14.0,6.0.0)",
58
org.junit.platform.suite.api;version="[1.14.0,2.0.0)"
69
Bundle-RequiredExecutionEnvironment: JavaSE-17
710
Bundle-SymbolicName: org.eclipse.ui.monitoring.tests;singleton:=true
811
Bundle-Vendor: %Bundle-Vendor
912
Bundle-Version: 1.3.0.qualifier
1013
Fragment-Host: org.eclipse.ui.monitoring;bundle-version="1.0.0"
1114
Require-Bundle: org.eclipse.jface;bundle-version="[3.10.0,4.0.0)",
12-
org.eclipse.ui.workbench;bundle-version="[3.106.0,4.0.0)",
13-
org.junit;bundle-version="[4.12.0,5.0.0)"
15+
org.eclipse.ui.workbench;bundle-version="[3.106.0,4.0.0)"
1416
Automatic-Module-Name: org.eclipse.ui.monitoring.tests

tests/org.eclipse.ui.monitoring.tests/src/org/eclipse/ui/internal/monitoring/DefaultLoggerTests.java

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
*******************************************************************************/
1616
package org.eclipse.ui.internal.monitoring;
1717

18-
import static org.junit.Assert.assertEquals;
19-
import static org.junit.Assert.assertTrue;
18+
import static org.junit.jupiter.api.Assertions.assertEquals;
19+
import static org.junit.jupiter.api.Assertions.assertTrue;
2020

2121
import java.lang.management.ManagementFactory;
2222
import java.lang.management.ThreadInfo;
@@ -30,8 +30,8 @@
3030
import org.eclipse.ui.monitoring.PreferenceConstants;
3131
import org.eclipse.ui.monitoring.StackSample;
3232
import org.eclipse.ui.monitoring.UiFreezeEvent;
33-
import org.junit.Before;
34-
import org.junit.Test;
33+
import org.junit.jupiter.api.BeforeEach;
34+
import org.junit.jupiter.api.Test;
3535

3636
/**
3737
* JUnit test for the {@link DefaultUiFreezeEventLogger}.
@@ -45,7 +45,7 @@ public class DefaultLoggerTests {
4545
private ThreadInfo thread;
4646
private IStatus loggedStatus;
4747

48-
@Before
48+
@BeforeEach
4949
public void setUp() {
5050
logger = new DefaultUiFreezeEventLogger(DURATION * 10);
5151
createLogListener();
@@ -68,30 +68,31 @@ private UiFreezeEvent createFreezeEvent() {
6868
}
6969

7070
@Test
71-
public void testLogEvent() {
72-
UiFreezeEvent event = createFreezeEvent();
73-
String expectedTime = dateFormat.format(new Date(TIME).toInstant());
74-
String expectedHeader =
75-
String.format("UI freeze of %.2gs at %s", DURATION / 1000.0, expectedTime);
76-
String expectedEventMessage = String.format("Sample at %s (+%.3fs)", expectedTime, 0.000);
71+
void testLogEvent() {
72+
UiFreezeEvent event = createFreezeEvent();
73+
String expectedTime = dateFormat.format(new Date(TIME).toInstant());
74+
String expectedHeader =
75+
String.format("UI freeze of %.2gs at %s", DURATION / 1000.0, expectedTime);
76+
String expectedEventMessage = String.format("Sample at %s (+%.3fs)", expectedTime, 0.000);
7777

78-
logger.log(event);
78+
logger.log(event);
7979

80-
assertEquals(PreferenceConstants.PLUGIN_ID, loggedStatus.getPlugin());
81-
assertTrue("Logged status was not a MultiStatus", loggedStatus.isMultiStatus());
82-
assertEquals(expectedHeader, loggedStatus.getMessage());
83-
assertEquals("One nested IStatus did not get logged correctly.", 1,
84-
loggedStatus.getChildren().length);
80+
assertEquals(PreferenceConstants.PLUGIN_ID, loggedStatus.getPlugin());
81+
assertTrue(loggedStatus.isMultiStatus(), "Logged status was not a MultiStatus");
82+
assertEquals(expectedHeader, loggedStatus.getMessage());
83+
assertEquals(1, loggedStatus.getChildren().length,
84+
"One nested IStatus did not get logged correctly.");
8585

86-
IStatus freezeEvent = loggedStatus.getChildren()[0];
87-
assertTrue(freezeEvent.getMessage().contains(expectedEventMessage));
86+
IStatus freezeEvent = loggedStatus.getChildren()[0];
87+
assertTrue(freezeEvent.getMessage().contains(expectedEventMessage));
8888

89-
StackTraceElement[] threadStackTrace = thread.getStackTrace();
90-
StackTraceElement[] loggedStackTrace = freezeEvent.getException().getStackTrace();
91-
assertEquals(threadStackTrace.length, loggedStackTrace.length);
89+
StackTraceElement[] threadStackTrace = thread.getStackTrace();
90+
StackTraceElement[] loggedStackTrace = freezeEvent.getException().getStackTrace();
91+
assertEquals(threadStackTrace.length, loggedStackTrace.length);
9292

93-
for (int i = 0; i < threadStackTrace.length; i++) {
94-
assertEquals(threadStackTrace[i], loggedStackTrace[i]);
95-
}
93+
for (int i = 0; i < threadStackTrace.length; i++) {
94+
assertEquals(threadStackTrace[i], loggedStackTrace[i]);
95+
}
9696
}
97+
9798
}

tests/org.eclipse.ui.monitoring.tests/src/org/eclipse/ui/internal/monitoring/EventLoopMonitorThreadManualTests.java

Lines changed: 58 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@
1717
*******************************************************************************/
1818
package org.eclipse.ui.internal.monitoring;
1919

20-
import static org.junit.Assert.assertEquals;
21-
import static org.junit.Assert.assertNotNull;
22-
import static org.junit.Assert.assertTrue;
20+
21+
import static org.junit.jupiter.api.Assertions.assertEquals;
22+
import static org.junit.jupiter.api.Assertions.assertNotNull;
23+
import static org.junit.jupiter.api.Assertions.assertTrue;
2324

2425
import java.lang.management.ManagementFactory;
2526
import java.lang.management.ThreadMXBean;
@@ -35,9 +36,9 @@
3536
import org.eclipse.jface.preference.IPreferenceStore;
3637
import org.eclipse.swt.widgets.Display;
3738
import org.eclipse.ui.monitoring.PreferenceConstants;
38-
import org.junit.After;
39-
import org.junit.Before;
40-
import org.junit.Test;
39+
import org.junit.jupiter.api.AfterEach;
40+
import org.junit.jupiter.api.BeforeEach;
41+
import org.junit.jupiter.api.Test;
4142

4243
/**
4344
* A test that measures performance overhead of {@link EventLoopMonitorThread}.
@@ -111,12 +112,12 @@ public class EventLoopMonitorThreadManualTests {
111112
*/
112113
protected static final long PN63_GENERATOR_POLY = (3L << 62) | 1;
113114

114-
@Before
115+
@BeforeEach
115116
public void setUp() {
116117
MonitoringPlugin.getPreferenceStore().setValue(PreferenceConstants.MONITORING_ENABLED, false);
117118
}
118119

119-
@After
120+
@AfterEach
120121
public void tearDown() {
121122
MonitoringPlugin.getPreferenceStore().setToDefault(PreferenceConstants.MONITORING_ENABLED);
122123
}
@@ -163,7 +164,7 @@ protected static long doWork(long pnSeqeuence, long iterations) {
163164
@Test
164165
public void testFixedWork() throws Exception{
165166
final Display display = Display.getDefault();
166-
assertNotNull("No SWT Display available.", display);
167+
assertNotNull(display, "No SWT Display available.");
167168

168169
final MockUiFreezeEventLogger logger = new MockUiFreezeEventLogger();
169170
final CountDownLatch backgroundJobsDone = new CountDownLatch(1);
@@ -246,13 +247,18 @@ public void testFixedWork() throws Exception{
246247
maxRelativeIncreaseOneStackAllowed * 100));
247248
}
248249
assertTrue(
249-
String.format("""
250-
Relative overhead of monitoring surpassed threshold for
251-
measurement %d of %d. It took %.3fs with a relative increase of %.3f%%
252-
(allowed < %.3f%%).""",
253-
i, NUM_UI_STACK_MEASUREMENTS, tWork[0] / 1e9, relativeDiffOneThread * 100,
254-
maxRelativeIncreaseOneStackAllowed * 100),
255-
relativeDiffOneThread <= maxRelativeIncreaseOneStackAllowed);
250+
relativeDiffOneThread <= maxRelativeIncreaseOneStackAllowed,
251+
String.format("""
252+
Relative overhead of monitoring surpassed threshold for \
253+
measurement %d of %d. It took %.3fs with a relative increase of %.3f%% \
254+
(allowed < %.3f%%).""",
255+
i,
256+
NUM_UI_STACK_MEASUREMENTS,
257+
tWork[0] / 1e9,
258+
relativeDiffOneThread * 100,
259+
maxRelativeIncreaseOneStackAllowed * 100)
260+
);
261+
256262
}
257263
killMonitorThread(monitor1, display);
258264

@@ -277,13 +283,19 @@ public void testFixedWork() throws Exception{
277283
i, NUM_ALL_STACKS_MEASUREMENTS, tWork[0] / 1e9, relativeDiffAllThreads * 100,
278284
maxRelativeIncreaseAllStacksAllowed * 100));
279285
}
280-
assertTrue(String.format("""
281-
Relative overhead of monitoring with stack traces of all threads
282-
surpassed threshold for measurement %d of %d. It took %.3fs with a relative
283-
increase of %.3f%% (allowed < %.3f%%).""",
284-
i, NUM_ALL_STACKS_MEASUREMENTS, tWork[0] / 1e9, relativeDiffAllThreads * 100,
285-
maxRelativeIncreaseAllStacksAllowed * 100),
286-
relativeDiffAllThreads <= maxRelativeIncreaseAllStacksAllowed);
286+
assertTrue(
287+
relativeDiffAllThreads <= maxRelativeIncreaseAllStacksAllowed,
288+
String.format("""
289+
Relative overhead of monitoring with stack traces of all threads \
290+
surpassed threshold for measurement %d of %d. It took %.3fs with a relative \
291+
increase of %.3f%% (allowed < %.3f%%).""",
292+
i,
293+
NUM_ALL_STACKS_MEASUREMENTS,
294+
tWork[0] / 1e9,
295+
relativeDiffAllThreads * 100,
296+
maxRelativeIncreaseAllStacksAllowed * 100)
297+
);
298+
287299
}
288300
killMonitorThread(monitor2, display);
289301

@@ -376,22 +388,30 @@ public void testFixedWork() throws Exception{
376388
threads.offer(t); // Retry.
377389
}
378390
}
379-
380-
assertEquals("Did not log expected number of freeze events,",
391+
assertEquals(
381392
NUM_UI_STACK_MEASUREMENTS + NUM_ALL_STACKS_MEASUREMENTS,
382-
logger.getLoggedEvents().size());
383-
assertTrue(String.format("""
384-
Relative overhead of monitoring with stack traces of the UI
385-
thread was %.3f%% (allowed < %.3f%%).""",
386-
worstRelativeDiffOneThread * 100,
387-
maxRelativeIncreaseOneStackAllowed * 100),
388-
worstRelativeDiffOneThread <= maxRelativeIncreaseOneStackAllowed);
389-
assertTrue(String.format("""
390-
Relative overhead of monitoring with stack traces of all
391-
threads was %.3f%% (allowed < %.3f%%).""",
392-
worstRelativeDiffAllThreads * 100,
393-
maxRelativeIncreaseAllStacksAllowed * 100),
394-
worstRelativeDiffAllThreads <= maxRelativeIncreaseAllStacksAllowed);
393+
logger.getLoggedEvents().size(),
394+
"Did not log expected number of freeze events."
395+
);
396+
397+
assertTrue(
398+
worstRelativeDiffOneThread <= maxRelativeIncreaseOneStackAllowed,
399+
String.format("""
400+
Relative overhead of monitoring with stack traces of the UI \
401+
thread was %.3f%% (allowed < %.3f%%).""",
402+
worstRelativeDiffOneThread * 100,
403+
maxRelativeIncreaseOneStackAllowed * 100)
404+
);
405+
406+
assertTrue(
407+
worstRelativeDiffAllThreads <= maxRelativeIncreaseAllStacksAllowed,
408+
String.format("""
409+
Relative overhead of monitoring with stack traces of all \
410+
threads was %.3f%% (allowed < %.3f%%).""",
411+
worstRelativeDiffAllThreads * 100,
412+
maxRelativeIncreaseAllStacksAllowed * 100)
413+
);
414+
395415
}
396416

397417
private Thread createAndStartMonitoringThread(Display display, boolean dumpAll) throws Exception {

0 commit comments

Comments
 (0)