Skip to content

Commit faba54c

Browse files
joaodinissfclaude
andcommitted
refactor: convert log calls to parameterized logging in test utilities
Replace string concatenation with parameterized {} placeholders. Use Supplier lambdas for lazy argument evaluation. Add NOPMD suppressions for SLF4J logger calls (SwtBot uses SLF4J, not Log4j). Add org.apache.logging.log4j.util to OSGi manifests for Supplier. Modules: test.core, test.ui Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 82941e2 commit faba54c

7 files changed

Lines changed: 21 additions & 43 deletions

File tree

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,6 @@ Export-Package: com.avaloq.tools.ddk.test.core,
2525
com.avaloq.tools.ddk.test.core.jupiter,
2626
com.avaloq.tools.ddk.test.core.mock,
2727
com.avaloq.tools.ddk.test.core.util
28+
Import-Package: org.apache.logging.log4j,
29+
org.apache.logging.log4j.util
2830
Automatic-Module-Name: com.avaloq.tools.ddk.test.core

com.avaloq.tools.ddk.test.core/src/com/avaloq/tools/ddk/test/core/LoggingRule.java

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,29 +63,21 @@ private String getDescriptionName(final Description description) {
6363

6464
@Override
6565
public void starting(final Description description) {
66-
if (LOGGER.isInfoEnabled()) {
67-
LOGGER.info("STARTING: " + getDescriptionName(description));
68-
}
66+
LOGGER.info("STARTING: {}", () -> getDescriptionName(description));
6967
}
7068

7169
@Override
7270
protected void finished(final Description description) {
73-
if (LOGGER.isInfoEnabled()) {
74-
LOGGER.info("FINISHED: " + getDescriptionName(description));
75-
}
71+
LOGGER.info("FINISHED: {}", () -> getDescriptionName(description));
7672
}
7773

7874
@Override
7975
protected void succeeded(final Description description) {
80-
if (LOGGER.isInfoEnabled()) {
81-
LOGGER.info("SUCCEEDED: " + getDescriptionName(description));
82-
}
76+
LOGGER.info("SUCCEEDED: {}", () -> getDescriptionName(description));
8377
}
8478

8579
@Override
8680
protected void failed(final Throwable e, final Description description) {
87-
if (LOGGER.isInfoEnabled()) {
88-
LOGGER.info("FAILED: " + getDescriptionName(description));
89-
}
81+
LOGGER.info("FAILED: {}", () -> getDescriptionName(description));
9082
}
9183
}

