Skip to content

Commit cf08e91

Browse files
joaodinissfclaude
andcommitted
test: migrate remaining org.junit.Assert calls to Jupiter Assertions
The dead-code deletion in the prior commit removed every JUnit-4 test class but kept ten helper / utility classes still using org.junit.Assert.* statics. Migrate each call site to org.junit.jupiter.api.Assertions. Note the argument-order swap: Jupiter assertion methods take (condition, [message]) or (expected, actual, [message]) - the optional message moves to LAST position. Files migrated: com.avaloq.tools.ddk.test.core/src/.../mock/ServiceMock.java com.avaloq.tools.ddk.test.core/src/.../mock/ExtensionRegistryMock.java com.avaloq.tools.ddk.test.core/src/.../util/SimpleProgressMonitor.java com.avaloq.tools.ddk.test.core/src/.../util/JobMatcher.java com.avaloq.tools.ddk.test.ui/src/.../swtbot/util/SwtBotWizardUtil.java com.avaloq.tools.ddk.test.ui/src/.../swtbot/SwtWizardBot.java com.avaloq.tools.ddk.test.ui/src/.../swtbot/CoreSwtbotTools.java com.avaloq.tools.ddk.xtext.test.core/src/.../model/ModelUtil.java com.avaloq.tools.ddk.xtext.test.core/src/.../AcfContentAssistProcessorTestBuilder.java Bonus fix: jupiter/AbstractAcfContentAssistTest still imported org.junit.Assert.assertFalse / assertNotEquals / fail (the JUnit 4 twins of Jupiter's same-named statics). The Java compiler accepted this because the import names happen to match Jupiter symbols, but the call-sites used the JUnit 4 message-FIRST argument order, so the intended message was being passed as `unexpected`/`condition`. Switch the static imports to org.junit.jupiter.api.Assertions.* and fix the argument order at each call site. MANIFEST fix: com.avaloq.tools.ddk.test.ui's Require-Bundle was missing junit-jupiter-api, so the static-import-only call sites in SwtWizardBot/CoreSwtbotTools/SwtBotWizardUtil hit "Access restriction: The type 'Assertions' is not API". Added junit-jupiter-api to the bundle's Require-Bundle. Verified locally: tests=357 failures=0 errors=0 - first BUILD SUCCESS on this branch since rebasing onto the step-1.5 fix. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 3c9c270 commit cf08e91

11 files changed

Lines changed: 38 additions & 37 deletions

File tree

com.avaloq.tools.ddk.test.core/src/com/avaloq/tools/ddk/test/core/mock/ExtensionRegistryMock.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import org.eclipse.core.runtime.IExtensionRegistry;
2626
import org.eclipse.core.runtime.RegistryFactory;
2727
import org.eclipse.emf.common.util.WrappedException;
28-
import org.junit.Assert;
28+
import org.junit.jupiter.api.Assertions;
2929
import org.mockito.stubbing.Answer;
3030

3131
import com.google.common.collect.LinkedHashMultimap;
@@ -179,7 +179,7 @@ public static void assertUnMocked() {
179179
if (registrySpy != null) {
180180
try {
181181
String extensionPointId = configurationElements.keySet().iterator().next();
182-
Assert.fail("Extension point " + extensionPointId + " still has mocked configuration elements."); //$NON-NLS-1$ //$NON-NLS-2$
182+
Assertions.fail("Extension point " + extensionPointId + " still has mocked configuration elements."); //$NON-NLS-1$ //$NON-NLS-2$
183183
} catch (NoSuchElementException e) { // shouldn't happen
184184
throw new IllegalStateException("The extension registry mock is in an unexpected state.", e); //$NON-NLS-1$
185185
}

com.avaloq.tools.ddk.test.core/src/com/avaloq/tools/ddk/test/core/mock/ServiceMock.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import java.util.Iterator;
1515
import java.util.Map;
1616

17-
import org.junit.Assert;
17+
import org.junit.jupiter.api.Assertions;
1818

1919

2020
/**
@@ -49,7 +49,7 @@ public static void assertAllMocksRemoved() {
4949
Iterator<Class<?>> iterator = originalServices.keySet().iterator();
5050
while (iterator.hasNext()) {
5151
Class<?> clazz = iterator.next();
52-
Assert.fail("Service " + clazz.getName() + " is still mocked."); //$NON-NLS-1$//$NON-NLS-2$
52+
Assertions.fail("Service " + clazz.getName() + " is still mocked."); //$NON-NLS-1$//$NON-NLS-2$
5353
}
5454
}
5555
}

com.avaloq.tools.ddk.test.core/src/com/avaloq/tools/ddk/test/core/util/JobMatcher.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import org.eclipse.core.runtime.jobs.IJobChangeEvent;
2020
import org.eclipse.core.runtime.jobs.Job;
2121
import org.eclipse.core.runtime.jobs.JobChangeAdapter;
22-
import org.junit.Assert;
22+
import org.junit.jupiter.api.Assertions;
2323

2424
import com.google.common.base.Predicate;
2525
import com.google.common.collect.ImmutableList;
@@ -214,7 +214,7 @@ public final void deregister() {
214214
* the expected number of jobs
215215
*/
216216
public final void assertNumberOfNewJobs(final int expected) {
217-
Assert.assertEquals("Wrong number of jobs were scheduled", expected, newJobs.size());
217+
Assertions.assertEquals(expected, newJobs.size(), "Wrong number of jobs were scheduled");
218218
}
219219

220220
/**
@@ -227,13 +227,13 @@ public final void assertNumberOfNewJobs(final int expected) {
227227
public final void assertNewJobsFinished() {
228228
try {
229229
List<Job> expectedJobs = Lists.newArrayList(newJobs);
230-
Assert.assertFalse("No matching new jobs were scheduled: " + finder, expectedJobs.isEmpty());
230+
Assertions.assertFalse(expectedJobs.isEmpty(), "No matching new jobs were scheduled: " + finder);
231231
expectedJobs.removeAll(finishedJobs);
232232
while (!expectedJobs.isEmpty()) {
233233
try {
234234
Job job = getNextJob();
235235
if (job == null) {
236-
Assert.fail("Expected new jobs did not finish after " + waitTimeout + " milliseconds: " + expectedJobs);
236+
Assertions.fail("Expected new jobs did not finish after " + waitTimeout + " milliseconds: " + expectedJobs);
237237
}
238238
expectedJobs.remove(job);
239239
} catch (InterruptedException e) {
@@ -261,7 +261,7 @@ public final void waitForExistingJobs() {
261261
try {
262262
Job job = getNextJob();
263263
if (job == null) {
264-
Assert.fail("Existing jobs did not finish after " + waitTimeout + " milliseconds: " + expectedJobs);
264+
Assertions.fail("Existing jobs did not finish after " + waitTimeout + " milliseconds: " + expectedJobs);
265265
}
266266
expectedJobs.remove(job);
267267
} catch (InterruptedException e) {

com.avaloq.tools.ddk.test.core/src/com/avaloq/tools/ddk/test/core/util/SimpleProgressMonitor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
package com.avaloq.tools.ddk.test.core.util;
1212

1313
import org.eclipse.core.runtime.IProgressMonitor;
14-
import org.junit.Assert;
14+
import org.junit.jupiter.api.Assertions;
1515

1616

1717
/**
@@ -169,7 +169,7 @@ public void waitForTermination() {
169169
final long timeStarted = System.currentTimeMillis();
170170
while (!isTerminated()) {
171171
long remainingWaitTime = TIMEOUT + timeStarted - System.currentTimeMillis();
172-
Assert.assertFalse("Progress monitor did not get done signal", remainingWaitTime <= 0); //$NON-NLS-1$
172+
Assertions.assertFalse(remainingWaitTime <= 0, "Progress monitor did not get done signal"); //$NON-NLS-1$
173173
try {
174174
this.wait(remainingWaitTime);
175175
} catch (InterruptedException e) /* CHECKSTYLE:OFF */ {

com.avaloq.tools.ddk.test.ui/META-INF/MANIFEST.MF

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Require-Bundle: com.avaloq.tools.ddk.test.core,
1818
org.eclipse.ui;visibility:=reexport,
1919
org.hamcrest.library,
2020
org.junit,
21+
junit-jupiter-api,
2122
org.mockito.mockito-core,
2223
com.google.guava,
2324
org.apache.commons.lang3,

com.avaloq.tools.ddk.test.ui/src/com/avaloq/tools/ddk/test/ui/swtbot/CoreSwtbotTools.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
package com.avaloq.tools.ddk.test.ui.swtbot;
1212

1313
import static org.eclipse.swtbot.swt.finder.waits.Conditions.widgetIsEnabled;
14-
import static org.junit.Assert.assertTrue;
14+
import static org.junit.jupiter.api.Assertions.assertTrue;
1515

1616
import java.awt.AWTException;
1717
import java.awt.Robot;
@@ -455,7 +455,7 @@ public static void openView(final SWTWorkbenchBot bot, final String category, fi
455455
}
456456
}
457457
}
458-
assertTrue("View or Category found", bot.button().isEnabled());
458+
assertTrue(bot.button().isEnabled(), "View or Category found");
459459
bot.button("OK").click();
460460
}
461461

@@ -498,7 +498,7 @@ public static SWTBotTreeItem findTreeItem(final SWTWorkbenchBot bot, final SWTBo
498498
}
499499
} while (itemCount > 0);
500500

