From 3e904b3f5658c3dac698220203b15004c302037a Mon Sep 17 00:00:00 2001 From: Heiko Klare Date: Sat, 3 Jan 2026 12:22:04 +0100 Subject: [PATCH] Remove general preference memento handling in debug tests The superclass of all debug tests manages a preference memento to restore initial preferences after a test case execution. This is, however, only used by two actual tests, such that providing it for every debug test is not necessary and leads to unnecessary complexity in the hierarchy of test classes. This change moves the preference memento to exactly those two test classes in which it is required, as a prerequisite for simplifying the inheritance hierarchy and moving to JUnit 5. --- .../debug/tests/AbstractDebugTest.java | 31 ------------------- .../console/ProcessConsoleManagerTests.java | 11 ++++++- .../tests/launching/LaunchHistoryTests.java | 11 ++++++- 3 files changed, 20 insertions(+), 33 deletions(-) diff --git a/debug/org.eclipse.debug.tests/src/org/eclipse/debug/tests/AbstractDebugTest.java b/debug/org.eclipse.debug.tests/src/org/eclipse/debug/tests/AbstractDebugTest.java index 4cd15825367..143b7059732 100644 --- a/debug/org.eclipse.debug.tests/src/org/eclipse/debug/tests/AbstractDebugTest.java +++ b/debug/org.eclipse.debug.tests/src/org/eclipse/debug/tests/AbstractDebugTest.java @@ -20,8 +20,6 @@ import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.jobs.Job; -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jface.preference.PreferenceMemento; import org.eclipse.swt.widgets.Display; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchWindow; @@ -43,11 +41,6 @@ public class AbstractDebugTest { */ protected long testTimeout = 30000; - /** - * Preference helper to restore changed preference values after test run. - */ - private final PreferenceMemento prefMemento = new PreferenceMemento(); - @Rule public TestName name = new TestName(); @@ -62,7 +55,6 @@ public void setUp() throws Exception { public void tearDown() throws Exception { TestUtil.log(IStatus.INFO, name.getMethodName(), "tearDown"); TestUtil.cleanUp(name.getMethodName()); - prefMemento.resetPreferences(); } /** @@ -143,27 +135,4 @@ private static void closeIntro(final IWorkbench wb) { } } - /** - * Change a preference value for this test run. The preference will be reset - * to its value before test started automatically on {@link #tearDown()}. - * - * @param preference value type. The type must have a corresponding - * {@link IPreferenceStore} setter. - * @param store preference store to manipulate (must not be - * null) - * @param name preference to change - * @param value new preference value - * @throws IllegalArgumentException when setting a type which is not - * supported by {@link IPreferenceStore} - * - * @see IPreferenceStore#setValue(String, double) - * @see IPreferenceStore#setValue(String, float) - * @see IPreferenceStore#setValue(String, int) - * @see IPreferenceStore#setValue(String, long) - * @see IPreferenceStore#setValue(String, boolean) - * @see IPreferenceStore#setValue(String, String) - */ - protected void setPreference(IPreferenceStore store, String name, T value) { - prefMemento.setValue(store, name, value); - } } diff --git a/debug/org.eclipse.debug.tests/src/org/eclipse/debug/tests/console/ProcessConsoleManagerTests.java b/debug/org.eclipse.debug.tests/src/org/eclipse/debug/tests/console/ProcessConsoleManagerTests.java index b841ef2fe86..d3c12fcf536 100644 --- a/debug/org.eclipse.debug.tests/src/org/eclipse/debug/tests/console/ProcessConsoleManagerTests.java +++ b/debug/org.eclipse.debug.tests/src/org/eclipse/debug/tests/console/ProcessConsoleManagerTests.java @@ -37,9 +37,11 @@ import org.eclipse.debug.tests.AbstractDebugTest; import org.eclipse.debug.tests.TestUtil; import org.eclipse.debug.ui.IDebugUIConstants; +import org.eclipse.jface.preference.PreferenceMemento; import org.eclipse.ui.console.ConsolePlugin; import org.eclipse.ui.console.IConsole; import org.eclipse.ui.console.IConsoleManager; +import org.junit.After; import org.junit.Test; /** @@ -47,6 +49,13 @@ */ public class ProcessConsoleManagerTests extends AbstractDebugTest { + private final PreferenceMemento prefMemento = new PreferenceMemento(); + + @After + public void restorePreferences() { + prefMemento.resetPreferences(); + } + /** * Test addition and removal of a ProcessConsole. It also kind of tests * {@link LaunchManager} because the ProcessConsoleManager primary works @@ -102,7 +111,7 @@ public void testBug546710_ConsoleCreationRaceCondition() throws Exception { final MockProcess mockProcess2 = new MockProcess(0); final IProcess process2 = mockProcess2.toRuntimeProcess("SecondMockProcess"); try { - setPreference(DebugUIPlugin.getDefault().getPreferenceStore(), IDebugUIConstants.PREF_AUTO_REMOVE_OLD_LAUNCHES, true); + prefMemento.setValue(DebugUIPlugin.getDefault().getPreferenceStore(), IDebugUIConstants.PREF_AUTO_REMOVE_OLD_LAUNCHES, true); // Stop the JobManager to reliable trigger the tested race // condition. TestUtil.waitForJobs(name.getMethodName(), ProcessConsoleManager.class, 0, 10000); diff --git a/debug/org.eclipse.debug.tests/src/org/eclipse/debug/tests/launching/LaunchHistoryTests.java b/debug/org.eclipse.debug.tests/src/org/eclipse/debug/tests/launching/LaunchHistoryTests.java index ad4e4b73272..2bfad4e7155 100644 --- a/debug/org.eclipse.debug.tests/src/org/eclipse/debug/tests/launching/LaunchHistoryTests.java +++ b/debug/org.eclipse.debug.tests/src/org/eclipse/debug/tests/launching/LaunchHistoryTests.java @@ -26,6 +26,8 @@ import org.eclipse.debug.internal.ui.DebugUIPlugin; import org.eclipse.debug.internal.ui.launchConfigurations.LaunchHistory; import org.eclipse.debug.ui.IDebugUIConstants; +import org.eclipse.jface.preference.PreferenceMemento; +import org.junit.After; import org.junit.Test; /** @@ -40,6 +42,13 @@ */ public class LaunchHistoryTests extends AbstractLaunchTest { + private final PreferenceMemento prefMemento = new PreferenceMemento(); + + @After + public void restorePreferences() { + prefMemento.resetPreferences(); + } + /** * Returns the run launch history */ @@ -60,7 +69,7 @@ private int getMaxHistorySize() { * @param value the new maximum size for launch histories */ private void setMaxHistorySize(int value) { - setPreference(DebugUIPlugin.getDefault().getPreferenceStore(), IDebugUIConstants.PREF_MAX_HISTORY_SIZE, value); + prefMemento.setValue(DebugUIPlugin.getDefault().getPreferenceStore(), IDebugUIConstants.PREF_MAX_HISTORY_SIZE, value); } /**