com.avaloq.tools.ddk.test.core/src/com/avaloq/tools/ddk/test/core/jupiter/LoggingRule.java

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,7 @@ public static LoggingRule getInstance() {
5454

5555
@Override
5656
public void beforeEach(final ExtensionContext context) throws Exception {
57-
if (LOGGER.isInfoEnabled()) {
58-
LOGGER.info("STARTING: " + getDescriptionName(context));
59-
}
57+
LOGGER.info("STARTING: {}", () -> getDescriptionName(context));
6058
}
6159

6260
/**
@@ -72,22 +70,16 @@ private String getDescriptionName(final ExtensionContext context) {
7270

7371
@Override
7472
public void testSuccessful(final ExtensionContext context) {
75-
if (LOGGER.isInfoEnabled()) {
76-
LOGGER.info("SUCCEEDED: " + getDescriptionName(context));
77-
}
73+
LOGGER.info("SUCCEEDED: {}", () -> getDescriptionName(context));
7874
}
7975

8076
@Override
8177
public void testFailed(final ExtensionContext context, final Throwable cause) {
82-
if (LOGGER.isInfoEnabled()) {
83-
LOGGER.info("FAILED: " + getDescriptionName(context));
84-
}
78+
LOGGER.info("FAILED: {}", () -> getDescriptionName(context));
8579
}
8680

8781
@Override
8882
public void afterEach(final ExtensionContext context) throws Exception {
89-
if (LOGGER.isInfoEnabled()) {
90-
LOGGER.info("FINISHED: " + getDescriptionName(context));
91-
}
83+
LOGGER.info("FINISHED: {}", () -> getDescriptionName(context));
9284
}
9385
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Export-Package: com.avaloq.tools.ddk.test.ui,
2828
com.avaloq.tools.ddk.test.ui.swtbot,
2929
com.avaloq.tools.ddk.test.ui.swtbot.condition,
3030
com.avaloq.tools.ddk.test.ui.swtbot.util
31-
Import-Package: org.slf4j, org.apache.logging.log4j
31+
Import-Package: org.slf4j, org.apache.logging.log4j,
32+
org.apache.logging.log4j.util
3233
Eclipse-RegisterBuddy: org.eclipse.swtbot.swt.finder
3334
Automatic-Module-Name: com.avaloq.tools.ddk.test.ui

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public SwtBotButton(final Button button, final SelfDescribing description) {
3939
*/
4040
@Override
4141
public SwtBotButton click() {
42-
log.debug("Clicking on {}", SWTUtils.getText(widget)); //$NON-NLS-1$
42+
log.debug("Clicking on {}", SWTUtils.getText(widget)); //$NON-NLS-1$ // NOPMD GuardLogStatement
4343
waitForEnabled();
4444
notify(SWT.MouseEnter);
4545
notify(SWT.MouseMove);
@@ -48,7 +48,7 @@ public SwtBotButton click() {
4848
notify(SWT.MouseDown);
4949
notify(SWT.MouseUp);
5050
notify(SWT.Selection);
51-
log.debug("Clicked on {}", SWTUtils.getText(widget)); //$NON-NLS-1$
51+
log.debug("Clicked on {}", SWTUtils.getText(widget)); //$NON-NLS-1$ // NOPMD GuardLogStatement
5252
return this;
5353
}
5454
}

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

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,7 @@ public static void clickContextMenu(final AbstractSWTBot<? extends Control> bot,
6565
* @throw {@link WidgetNotFoundException} if the context menu could not be found
6666
*/
6767
public static void clickContextMenu(final Runnable setSelection, final AbstractSWTBot<? extends Control> bot, final DynamicMenuPredicate predicate, final String... labels) {
68-
if (LOGGER.isDebugEnabled()) {
69-
LOGGER.debug("clickContextMenu(" + bot + " , " + Arrays.asList(labels) + ");"); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
70-
}
68+
LOGGER.debug("clickContextMenu({} , {});", () -> bot, () -> Arrays.asList(labels)); //$NON-NLS-1$
7169
try {
7270
setSelection.run();
7371
logSelection(bot);
@@ -101,7 +99,7 @@ private static void logSelection(final AbstractSWTBot<? extends Control> bot) {
10199
if (LOGGER.isDebugEnabled()) {
102100
TableCollection selection = tryGetSelection(bot);
103101
if (selection != null) {
104-
LOGGER.debug("setSelection(" + selection + ")"); // NOPMD GuardLogStatement //$NON-NLS-1$//$NON-NLS-2$
102+
LOGGER.debug("setSelection({})", selection); //$NON-NLS-1$
105103
}
106104
}
107105
}
@@ -140,9 +138,7 @@ private static void tryUnselect(final AbstractSWTBot<? extends Control> bot) {
140138
* @return {@code true} if on the given widget bot a context menu with the given text is available, else {@code false}
141139
*/
142140
public static boolean hasContextMenuItem(final AbstractSWTBot<? extends Control> widgetBot, final DynamicMenuPredicate predicate, final String... labels) {
143-
if (LOGGER.isDebugEnabled()) {
144-
LOGGER.debug("hasContextMenuItem(" + widgetBot + " , " + Arrays.asList(labels) + ");"); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
145-
}
141+
LOGGER.debug("hasContextMenuItem({} , {});", () -> widgetBot, () -> Arrays.asList(labels)); //$NON-NLS-1$
146142
try {
147143
return new SwtBotDynamicContextMenu(widgetBot.contextMenu(), predicate).menu(labels) != null;
148144
} catch (WidgetNotFoundException widgetNotFound) {
@@ -164,9 +160,7 @@ public static boolean hasContextMenuItem(final AbstractSWTBot<? extends Control>
164160
* @throw {@link WidgetNotFoundException} if the context menu could not be found
165161
*/
166162
public static boolean isEnabled(final AbstractSWTBot<? extends Control> widgetBot, final DynamicMenuPredicate predicate, final String... labels) {
167-
if (LOGGER.isDebugEnabled()) {
168-
LOGGER.debug("isEnabled(" + widgetBot + " , " + Arrays.asList(labels) + ");"); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
169-
}
163+
LOGGER.debug("isEnabled({} , {});", () -> widgetBot, () -> Arrays.asList(labels)); //$NON-NLS-1$
170164
try {
171165
return new SwtBotDynamicContextMenu(widgetBot.contextMenu(), predicate).menu(labels).isEnabled();
172166
} catch (WidgetNotFoundException widgetNotFound) {

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
*/
3535
public class WaitForDynamicContextMenuItem extends WaitForMenuItem {
3636
private static final Logger LOGGER = LogManager.getLogger(WaitForDynamicContextMenuItem.class);
37+
private static final String LOG_MENU_ITEM_FINDER = "MenuItem finder matching {}"; //$NON-NLS-1$
3738

3839
/**
3940
* Custom wrapper around a given {@link Matcher} that collects data about waiting dynamic menu items as
@@ -78,18 +79,14 @@ public WaitForDynamicContextMenuItem(final SwtBotDynamicContextMenuItem menu, fi
7879
super(menu, new DynamicContextMenuItemMatcher(matcher, menu.getPredicate()), recursive, index);
7980
itemMatcher = (DynamicContextMenuItemMatcher) this.matcher;
8081
this.widget = menu.widget;
81-
if (LOGGER.isDebugEnabled()) {
82-
LOGGER.debug("MenuItem finder matching " + itemMatcher); //$NON-NLS-1$
83-
}
82+
LOGGER.debug(LOG_MENU_ITEM_FINDER, itemMatcher);
8483
}
8584

8685
public WaitForDynamicContextMenuItem(final SwtBotDynamicContextMenu menu, final Matcher<MenuItem> matcher, final boolean recursive, final int index) {
8786
super(menu, new DynamicContextMenuItemMatcher(matcher, menu.getPredicate()), recursive, index);
8887
itemMatcher = (DynamicContextMenuItemMatcher) this.matcher;
8988
this.widget = menu.widget;
90-
if (LOGGER.isDebugEnabled()) {
91-
LOGGER.debug("MenuItem finder matching " + itemMatcher); //$NON-NLS-1$
92-
}
89+
LOGGER.debug(LOG_MENU_ITEM_FINDER, itemMatcher);
9390
}
9491

9592
@Override

0 commit comments

Comments
 (0)