501-
assertTrue("Searching TreeItem", itemFound);
501+
assertTrue(itemFound, "Searching TreeItem");
502502

503503
return botTreeItem;
504504

com.avaloq.tools.ddk.test.ui/src/com/avaloq/tools/ddk/test/ui/swtbot/SwtWizardBot.java

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

1313
import static com.avaloq.tools.ddk.test.ui.swtbot.util.SwtBotWizardUtil.selectItem;
1414
import static org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable.syncExec;
15-
import static org.junit.Assert.assertTrue;
15+
import static org.junit.jupiter.api.Assertions.assertTrue;
1616

1717
import java.util.Arrays;
1818

@@ -49,7 +49,7 @@ public class SwtWizardBot extends SwtWorkbenchBot {
4949
public void closeWizard() {
5050
SWTBotShell activeShell = activeShell();
5151
boolean wizardIsActive = isWizard(activeShell);
52-
assertTrue("Wizard is active on close", wizardIsActive);
52+
assertTrue(wizardIsActive, "Wizard is active on close");
5353
activeShell.close();
5454
}
5555

@@ -155,13 +155,13 @@ public void openExportWizard(final String wizardName) {
155155
* name of the wizard to be activated
156156
*/
157157
private void activateWizard(final String wizardName) {
158-
assertTrue("A wizard dialog must be active", syncExec(() -> {
158+
assertTrue(syncExec(() -> {
159159
SWTBotShell wizardShell = activeShell();
160160
return wizardShell.widget.getData() instanceof WizardDialog;
161-
}));
162-
assertTrue("Wizard '" + wizardName + "' does not exist.", syncExec(() -> {
161+
}), "A wizard dialog must be active");
162+
assertTrue(syncExec(() -> {
163163
return selectItem(tree(), wizardName);
164-
}));
164+
}), "Wizard '" + wizardName + "' does not exist.");
165165
clickButton(NEXT);
166166
}
167167

com.avaloq.tools.ddk.test.ui/src/com/avaloq/tools/ddk/test/ui/swtbot/util/SwtBotWizardUtil.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
1919
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
2020
import org.eclipse.ui.PlatformUI;
21-
import org.junit.Assert;
21+
import org.junit.jupiter.api.Assertions;
2222

2323
import com.avaloq.tools.ddk.test.ui.swtbot.SwtWorkbenchBot;
2424

@@ -48,7 +48,7 @@ public static void selectProjectFolder(final SwtWorkbenchBot bot, final String f
4848
final Tree tree = bot.widget(WidgetMatcherFactory.widgetOfType(Tree.class), comp);
4949
PlatformUI.getWorkbench().getDisplay().syncExec(() -> {
5050
SWTBotTree botTree = new SWTBotTree(tree);
51-
Assert.assertTrue("folder was not found", selectItem(botTree, folderName));
51+
Assertions.assertTrue(selectItem(botTree, folderName), "folder was not found");
5252
});
5353
}
5454

com.avaloq.tools.ddk.xtext.test.core/src/com/avaloq/tools/ddk/xtext/test/AcfContentAssistProcessorTestBuilder.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
package com.avaloq.tools.ddk.xtext.test;
1212

1313
// CHECKSTYLE:OFF
14-
import static org.junit.Assert.assertNotNull;
14+
import static org.junit.jupiter.api.Assertions.assertNotNull;
1515

1616
import java.text.MessageFormat;
1717
import java.util.concurrent.atomic.AtomicReference;
@@ -35,7 +35,7 @@
3535
import org.eclipse.xtext.util.Pair;
3636
import org.eclipse.xtext.util.StringInputStream;
3737
import org.eclipse.xtext.util.Tuples;
38-
import org.junit.Assert;
38+
import org.junit.jupiter.api.Assertions;
3939

4040
import com.google.inject.Injector;
4141

@@ -111,7 +111,7 @@ public AcfContentAssistProcessorTestBuilder applyText(final String expectedDispl
111111
break;
112112
}
113113
}
114-
assertNotNull(MessageFormat.format("\"{0}\" not a valid completion proposal", expectedDisplayString), proposal);
114+
assertNotNull(proposal, MessageFormat.format("\"{0}\" not a valid completion proposal", expectedDisplayString));
115115
String text = "";
116116
if (proposal instanceof ConfigurableCompletionProposal) {
117117
text = ((ConfigurableCompletionProposal) proposal).getReplacementString();
@@ -180,11 +180,11 @@ public ContentAssistProcessorTestBuilder assertMatchString(final String matchStr
180180
ContentAssistContext.Factory factory = get(ContentAssistContext.Factory.class);
181181
ContentAssistContext[] contexts = factory.create(sourceViewer, currentModelToParse.length(), xtextResource);
182182
for (ContentAssistContext context : contexts) {
183-
Assert.assertTrue("matchString = '" + matchString + "', actual: '" + context.getPrefix() + "'", "".equals(context.getPrefix())
184-
|| matchString.equals(context.getPrefix()));
183+
Assertions.assertTrue("".equals(context.getPrefix())
184+
|| matchString.equals(context.getPrefix()), "matchString = '" + matchString + "', actual: '" + context.getPrefix() + "'");
185185
}
186186
} else {
187-
Assert.fail("No content assistant for content type " + contentType);
187+
Assertions.fail("No content assistant for content type " + contentType);
188188
}
189189
} catch (BadLocationException e) {
190190
exception.set(e);

com.avaloq.tools.ddk.xtext.test.core/src/com/avaloq/tools/ddk/xtext/test/jupiter/AbstractAcfContentAssistTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
*******************************************************************************/
1111
package com.avaloq.tools.ddk.xtext.test.jupiter;
1212

13-
import static org.junit.Assert.assertFalse;
14-
import static org.junit.Assert.assertNotEquals;
15-
import static org.junit.Assert.fail;
13+
import static org.junit.jupiter.api.Assertions.assertFalse;
14+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
15+
import static org.junit.jupiter.api.Assertions.fail;
1616

1717
import java.text.MessageFormat;
1818
import java.util.Arrays;
@@ -90,7 +90,7 @@ private String getCompletionProposalDisplayStrings(final ICompletionProposal...
9090
* the expected proposals as display strings
9191
*/
9292
private void assertCompletionProposal(final ICompletionProposal[] computedProposals, final boolean positiveTest, final String... proposals) {
93-
assertNotEquals(AT_LEAST_ONE_PROPOSAL_WAS_PROVIDED, proposals.length, 0);
93+
assertNotEquals(0, proposals.length, AT_LEAST_ONE_PROPOSAL_WAS_PROVIDED);
9494
for (final String s : proposals) {
9595
boolean foundProposal = false;
9696
for (ICompletionProposal p : computedProposals) {
@@ -155,7 +155,7 @@ protected void assertNotCompletionProposal(final ICompletionProposal[] computedP
155155
* the expected proposals as display strings
156156
*/
157157
protected void assertExactlyCompletionProposal(final ICompletionProposal[] computedProposals, final String... expectedProposals) {
158-
assertNotEquals(AT_LEAST_ONE_PROPOSAL_WAS_PROVIDED, expectedProposals.length, 0);
158+
assertNotEquals(0, expectedProposals.length, AT_LEAST_ONE_PROPOSAL_WAS_PROVIDED);
159159

160160
Set<String> computedProposalsAsSet = new HashSet<String>();
161161
for (ICompletionProposal p : computedProposals) {
@@ -190,8 +190,8 @@ protected void assertExactlyCompletionProposal(final ICompletionProposal[] compu
190190
private void assertSourceProposals(final String sourceFileName) {
191191
try {
192192
AcfContentAssistProcessorTestBuilder builder = newBuilder().append(getTestSource(sourceFileName).getContent());
193-
assertFalse(EXPECTED_PROPOSALS_NOT_SET, (acfContentAssistMarkerTagInfo.expectedProposalMap.isEmpty()
194-
&& acfContentAssistMarkerTagInfo.notExpectedProposalMap.isEmpty() && acfContentAssistMarkerTagInfo.expectedExactlyProposalMap.isEmpty()));
193+
assertFalse((acfContentAssistMarkerTagInfo.expectedProposalMap.isEmpty()
194+
&& acfContentAssistMarkerTagInfo.notExpectedProposalMap.isEmpty() && acfContentAssistMarkerTagInfo.expectedExactlyProposalMap.isEmpty()), EXPECTED_PROPOSALS_NOT_SET);
195195
for (int markerId : getUsedTagsItems()) {
196196
final ICompletionProposal[] proposals = builder.computeCompletionProposals(getOffsetForTag(markerId));
197197
if (acfContentAssistMarkerTagInfo.expectedProposalMap.containsKey(markerId)) {

0 commit comments

Comments
 (0)